You are on page 1of 6

Gliwice, 26.01.

2022

Computer Programming 3
Laboratory

Arkanoid

Author: Dawid Tomala


E-mail: dawitom895@student.polsl.pl
Tutor: Michał Staniszewski
1. Task topic

Implementation of an Arkanoid style game, using inheritance,


polymorphism, exceptions, streams and correct memory management.

2. Project analysis

For the project I’ve used the SFML library. It handles f.e. the rendering of textures, reading
input from the mouse etc.

The following data structures are used:


- vectors holding unique_ptr’s are used to store objects which number might fluctuate
during the game - blocks and powerups
- a stack is used to store the game states - this allows to easily switch to a previous
state

The following object-oriented programming techniques were used:


- Inheritance
- Polymorphism
- Streams, reading from files is used to read the block layout for a given level
- Exceptions, are used for checking whether files exist

The class structure is as follows:


Entity
|_____ Ball
|_____ Brick
|_____ Paddle
|_____ Powerup
Game
Gamestate
|_____ GameStateStart
|_____ GameStatePlay
3. External specification

After launching the program the following menu is visible:

Clicking play starts the game


During the game, your objective is to clear all of the bricks using the paddle to bounce the
ball back into them. The movement is done by dragging the mouse across the screen.

The following types of blocks are encountered:


- Normal, takes one hit to destroy
- Hard, takes two hits to destroy
- Indestructible

The following types of power ups/downs occasionally drop from the blocks and fall towards
the paddle. They’re activated by touching them with the paddle

- Ball size increase

- Ball size decrease

- Paddle length extend

- Paddle length shorten


After the ball touches the ground, you lose one life. If you lose all three, the game is over.

4. Internal specification
Classes:
- Entity - Base class for all entities in the game
Methods:
- void Entity::setPosition - function responsible for setting the position of
sprites, also takes into the account the offset of the sprite’s coordinates
- void Entity::createSprite - creates the entities sprite

- Ball - Inherits from Entity


Methods:
- void applyPowerup - change the balls size/scale after picking up a powerup
- void respawn - respawn the ball after it hit the ground
- Brick - Inherits from Entity
Methods:
- void setType - set the type of a brick
- bool collisionEvent - check if a collision with the ball occurred
- Paddle - Inherits from Entity
Methods:
- void setPosition - different implementation from the one in Entity, as this one
takes into account mouse movement only along the X axis - the Y axis is kept
constant
- Powerup - Inherits from Entity
- GameState - Abstract Class
Methods:
- virtual void draw - draws on the window
- virtual void update - updates the current state of the game
- virtual void handleInput - handles the user’s input
- GameStateStart - inherits from GameState, handles the main menu
Methods:
- void GameStateStart::loadGame - is used to start the next state, after the
player clicks “Play”
- GameStatePlay - inherits from GameState, handles the actual game itself
Methods:
- GameStatePlay::loadLevel - is used to read the current level layout from files
- GameStatePlay::brickUpdate - is used to handle processing related to bricks -
so collisions, chance to drop a powerup, etc.
- Game - responsible for running everything
Methods:
- void pushState - push the next state onto the stack
- void popState - remove a state from the stack
- GameState *peekState - returns a pointer to the state which is currently on
top of the stack
- void gameLoop - runs the game states

5. Source code
https://github.com/polsl-aei-cp3-makro/76ee6fd2-gr14-repo
6. Testing

The project was tested for memory leaks using Valgrind integrated in the CLion IDE. After
excluding leaks reported to be originating from external libraries (e.g., X11, the windowing
system on Linux) Valgrind hasn’t detected any memory leaks. The program uses only smart
pointers, like unique_ptr and all objects are correctly deleted.

You might also like