-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.h
140 lines (104 loc) · 3.47 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma once
#include "BulletType.h"
#include "ColorRect.h"
#include "Controller.h"
#include "GameState.h"
#include "InvaderGroup.h"
#include "ParticleCloudProperties.h"
#include "Quadtree.h"
#include "SDLWindow.h"
#include "Sprite.h"
#include "StopWatch.h"
#include "Test.h"
#include <memory>
#include <vector>
using std::shared_ptr;
class Bullet;
class Bunker;
class GameOverScreen;
class Invader;
class InvaderGroup;
class Item;
class Particle;
class Player;
class ScoreDisplay;
class TitleScreen;
class UFO;
class Game {
float clockThisFrame = 0, dt = 0;
StopWatch clock;
int engineIterationPerFrame = 1; // process multiple game steps / display interval
shared_ptr<TitleScreen> titleScreen;
shared_ptr<GameOverScreen> gameOverScreen;
// Collideable:
vector< shared_ptr<Bullet> > allBullets;
vector< shared_ptr<Bunker> > allBunkers;
InvaderGroup invaderGroup;
vector< shared_ptr<Item> > allItems;
shared_ptr<Player> player;
vector< shared_ptr<UFO> > allUFOs;
// Cosmetic
shared_ptr<Sprite> pausedText;
vector< shared_ptr<Particle> > allParticles;
vector< shared_ptr<ScoreDisplay> > allScores;
vector< shared_ptr<Sprite> > playOnceAnimations;
vector< shared_ptr<Sprite> > playerLives;
string debugText;
shared_ptr<Sprite> debugTextSprite;
Test test;
SDL_Color bkgColor; // the current background color
int score = 0;
shared_ptr<Sprite> scoreSprite;
// You get a UFO every (interval) sec.
float nextUFO = 5;
GameState prevState = GameState::Title;
GameState gameState = GameState::Title;
vector<uint16_t> startKeys = { SDL_SCANCODE_RETURN, SDL_SCANCODE_RETURN2, SDL_SCANCODE_KP_ENTER };
Controller controller;
float shakeTimeRemaining = 0;
inline static const float ShakeMagnitude = 25;
Quadtree quadtree;
vector<ColorRect> debugRects;
void initGameBoard();
void clearGameBoard();
void togglePause();
void genUFO();
int getNumBullets( bool isFromInvader );
void checkWinConditions();
void checkBulletCollisions_basic();
void checkAllCollisions_basic();
void buildQuadtree();
void checkAllCollisions_quadtree();
void clearDead();
void runGame();
void updateNumberOfPlayerLives();
void controllerUpdateTitle();
void controllerUpdateRunning();
void controllerUpdate();
public:
Game( const RectF &bounds );
~Game() { }
void init();
inline bool isState( GameState state ) { return gameState == state; }
void setState( GameState newState );
void setKeyJustPressed( uint16_t key );
void setMouseJustClicked( uint16_t mouseButton );
// Things to happen in the game when the player dies
void playerDie();
void shakeScreen( float shakeTime );
// Player shoots from top, invaders from their bottom.
void tryShootBullet( BulletType bulletType, const Vector2f &shootPoint );
// Plays a sprite animation ONCE where you want it
void playSpriteAnimation( const RectF &where, AnimationId animationId );
// Generates numParticles that are inside `insideBoxArea`
void particleCloud( const RectF &insideBoxArea, const ParticleCloudProperties &particleCloudProperties );
void createItem( const Vector2f &pos, AnimationId animationId );
void displayScore( int score, const Vector2f &pos, SDL_Color color );
void setScore( int newScore );
void changeScore( int byScoreValue );
void update();
void draw();
void drawDebug();
void addDebugRect( const RectF &rect, SDL_Color color, float lifetime = 1 );
};
extern shared_ptr<Game> game;