opengl-pong

OpenGL high resolution graphics remaster of the classic Pong game inspired by learnopengl.com

https://github.com/sheraadams/opengl-pong

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.8%) to scientific vocabulary

Keywords

cpp game game-development gameengine graphics graphics-programming opengl physics
Last synced: 6 months ago · JSON representation ·

Repository

OpenGL high resolution graphics remaster of the classic Pong game inspired by learnopengl.com

Basic Info
  • Host: GitHub
  • Owner: sheraadams
  • License: apache-2.0
  • Language: C
  • Default Branch: main
  • Homepage:
  • Size: 23.5 MB
Statistics
  • Stars: 6
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
cpp game game-development gameengine graphics graphics-programming opengl physics
Created about 3 years ago · Last pushed about 1 year ago
Metadata Files
Readme License Citation

README.md

OpenGL Pong Game

About the Project

This game was inspired by LearnOpenGL's Breakout game. The game mechanics and physics are a bit different and you will see that the inverted rendering is used here but with different mechanics. A pause state, AI state and fruit drop state were added for fun. A second player was added that uses AI to return the ball each time. Users can select AI from the main menu to have two AI players play the game instead.

Controls

Default game controls: Move the fox with WASD and UP, DOWN, LEFT, RIGHT. Key P will pause the game. Player 2 is AI.

Watch the YouTube Video here.

pong

S3

Keyboard Controls

We set the key controls in the processInput(dt) function where delta time is a parameter. With the following code, we set WASD and UP, DOWN, LEFT, RIGHT to contol the fox's movement. Key P will pause the game.

```cpp if (this->State == GAMEACTIVE) // ... { if (this->Keys[GLFWKEYP] && !this->KeysProcessed[GLFWKEYP]) { int pausepoints = points; points = pausepoints; this->State = GAMEPAUSE; this->KeysProcessed[GLFWKEYP] = true; } if (this->Keys[GLFWKEYA]) {

        if (Player->Position.x >= 0.0f)
        {

            Player->Position.x -= velocity;
            if (Player->Position.x <= 0)
                Player->Position.x = 0;

            if (Ball->Stuck)
                Ball->Position.x -= velocity;
        }
    }
    if (this->Keys[GLFW_KEY_D])
    {

        if (Player->Position.x <= this->Width - Player->Size.x)
        {
            Player->Position.x += velocity;
            if (Ball->Stuck)
                Ball->Position.x += velocity;
        }
    }
    if (this->Keys[GLFW_KEY_W])
    {
        keycounter += 1;
        if (Player->Position.y >= 0.0f)
        {
            Player->Position.y -= velocity;
            if (Ball->Stuck)
                Ball->Position.y -= velocity;
        }
    }
    if (this->Keys[GLFW_KEY_S])
    {
        keycounter += 1;
        if (Player->Position.y <= this->Height - Player->Size.y)
        {
            Player->Position.y += velocity;
            if (Ball->Stuck)
                Ball->Position.y += velocity;
        }
    }

// ... } ```

AI Controls

AI controls are added in the ProcessInput function. Random fruit drops and effects are added for fun.

```cpp if (this->State == GAMEAI) {
if (this->Keys[GLFW
KEYP] && !this->KeysProcessed[GLFWKEYP]) { int pausepoints = points; points = pausepoints; this->State = GAMEPAUSE; this->KeysProcessed[GLFWKEYP] = true; } // random effects if (keycounter > 200) { Effects->Chaos = true; } if (keycounter > 470) { Effects->Chaos = false; } if (keycounter > 600) { Effects->Confuse = true; } if (keycounter > 800) { Effects->Confuse = false;} if (keycounter > 810) { Effects->Shake = false; } if (keycounter > 880) { Effects->Shake = false; }

    Ball->Stuck = false;
    float velocity = PLAYER_VELOCITY * dt;
    if (Player->Position.y <= Ball->Position.y)
    {
        keycounter += 1;
        Player->Position.y += velocity;

        // keep player 2 in the upper bounds of the screen

        if (Player->Position.y >= this->Height - Player->Size.y)
        {
            Player->Position.y = this->Height - Player->Size.y;
        }
    }
    if (Player->Position.y >= Ball->Position.y)
    {
        // keep player 2 in the lower bounds of the screen
        if (Player->Position.y <= 0)
        {
            Player->Position.y = 0;
        }
        Player->Position.y -= velocity;

    }
    // AI player 2 is auto
    if (Player2->Position.y <= Ball->Position.y)
    {

        Player2->Position.y += velocity;

        // keep player 2 in the upper bounds of the screen

        if (Player2->Position.y >= this->Height - Player2->Size.y)
        {
            Player2->Position.y = this->Height - Player2->Size.y;
        }
    }
    if (Player2->Position.y >= Ball->Position.y)
    {
        // keep player 2 in the lower bounds of the screen
        if (Player2->Position.y <= 0)
        {
            Player2->Position.y = 0;
        }
        Player2->Position.y -= velocity;

    }
    // AI player 2 vertical

    if (this->Keys[GLFW_KEY_SPACE])
        Ball->Stuck = false;

    // fruit drops
    Fruit->Position.y += velocity / 2.0f;
    Fruit2->Position.y += velocity / 1.1f;
    Fruit3->Position.y += velocity / 3.0f;
    Fruit4->Position.y += velocity;
    Fruit5->Position.y += velocity;

}

```

Photoshop Tutorials

Here is a Photoshop tutorial where I design the spaceships and other game assets and here is a tutorial that demonstrates how to configure your projects in Visual Studio.

XCode Usage

  1. Open a terminal in the project directory and run the code to remove the old build folder and generate a new one with the Xcode project file.

bash rm -rf build mkdir build cd build cmake -G Xcode ..

  1. Set the working directory in Xcode using Product > Scheme > Edit Scheme > Run Debug > Options > Working Directory > (Check Set Custom) > Project directory/build.

  2. Build and run the project.

References

Check out my references here.

License:

  • The code is based on the Breakout game by Nolan Bushnell and Steve Bristow (Atari).
  • The tutorial code is Joey DeVries and licensed under the CC BY 4.0 License.
  • Modifications and additional contributions are Shera Adams and licensed under the Apache 2.0 License.

Proudly crafted with by Shera Adams.

Owner

  • Name: Shera Adams
  • Login: sheraadams
  • Kind: user
  • Location: Burlington, VT
  • Company: The Hoffner Group

Software Engineer / Graphics Engineer

Citation (CITATION.cff)

Adams, Shera (2023). OpenGL Pong Remake. https://github.com/sheraadams/OpenGL-Pong

GitHub Events

Total
  • Push event: 1
Last Year
  • Push event: 1