forked from martin-segersten/space_war
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGamestates.h
executable file
·118 lines (104 loc) · 2.55 KB
/
Gamestates.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
/*
* Gamestates.h
*
* Created on: Jan 19, 2012
* Author: msegersten
*/
#ifndef GAMESTATES_H_
#define GAMESTATES_H_
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#include <string>
#include "Objects.h"
#include "timer.h"
#include <vector>
#include <cstdlib>
#include <sstream>
#define FONT_PATH "files/8bit.ttf"
#define FONT_SIZE 14
#define NUMBER_OF_MENU_ITEMS 4
#define NUMBER_OF_INTRO_MESSAGES 2
#define NUMBER_OF_HUD_MESSAGES 5
#define NUMBER_OF_CREDITS 7
#define DISPLAY_READY_MSG 3
#define DISPLAY_LVL_COMPLETE 4
#define DISPLAY_GAME_OVER 6
enum STATES {
GAMESTATE_GAMEPLAY,
GAMESTATE_INTRO,
GAMESTATE_CREDITS,
GAMESTATE_EXIT,
GAMESTATE_MENU,
};
class Gamestate {
protected:
u_int8_t id;
u_int8_t next_state;
u_int32_t time;
SDL_Surface** messages;
int* message_width;
public:
static TTF_Font *gamefont;
static SDL_Color font_color;
virtual ~Gamestate();
void setNextState(u_int8_t i);
int nextState();
int currentState();
virtual void handleInput(SDL_Event &event) = 0;
virtual void update(u_int32_t delta_timer) = 0;
virtual void render(SDL_Surface * screen) = 0;
};
class Gamestate_Intro : public Gamestate {
public:
Gamestate_Intro();
~Gamestate_Intro();
void handleInput(SDL_Event &event);
void update(u_int32_t delta_timer);
void render(SDL_Surface * screen);
};
class Gamestate_Menu : public Gamestate {
private:
u_int8_t select;
public:
Gamestate_Menu();
~Gamestate_Menu();
void handleInput(SDL_Event &event);
void update(u_int32_t delta_timer);
void render(SDL_Surface * screen);
};
class Gamestate_Gameplay : public Gamestate{
private:
Player* player1;
Timer delta_timer;
std::vector<Asteroid*> asteroids;
std::stringstream dataToString;
int level;
int asteroidsLeft;
bool displayReady;
bool gameOver;
public:
Gamestate_Gameplay();
~Gamestate_Gameplay();
void handleInput(SDL_Event &event);
void update(u_int32_t delta_timer);
void render(SDL_Surface * screen);
void initiateLevel();
void renderHUD(SDL_Surface * screen);
};
class Gamestate_Exit : public Gamestate{
public:
Gamestate_Exit();
~Gamestate_Exit();
void handleInput(SDL_Event &event);
void update(u_int32_t delta_timer);
void render(SDL_Surface * screen);
};
class Gamestate_Credits : public Gamestate{
public:
Gamestate_Credits();
~Gamestate_Credits();
void handleInput(SDL_Event &event);
void update(u_int32_t delta_timer);
void render(SDL_Surface * screen);
};
#endif /* GAMESTATES_H_ */