-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.h
89 lines (70 loc) · 1.89 KB
/
Game.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#if !defined(GAME_H)
#define GAME_H
#include <SFML/Graphics.hpp>
#include "Body.h"
#include "collisions.h"
using namespace A6;
/**
* An asteroids clone, where the asteroids are represented by triangle fans
* that are split apart by the player's bullets.
*
* Controls: Left/right arrows to rotate. Up to apply thrust. Space to shoot.
*
* @author Andrew Vardy
*/
class Game {
public:
/**
* Possible game states. Could potentially introduce others (e.g. PAUSED).
*/
enum class State { PLAYING, GAME_OVER };
/**
* Construct the Game, including opening the window and creating
* any entities that will populate the world.
*/
Game();
/**
* The main game loop. This function will not return until the user has
* closed the window.
*/
void loop();
private:
/**
* Launch a bullet (meaning add a bullet at the player's location.
*/
void launchBullet();
/**
* Update the window's title to show some statistics.
*/
void updateTitle();
/**
* Handle collisions between all three types of bodies.
*/
void handleCollisions();
/**
* Handle removal of bodies that have died of old age.
*/
void handleBullets();
/**
* Modified the velocities of entities to account for any collisions.
* Update all entity positions.
*/
void applyPhysics(vector<Body*> bodies);
/**
* Draw all entities.
*/
void draw(vector<Body*> bodies);
/**
* Put together a special TriFan for the player's body.
*/
TriFan* createPlayerTriFan();
sf::RenderWindow m_window;
// The characters: player, asteroids and bullets.
Body m_player;
vector<Body> m_asteroids;
vector<Body> m_bullets;
State m_state;
// If this is positive, then we need to wait before launching another bullet.
int m_bulletWait = 0;
};
#endif // !defined(GAME_H)