GithubHelp home page GithubHelp logo

sdl-pong's Introduction

sdl-pong ๐Ÿ•น

Here is a simple pong implementation with SDL2.

SDL2 is a cross platfrom library that provides low-level access to computer hardware. It is responsible for the windowing, capturing the user input and rendering the objects to the screen.

Exexute c++ on the web :)

asm.js/wasm live demo: https://machaju.github.io/sdl4pong/

Take a look at the top-level CMake for instructions on compiling for the web. Also take note of emscripten_set_main_loop(frame_wrapper, 0, 0); in main.cpp.

REQUIREMENTS

The CMakeFinds in cmake/modules should take care of finding these libraries once they are installed.

Building Locally ๐Ÿ‘ทโ€โ™€๏ธ๐Ÿšง

Clone the Repo

> git clone https://github.com/machaju/sdl-pong.git
Cloning into 'sdl-pong'...

Verify Target System

By default, the target set is set to "web", which will build .js files instead of a c++ executable.

Change this line in CMakeLists.txt from "web" to "auto".

#edit this line to change compile target 
set(EXPORT_TARGET "auto")

Build the project

cd sdl-pong
mkdir build
cd build 
cmake ..
make -j4

Run SDL4Pong

./SDL4Pong

An SDL window should appear with the game ready to play!

SDL4Pong running locally

Play!

Left Click to begin.

Move your paddle using your mouse or trackpad. The paddle only moves in the Y direction, so no need to worry about horizontal movement.

Try to get the ball past the enemy paddle.

Playing SDL4Pong locally

Enemy Paddle

The Enemy paddle will track the ball "imperfectly" using a buffer to slow the paddle down when it gets close to the ball.

Difficulty ๐Ÿ”ฅ

You can change the difficulty in GameScene.cpp.

Possible selections include:

  • EASY
  • MEDIUM
  • HARD

By default the difficulty is set to HARD.

GameScene::GameScene() {

    // set difficulty
    DIFFICULTY diff = DIFFICULTY::HARD;

ASSETS

I drew glow-ball.png and glow-paddle.png in AffinityDesigner but you can swap them out for better graphics if you'd like, just make sure the names remain the same.

I'm using and open font called Alieron for the scores.

sdl-pong's People

Contributors

machaju avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.