matvargas / breakout

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Breakout

Breakout game implementation using OpenGL and C++ language

All the tests were made on Ubuntu 20.04, no other operational systems are currently available

Compile

In order to compile the files, make sure the following libs are properly installed on your system:

To compile and run the game you must execute run script on the root directory:
$ ./run.sh

The script will use CMake to compile the .cpp and .h files on project, it will certify that all libs needed are properly installed.
A build folder will be created when the compilation succeed.
The game will start automatically, if it doesn't happen, you can navigate to the build folder and execute the command:
$ ./breakout

Game Configuration

The GameConfig.h file on the root directory of this project is responsible for handle game definitions as it follows:

  • Game window size configuration: WINWIDTH and WINHEIGHT
  • Wall bricks size: WALLWIDTH and WALLHEIGHT
  • Number of balls: MAXBALLS

Implementation

All the elements of this game can be listed as:

  • Main window: The instance of main window is handled in the Screen.cpp class.
  • The main goal of this kind of game, in this context is called brick.
    The objective is to destroy all the bricks drawn on the screen. Once a ball hits a brick it is removed from bricks list.
  • To destroy them, the every instace of the game gives the player MAXBALLS balls as attempts. The balls are treated as a struct array on the Level.h. The initial position of the ball is the center of paddle. Each ball has a random color generated by drawBalls function on Level.cpp class, the color is associated with the ball speed.
  • Paddle is a tool for change the ball direction once it hits the paddle surface.
    The direction of the ball is affected by the position it touches the paddle. It is also defined as a struct in the Level.h class.

The Breakout class is responsible to point the developed classes in this project to the classes implemented on Glut library.

The Level class is the main code and handles the events between paddle, balls and bricks.

Gameplay

The paddle is controlled by mouse movement.
To start the level, the player must hit the R key on the keyboard.
Once the key is pressed, a single ball is drawn on the screen. If the key is pressed more than once, with the limit of MAXBALLS, more than one ball is drawn on the screen.
To exit the game, user can hit the Q key on keyboard. It will close the application and the game window.
After all the balls available are lost or all the bricks has been destroyed the game will close its application.
The level layout can be altered by changing the brick's all properties on GameConfig.h.

TODO

In order to pause the game, the actual state of all elements must be saved and all the iterations has to stop.
The way the code was written, all the balls are treated as an array iteration which stops if the ball fall off the screen or all the brick are destroyed. It means that a pause command should stop the iteration loop.
To implement the option to stop the game, the iteration has to be asynchronous with the keyboard listener function provided by Glut Library.

New levels must be added to allow user to progress on the game. A level generator function must be implemented, although all the path has already been developed.

Bricks must support different hit points. The hitBrick function has been develop to implement this future feature.

About


Languages

Language:C++ 87.0%Language:C 8.1%Language:CMake 4.3%Language:Shell 0.7%