Assignment 2 Solution

$35.00 $30.80


In this assignment you will be writing the game that was presented in class.

This game must have the following features:



– The player is represented by a shape which is defined in the config file

– The player must spawn in the center of the screen at the beginning of the

game, and after it dies (collides with an enemy)

– The player moves by a speed read from the config file in these directions:

Up: W key, Left: A key, Down: S key, Right: R key

– The player is confined to move only within the bounds of the window

– The player will shoot a bullet toward the mouse pointer when the left mouse

button is clicked. The speed, size, and lifespan of the bullets are read

from the config file.

– You are free to come up with your own ‘special move’ which is fired by

the player when the right mouse button is clicked. This special move must

consist of more than one bullet which travels in an interesting way. The

properties of the special move are not in the config file.



– Enemies will spawn in a random location on the screen every X milliseconds,

where X is defined in the configuration file. Enemies must not overlap

the sides of the screen at the time of spawn.

– Enemies shapes have random number of vertices, between a given minimum and

maximum number, which is specified in the config file.

– Enemy shape radius will be specified in the configuration file.

– Enemies will be given a random color upon spawning.

– Enemies will be given a random speed upon spawning, between a minimum and

maximum value specified in the config file.

– When (large) enemies collide with a bullet or player, they are destroyed,

and N small enemies spawn in its place, where N is the number of vertices

of the original enemy. Each small enemy must have the same number of

vertices and color of the original enemy. These small entities travel

outward at angles at a fixed intervals equal to (360 / vertices).

For example, if the original enemy had 6 sides, the 6 smaller enemies will

travel outward in intervals of (360/6) = 60 degrees.



– Each time an enemy spawns, it is given a score component of N*100, where N

is the number of vertices it has. Small enemies get double this value.

– If a player bullet kills an enemy, the game score is increased by the score

component of the enemy killed.

– The score should be displayed with the font specified by the config file in

the top-left corner of the screen.



– In the render system, all entities should be given a slow rotation, which

makes the game look a little nicer.

– Any special effects which do not alter game play can be added for up to

5% bonus marks on the assignment. Note that assignments cannot go above

100% total marks, but the 5% bonus can overwrite any marks lost in other

areas of the assignment.

– Any Entity with a lifespan is currently alive, it should have its Color

alpha channel set to a ratio depending on how long it has left to live.

For example, if an Entity has a 1000ms life span, and it has been alive for

500ms, its alpha value should be set to 0.5 * 255. This ratio should go from

255 when it is first spawned, to 0 on the last frame it is alive.



– The ‘P’ key should pause the game

– The ‘ESC’ key should close the game


Configuration File:


The configuration file will have one line each specifying the window size,

font format, player, bullet specification, and enemy specifications.

Lines will be given in that order, with the following syntax:


Window W H FL FS

– This line declares that the SFML Window must be constructed with width W

and height H, each of which will be integers. FL is the frame limit that the

window should be set to, and FS will be an integer which specifies whether to

display the application in full-screen mode (1) or not (0).


Font F S R G B

– This lines defines the font which is to be used to draw text

for this program. The format of the line is as follows:

Font File        F        std::string (it will have no spaces)

Font Size        S        int

RGB Color        (R,G,B)  int, int, int


Player Specification:


Shape Radius      SR         int

Collision Radius  CR         int

Speed             S          float

Fill Color        FR,FG,FB   int,int,int

Outline Color     OR,OG,OB   int,int,int

Outline Thickness OT         int

Shape Vertices    V          int


Enemy Specification:


Shape Radius      SR        int

Collision Radius  CR        int

Min / Max Speed   SMIN,SMAX float, float

Outline Color     OR,OG,OB  int,int,int

Outline Thickness OT        int

Min/Max Vertices  VMIN,VMAX int,int

Small Lifespan    L         int

Spawn Interval    SP        int


Bullet Specification:


Shape Radius      SR         int

Collision Radius  CR         int

Speed             S          float

Fill Color        FR,FG,FB   int,int,int

Outline Color     OR,OG,OB   int,int,int

Outline Thickness OT         int

Shape Vertices    V          int

Lifespan          L          int



Assignment Hints



I recommend approaching this assignment in the following order:


  1. Save the configuration file reading until later, after Entities implemented
  2. Implement the Vec2 class, which you will use for all Components
  3. Implement the basic functionality in the EntityManager class

Implement the EntityManager’s addEntity() and update() functions so

you can start testing the Game class quickly. Don’t worry about the update()

function which deletes dead entities until later when you get more game

mechanics working.

  1. Implement basics of the Game class:
  2. Construct a player Entity using the spawnPlayer() function
  3. Implement basic drawing of entities using the Game::sRender() function
  4. Construct some enemies using the spawnEnemy() function
  5. Construct a bullet using the spawnBullet() function
  6. Implement Player Movement in Game::sUserInput and Game::sMovement
  7. Implement the EntityManager::update() function so it deletes dead entities
  8. Implement the EntityManager::getEntities(tag) functionality
  9. Implement collisions in sCollision and entity.destroy() if it’s dead
  10. Implement the rest of the game’s functionality, including config file reading