Capstone project in the Udacity C++ Nanodegree Program. The code for this repo was inspired by this excellent StackOverflow post and set of responses.
https://github.com/RomanMayer7
In this project, i am building C++ application , following the principles i have learned throughout this Nanodegree Program.
- cmake >= 3.7
- All OSes: click here for installation instructions
- make >= 4.1 (Linux, Mac), 3.81 (Windows)
- Linux: make is installed by default on most Linux distros
- Mac: install Xcode command line tools to get make
- Windows: Click here for installation instructions
- SDL2 >= 2.0
- All installation instructions can be found here
Note that for Linux, an
apt
orapt-get
installation is preferred to building from source. - gcc/g++ >= 5.4
- Linux: gcc / g++ is installed by default on most Linux distros
- Mac: same deal as make - install Xcode command line tools
- Windows: recommend using MinGW
- Clone this repo.
- Make a build directory in the top level directory:
mkdir build && cd build
- Compile:
cmake .. && make
- Run it:
./AeroInvaders
.
The application consists of the main()
function and three manager classes,one renderer class and one controller class
Also there are number of infrastructure classes: Sprite
,Sprite2D
,RColor
,RectSprite
,BitmapSprite
,BitmapLoop
,MissleSprite
,PlayerSprite
,BitmapSprite
,EnemySprite
And two interfaces:Movable
,Intersect
-
GameManager
: contains main game loop and game logic.it manages instances of two other managers:PlayerManager
,EnemyManager
Also have instance ofController
andRenderer
classes.- Objects:
renderer
,controller
,em
,pm
- Getters/Setters/Initializators:
init
- Behaviour methods:
incrementScore
,alienLanded
,newGame
,gameOver
,updateManagers
,paint
,run
,stop
- Objects:
-
PlayerManager
: manages the behaviour of Aircraft controlled by Player viaController
and renders it viaRenderer
.- Objects:
missile
,gun
,renderer
- Getters/Setters/Initializators:
getGunY
,getGunX
,getGun
- Behaviour methods:
newGame
,moveGun
,fireMissile
,handleHit
,update
,paint
- Objects:
-
EnemyManager
: manages the behaviour of Enemy aircrafts controlled by AI and renders them with help ofRenderer
.- Objects:
gm
,pm
,renderer
,enemies
- Getters/Setters/Initializators:
initialize
,InitializeManager
,setStartLevel
,initializePosition
,getEnemies
- Behaviour methods:
newGame
,killed
,paintAll
,update
- Objects:
-
Controller
: is responsible for player's controlls- Objects:
player
,player_manager
- Behaviour methods:
HandleInput
- Objects:
-
Renderer
: is responsible for rendering game objects such as ,MissleSprite
,PlayerSprite
,EnemySprite
.- Objects:
background_texture
,aircraft_texture
,enemy_textures
,enemy_attack_textures
,enemy_explode_textures
- Behaviour methods:
Render
,UpdateWindowTitle
,UpdateWindowTitleEndGame
,loadMedia
,draw_rectangle
- Objects:
The main()
function instantiates an object for each class and then runs the simulation in an infinite loop. The application is run in a single thread. A future implementation could add concurrency, though it's not necessary since the application is plenty fast.
-
The project demonstrates an understanding of C++ functions and control structures:
missle_sprite.cpp
lines 93-162 is a good example of constrol structures using IF conditions and FOR loops -
The project uses Object Oriented Programming techniques: the project has many infrastructure classes with rich inheritance chains. The
EnemySprite
inherits fromBitmapLoop
and implementsIntersect
interface TheBitmapLoop
inherits fromBitmapSprite
and implementsMoveable
interface TheBitmapSprite
inherits fromSprite2D
which inherits fromSprite
-
Classes use appropriate access specifiers for class members: The EnemyManager class declaration in
enemy_manager.hpp
shows the use of thepublic
(line 13) andprivate
(line 67) access specifiers. -
Class constructors utilize member initialization lists: The MissileSprite class constructors on lines 8,23,40 and 57 in
missle_sprite.hpp
use Initializer Lists. -
The project uses smart pointers instead of raw pointers: lines 46 to 49 in
game_manager.hpp
are a good example of the use ofshared_ptr
for shared class objects.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.