Breach

Check-in [08b33617a4]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:implemented the StateSplash class. setup gameloop and main function to load and unload the game properly. the game currently starts up and shows the splash screen for 60 frames before exiting. no art has been added yet so there is just a black screen, but the program is protected from segfaults due to missing images. next things to do are to add some basic art, implement STATE_PLAYING (jump straight there from splash, skip menus for now), and see if i can get the paddle on screen and rotating to mouse input
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:08b33617a4b7c0f75b79439632633f7c83eec7cf
User & Date: donnyjward@gmail.com 2010-09-10 07:16:12
Context
2010-09-11
20:07
added some graphics to test the rotating the paddle in a level. the paddle is rotated and displayed corretly. it moves continuously in a circle in 1 degree increments. check-in: 1d10f47a25 user: donnyjward@gmail.com tags: trunk
2010-09-10
07:16
implemented the StateSplash class. setup gameloop and main function to load and unload the game properly. the game currently starts up and shows the splash screen for 60 frames before exiting. no art has been added yet so there is just a black screen, but the program is protected from segfaults due to missing images. next things to do are to add some basic art, implement STATE_PLAYING (jump straight there from splash, skip menus for now), and see if i can get the paddle on screen and rotating to mouse input check-in: 08b33617a4 user: donnyjward@gmail.com tags: trunk
03:46
condensed the gameobject subclasses into 1 header/source pair check-in: 4a58ed9d53 user: donnyjward@gmail.com tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to breach.cpp.

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












#include <iostream>
#include "SDL/SDL.h"
#include "s_statemachine.h"








int DEBUG_MODE = 0;
int FULLSCREEN = 0;

//const vars default to static default (which limits the scope to the file its defined)
//so declare it extern in all files its used
extern const int COLORKEY_R = 78;
extern const int COLORKEY_G = 0;
extern const int COLORKEY_B = 63;






















void BreachLoop();


using namespace std;

int main( int argc, char * argv[] )
{
	int i;
	

	for ( i = 1; i < argc; i++ )
	{
		if ( !strcmp(argv[i], "-dev") ) //strings equal
			DEBUG_MODE = 1;
		else if ( !strcmp(argv[i], "-fullscreen") )
			FULLSCREEN = 1;
	}

	cout << "Exiting... (argc was " << argc << ")!!!!\n";

































	BreachLoop();
	return 0;
}

void BreachLoop()
{









}















>

>
>
>
>
>
>
|



|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>

<





>



|




|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>
>
|
>
|
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
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
#include <iostream>
#include "SDL/SDL.h"
#include "s_statemachine.h"
#include "r_graphics.h"

#include <string>

using namespace std;

static const string fileID = "[breach.cpp]: ";

int DEBUG = 0;
int FULLSCREEN = 0;

//const vars default to static default (which limits the scope to the file its defined)
//	so declare it extern in all files its used
extern const int COLORKEY_R = 78;
extern const int COLORKEY_G = 0;
extern const int COLORKEY_B = 63;

extern const int SCREEN_WIDTH = 800;
extern const int SCREEN_HEIGHT = 600;
extern const int SCREEN_BITDEPTH = 32;

//how long splash screen shows before moving to the next state
//	(measured frames)
extern const int SPLASH_DURATION = 60;

//target frame rate
extern const int FPS = 30;

//the main screen surface that will be blitted onto
//	and flipped
SDL_Surface * screen = NULL;

//the little icon for the window/taskbar
SDL_Surface * icon = NULL;

//from s_statemachine.cpp
extern StateMachine * gameState;

void BreachLoop();
void ExitProgram();



int main( int argc, char * argv[] )
{
	int i;
	
	//parse command line arguments
	for ( i = 1; i < argc; i++ )
	{
		if ( !strcmp(argv[i], "-dev") ) //strings equal
			DEBUG = 1;
		else if ( !strcmp(argv[i], "-fullscreen") )
			FULLSCREEN = 1;
	}

	//startup sdl library
	if ( SDL_Init( SDL_INIT_EVERYTHING ) != 0 )
	{
		if (DEBUG)
			cout << fileID << "SDL_Init failed, reason: " << SDL_GetError() << "\n";
		return -1;
	}
	
	//set window/taskbar caption and icon
	icon = r_loadImage("./graphics/icon.bmp");
	
	if (icon == NULL && DEBUG)
		cout << fileID << "load icon failed\n";
		
	SDL_WM_SetCaption("Breach", "Breach");
	SDL_WM_SetIcon(icon, NULL); //"must be done before first call to set video mode (below)
	
	//setup game window
	if (DEBUG)
		cout << fileID << "Setting video mode to " << SCREEN_WIDTH << "x" << SCREEN_HEIGHT << " resolution with " << SCREEN_BITDEPTH << " bit depth\n";
	
	if (FULLSCREEN)
		screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BITDEPTH, SDL_SWSURFACE | SDL_FULLSCREEN);
	else
		screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BITDEPTH, SDL_SWSURFACE);
		
	if (screen == NULL)
	{
		if (DEBUG)
			cout << fileID << "SDL_SetVideoMode failed to set " << SCREEN_WIDTH << "x" << SCREEN_HEIGHT << " resolution with " << SCREEN_BITDEPTH << " bit depth\n";
		return -1;
	}
	
	
	BreachLoop();
	return 0;
}

void BreachLoop()
{
	s_initStateMachine();
	gameState = new StateSplash();
	
	while ( s_getGameState() != STATE_EXIT )
	{
		gameState->HandleInput();
		gameState->UpdateGame();
		s_changeState();
		gameState->Render();
	}
	
	ExitProgram();
}

void ExitProgram()
{
	if (DEBUG)
		cout << fileID << "preparing to exit...\n";
		
	delete gameState;
	SDL_Quit();
}

Changes to defs.h.

1
2
3


4
5
6
7
8
9
10
11
12








13
14
15
16
17
18
19
#ifndef __DEFS_H__
#define __DEFS_H__



extern int DEBUG_MODE;
extern int FULLSCREEN;


//const vars default to static default (which limits the scope to the file its defined)
//so declare it extern in all files its used
extern const int COLORKEY_R;
extern const int COLORKEY_G;
extern const int COLORKEY_B;









typedef enum objectType_e
{
	//
} objectType_t;

typedef enum itemType_e



>
>
|




|



>
>
>
>
>
>
>
>







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
#ifndef __DEFS_H__
#define __DEFS_H__

#include "SDL/SDL.h"

extern int DEBUG;
extern int FULLSCREEN;


//const vars default to static default (which limits the scope to the file its defined)
//	so declare it extern in all files its used
extern const int COLORKEY_R;
extern const int COLORKEY_G;
extern const int COLORKEY_B;

//how long splash screen shows before moving to the next state
//	(in seconds)
extern const int SPLASH_DURATION;

//the main screen surface that will be blitted onto
//	and flipped
extern SDL_Surface * screen;

typedef enum objectType_e
{
	//
} objectType_t;

typedef enum itemType_e

Changes to g_gameobject.cpp.

1
2
3







4
5
6
7
8
9
10
//focus on getting 1 class at a time to work completely
#include "g_gameobject.h"








//gameobject functions
void GameObject::GetLoc(int & xloc, int & yloc)
{
	xloc = x;
	yloc = y;
}




>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//focus on getting 1 class at a time to work completely
#include "g_gameobject.h"

#include <iostream>
#include <string>

using namespace std;

static string fileID = "[g_gameobject.cpp]: ";

//gameobject functions
void GameObject::GetLoc(int & xloc, int & yloc)
{
	xloc = x;
	yloc = y;
}

Changes to g_gameobject.h.

1
2
3
4

5
6
7
8
9
10
11
#ifndef __G_GAMEOBJECT_H__
#define __G_GAMEOBJECT_H__

#include "defs.h"


class GameObject
{
	public:
		virtual void Draw() =0;
		virtual void OnCollide(GameObject * otherObject) =0;
		void GetLoc(int & xloc, int & yloc);




>







1
2
3
4
5
6
7
8
9
10
11
12
#ifndef __G_GAMEOBJECT_H__
#define __G_GAMEOBJECT_H__

#include "defs.h"


class GameObject
{
	public:
		virtual void Draw() =0;
		virtual void OnCollide(GameObject * otherObject) =0;
		void GetLoc(int & xloc, int & yloc);

Changes to r_graphics.cpp.

1
2
3







4
5
6
7
8
9
10
11
..
22
23
24
25
26
27
28













29
30
31
32
33
34
35
36
37
38
#include "r_graphics.h"
#include "defs.h"








SDL_Surface * r_loadImage(char * filename)
{
	SDL_Surface * loaded = NULL;
	SDL_Surface * image = NULL;
	Uint32 colorkey;
	
	loaded = SDL_LoadBMP(filename);
	
................................................................................
		return NULL;
		
	return image;
}

bool r_blitSurface(int x, int y, SDL_Surface * source, SDL_Surface * dest, SDL_Rect * clip)
{













	SDL_Rect offset;
	
	offset.x = x;
	offset.y = y;
	
	if ( SDL_BlitSurface(source, clip, dest, &offset) < 0 ) //<0 = fail
		return false;
	else
		return true;
}



>
>
>
>
>
>
>
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>










1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
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
#include "r_graphics.h"
#include "defs.h"

#include <iostream>
#include <string>

using namespace std;

static string fileID = "[r_graphics]: ";

SDL_Surface * r_loadImage(const char * filename)
{
	SDL_Surface * loaded = NULL;
	SDL_Surface * image = NULL;
	Uint32 colorkey;
	
	loaded = SDL_LoadBMP(filename);
	
................................................................................
		return NULL;
		
	return image;
}

bool r_blitSurface(int x, int y, SDL_Surface * source, SDL_Surface * dest, SDL_Rect * clip)
{
	if (source == NULL)
	{
		if (DEBUG)
			cout << fileID << "an invalid source image was requested to be blitted\n";
		return false;
	}
	else if (dest == NULL)
	{
		if (DEBUG)
			cout << fileID << "an invalid surface was requested to be blitted on\n";
		return false;
	}
	
	SDL_Rect offset;
	
	offset.x = x;
	offset.y = y;
	
	if ( SDL_BlitSurface(source, clip, dest, &offset) < 0 ) //<0 = fail
		return false;
	else
		return true;
}

Changes to r_graphics.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef __R_GRAPHICS_H__
#define __R_GRAPHICS_H__

#include "SDL/SDL.h"

//loads a bmp file and returns the SDL_Surface
SDL_Surface * r_loadImage(char * filename);

//Pastes a surface onto the screen with location from top left corner
//	and optionally only a partial section of the surface (clip).
//Does not auto free source surface.
//x and y had default parameters of 0, but in c++ all parameters
//	default parameters must be default as well, so I just left it out
bool r_blitSurface(int x, int y, SDL_Surface * source, SDL_Surface * dest, SDL_Rect * clip = NULL);

#endif






|









1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef __R_GRAPHICS_H__
#define __R_GRAPHICS_H__

#include "SDL/SDL.h"

//loads a bmp file and returns the SDL_Surface
SDL_Surface * r_loadImage(const char * filename);

//Pastes a surface onto the screen with location from top left corner
//	and optionally only a partial section of the surface (clip).
//Does not auto free source surface.
//x and y had default parameters of 0, but in c++ all parameters
//	default parameters must be default as well, so I just left it out
bool r_blitSurface(int x, int y, SDL_Surface * source, SDL_Surface * dest, SDL_Rect * clip = NULL);

#endif

Changes to r_sound.cpp.

1







#include "r_sound.h"








>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
#include "r_sound.h"

#include <iostream>
#include <string>

using namespace std;

static string fileID = "[r_sound.cpp]: ";

Changes to s_statemachine.cpp.

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
..
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
..
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
...
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
...
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301


#include "s_statemachine.h"




















































































/************************************************
*                                               *
*	STATE_SPLASH                            *
*                                               *
************************************************/
StateSplash::StateSplash()
{






	//load background image;





}

StateSplash::~StateSplash()
{
	SDL_FreeSurface(background);



}

void StateSplash::HandleInput()
{











}

void StateSplash::UpdateGame()
{






}


void StateSplash::DrawGame()
{
	//blit background image




}

/************************************************
*                                               *
*	STATE_MMAIN                             *
*                                               *
************************************************/
................................................................................
{

}
void StateMenuMain::UpdateGame()
{

}
void StateMenuMain::DrawGame()
{

}

/************************************************
*                                               *
*	STATE_MCHOOSEDIFFICULTY                 *
................................................................................
}

void StateMenuChooseDifficulty::UpdateGame()
{

}

void StateMenuChooseDifficulty::DrawGame()
{

}

/************************************************
*                                               *
*	STATE_MLISTSAVEGAMES                    *
................................................................................
}

void StateMenuListSaveGames::UpdateGame()
{

}

void StateMenuListSaveGames::DrawGame()
{

}

/************************************************
*                                               *
*	STATE_MOPTIONS                          *
................................................................................
}

void StateMenuOptions::UpdateGame()
{

}

void StateMenuOptions::DrawGame()
{

}

/************************************************
*                                               *
*	STATE_MCONTROLS                         *
................................................................................
}

void StateMenuControls::UpdateGame()
{

}

void StateMenuControls::DrawGame()
{

}

/************************************************
*                                               *
*	STATE_MCONFIRMEXIT                      *
................................................................................
}

void StateMenuConfirmExit::UpdateGame()
{

}

void StateMenuConfirmExit::DrawGame()
{

}

/************************************************
*                                               *
*	STATE_MCREDITS                          *
................................................................................
}

void StateMenuCredits::UpdateGame()
{

}

void StateMenuCredits::DrawGame()
{

}

/************************************************
*                                               *
*	STATE_MHIGHSCORES                       *
................................................................................
}

void StateMenuHighScores::UpdateGame()
{

}

void StateMenuHighScores::DrawGame()
{

}

/************************************************
*                                               *
*	STATE_PLAYING                           *
................................................................................
}

void StatePlaying::UpdateGame()
{

}

void StatePlaying::DrawGame()
{

}

//STATE_EXIT
//STATE_NULL



>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







>
>
>
>
>
>
|
>
>
>
>
>





>
>
>




>
|
>
>
>
>
>
>
>
>
>




>
>
>
|
>
>
|
|
>
|


>
>
>
>







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|






>
>
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
...
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
...
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
...
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
...
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
...
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
...
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#include "s_statemachine.h"
#include "r_graphics.h"

#include <iostream>
#include <string>

using namespace std;

static string fileID = "[s_statemachine.cpp]: ";

gameState_t currentStateID = STATE_NULL;
gameState_t nextStateID = STATE_NULL;

StateMachine * gameState;

void s_initStateMachine()
{
	currentStateID = STATE_SPLASH;
}

gameState_t s_getGameState()
{
	return currentStateID;
}

void s_setNextState( gameState_t requestedState)
{
	//if exit was requested at all during this frame,
	//	all other requests are ignored for this frame
	if (nextStateID != STATE_EXIT)
		nextStateID = requestedState;
}

void s_changeState()
{
	if (nextStateID != STATE_NULL)
	{
		//STATE_EXIT is not deleted because its needed
		//	for the final rendered frame in the
		//	last loop of the game loop
		if (nextStateID != STATE_EXIT)
			delete gameState;
			
		switch (nextStateID)
		{
			case STATE_SPLASH:
				gameState = new StateSplash();
				break;
			case STATE_MMAIN:
				gameState = new StateMenuMain();
				break;
			case STATE_MCHOOSEDIFFICULTY:
				gameState = new StateMenuChooseDifficulty();
				break;
			case STATE_MLISTSAVEGAMES:
				gameState = new StateMenuListSaveGames();
				break;
			case STATE_MOPTIONS:
				gameState = new StateMenuOptions();
				break;
			case STATE_MCONTROLS:
				gameState = new StateMenuControls();
				break;
			case STATE_MCONFIMEXIT:
				gameState = new StateMenuConfirmExit();
				break;
			case STATE_MCREDITS:
				gameState = new StateMenuCredits();
				break;
			case STATE_MHIGHSCORES:
				gameState = new StateMenuHighScores();
				break;
			case STATE_PLAYING:
				gameState = new StatePlaying();
				break;
			//case STATE_EXIT:
			//case STATE_NULL:
			//default:
		}
		
		currentStateID = nextStateID;
		nextStateID = STATE_NULL;
	}
}

/************************************************
*                                               *
*	STATE_SPLASH                            *
*                                               *
************************************************/
StateSplash::StateSplash()
{
	if (DEBUG)
		cout << fileID << "splash screen activated\n";
		
	background = r_loadImage("./graphics/background_splash.bmp");
	
	if (background == NULL && DEBUG)
		cout << fileID << "load background image failed\n";
		
	frame = 0;
	
	//hide cursor during splash screen
	SDL_ShowCursor(SDL_DISABLE);
}

StateSplash::~StateSplash()
{
	SDL_FreeSurface(background);
	
	if (DEBUG)
		cout << fileID << "splash screen deactivated\n";
}

void StateSplash::HandleInput()
{
	SDL_Event event;
	
	while ( SDL_PollEvent(&event) ) //returns 1 until no more eventz
	{
		switch (event.type)
		{
			case SDL_QUIT:
				s_setNextState(STATE_EXIT);
				break;
		}
	}
}

void StateSplash::UpdateGame()
{
	if (frame >= SPLASH_DURATION)
		s_setNextState(STATE_EXIT);
	else
	{
		cout << fileID << "frame = " << frame << "\n";
		frame++;
	}
}

void StateSplash::Render()
{
	//blit background image
	if ( !r_blitSurface(0, 0, background, screen) && DEBUG )
		cout << fileID << "blit background image failed\n";
		
	SDL_Flip(screen);
}

/************************************************
*                                               *
*	STATE_MMAIN                             *
*                                               *
************************************************/
................................................................................
{

}
void StateMenuMain::UpdateGame()
{

}
void StateMenuMain::Render()
{

}

/************************************************
*                                               *
*	STATE_MCHOOSEDIFFICULTY                 *
................................................................................
}

void StateMenuChooseDifficulty::UpdateGame()
{

}

void StateMenuChooseDifficulty::Render()
{

}

/************************************************
*                                               *
*	STATE_MLISTSAVEGAMES                    *
................................................................................
}

void StateMenuListSaveGames::UpdateGame()
{

}

void StateMenuListSaveGames::Render()
{

}

/************************************************
*                                               *
*	STATE_MOPTIONS                          *
................................................................................
}

void StateMenuOptions::UpdateGame()
{

}

void StateMenuOptions::Render()
{

}

/************************************************
*                                               *
*	STATE_MCONTROLS                         *
................................................................................
}

void StateMenuControls::UpdateGame()
{

}

void StateMenuControls::Render()
{

}

/************************************************
*                                               *
*	STATE_MCONFIRMEXIT                      *
................................................................................
}

void StateMenuConfirmExit::UpdateGame()
{

}

void StateMenuConfirmExit::Render()
{

}

/************************************************
*                                               *
*	STATE_MCREDITS                          *
................................................................................
}

void StateMenuCredits::UpdateGame()
{

}

void StateMenuCredits::Render()
{

}

/************************************************
*                                               *
*	STATE_MHIGHSCORES                       *
................................................................................
}

void StateMenuHighScores::UpdateGame()
{

}

void StateMenuHighScores::Render()
{

}

/************************************************
*                                               *
*	STATE_PLAYING                           *
................................................................................
}

void StatePlaying::UpdateGame()
{

}

void StatePlaying::Render()
{

}

//STATE_EXIT
//STATE_NULL


Changes to s_statemachine.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

160
#ifndef __STATEMACHINE_H__
#define __STATEMACHINE_H__

#include "SDL/SDL.h"
#include "defs.h"










class StateMachine //abstract base class
{
	public:
		virtual void HandleInput() =0;
		virtual void UpdateGame() =0;
		virtual void DrawGame() =0;
		
		virtual ~StateMachine() { };
};





class StateSplash : public StateMachine
{
	public:
		StateSplash();
		~StateSplash();
		
		void HandleInput();
		void UpdateGame();
		void DrawGame();
		
	private:
		SDL_Surface * background;

};

class StateMenuMain : public StateMachine
{
	public:
		StateMenuMain();
		~StateMenuMain();
	
		void HandleInput();
		void UpdateGame();
		void DrawGame();
		
	private:
		SDL_Surface * background;
};

class StateMenuChooseDifficulty : public StateMachine
{
	public:
		StateMenuChooseDifficulty();
		~StateMenuChooseDifficulty();
	
		void HandleInput();
		void UpdateGame();
		void DrawGame();
		
	private:
		SDL_Surface * background;
};

class StateMenuListSaveGames : public StateMachine
{
	public:
		StateMenuListSaveGames();
		~StateMenuListSaveGames();
	
		void HandleInput();
		void UpdateGame();
		void DrawGame();
		
	private:
		SDL_Surface * background;
};

class StateMenuOptions : public StateMachine
{
	public:
		StateMenuOptions();
		~StateMenuOptions();
	
		void HandleInput();
		void UpdateGame();
		void DrawGame();
		
	private:
		SDL_Surface * background;
};

class StateMenuControls : public StateMachine
{
	public:
		StateMenuControls();
		~StateMenuControls();
		
		void HandleInput();
		void UpdateGame();
		void DrawGame();
		
	private:
		SDL_Surface * background;
};

class StateMenuConfirmExit : public StateMachine
{
	public:
		StateMenuConfirmExit();
		~StateMenuConfirmExit();
	
		void HandleInput();
		void UpdateGame();
		void DrawGame();
		
	private:
		SDL_Surface * background;
};

class StateMenuCredits : public StateMachine
{
	public:
		StateMenuCredits();
		~StateMenuCredits();
	
		void HandleInput();
		void UpdateGame();
		void DrawGame();
		
	private:
		SDL_Surface * background;
};

class StateMenuHighScores : public StateMachine
{
	public:
		StateMenuHighScores();
		~StateMenuHighScores();
	
		void HandleInput();
		void UpdateGame();
		void DrawGame();
		
	private:
		SDL_Surface * background;
};

class StatePlaying : public StateMachine
{
	public:
		StatePlaying();
		~StatePlaying();
	
		void HandleInput();
		void UpdateGame();
		void DrawGame();
		
	private:
		SDL_Surface * background;
};

void set_next_state( gameState_e nextState);
void change_state();


#endif





>
>
>
>
>
>
>
>
>






|




>
>
>
>








|



>










|













|













|













|













|













|













|













|













|





<
<

>

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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170


171
172
173
#ifndef __STATEMACHINE_H__
#define __STATEMACHINE_H__

#include "SDL/SDL.h"
#include "defs.h"

//sets up the initial state of this state machine
void s_initStateMachine();

//used by main loop to fetch currentStateID
gameState_t s_getGameState();

void s_setNextState(gameState_e requestedState);
void s_changeState();

class StateMachine //abstract base class
{
	public:
		virtual void HandleInput() =0;
		virtual void UpdateGame() =0;
		virtual void Render() =0;
		
		virtual ~StateMachine() { };
};

//splash screen
//	current behavior is to just display splash image
//	for about 2 seconds, ignoring all input (except exit)
//	and then moving to the next state
class StateSplash : public StateMachine
{
	public:
		StateSplash();
		~StateSplash();
		
		void HandleInput();
		void UpdateGame();
		void Render();
		
	private:
		SDL_Surface * background;
		int frame;
};

class StateMenuMain : public StateMachine
{
	public:
		StateMenuMain();
		~StateMenuMain();
	
		void HandleInput();
		void UpdateGame();
		void Render();
		
	private:
		SDL_Surface * background;
};

class StateMenuChooseDifficulty : public StateMachine
{
	public:
		StateMenuChooseDifficulty();
		~StateMenuChooseDifficulty();
	
		void HandleInput();
		void UpdateGame();
		void Render();
		
	private:
		SDL_Surface * background;
};

class StateMenuListSaveGames : public StateMachine
{
	public:
		StateMenuListSaveGames();
		~StateMenuListSaveGames();
	
		void HandleInput();
		void UpdateGame();
		void Render();
		
	private:
		SDL_Surface * background;
};

class StateMenuOptions : public StateMachine
{
	public:
		StateMenuOptions();
		~StateMenuOptions();
	
		void HandleInput();
		void UpdateGame();
		void Render();
		
	private:
		SDL_Surface * background;
};

class StateMenuControls : public StateMachine
{
	public:
		StateMenuControls();
		~StateMenuControls();
		
		void HandleInput();
		void UpdateGame();
		void Render();
		
	private:
		SDL_Surface * background;
};

class StateMenuConfirmExit : public StateMachine
{
	public:
		StateMenuConfirmExit();
		~StateMenuConfirmExit();
	
		void HandleInput();
		void UpdateGame();
		void Render();
		
	private:
		SDL_Surface * background;
};

class StateMenuCredits : public StateMachine
{
	public:
		StateMenuCredits();
		~StateMenuCredits();
	
		void HandleInput();
		void UpdateGame();
		void Render();
		
	private:
		SDL_Surface * background;
};

class StateMenuHighScores : public StateMachine
{
	public:
		StateMenuHighScores();
		~StateMenuHighScores();
	
		void HandleInput();
		void UpdateGame();
		void Render();
		
	private:
		SDL_Surface * background;
};

class StatePlaying : public StateMachine
{
	public:
		StatePlaying();
		~StatePlaying();
	
		void HandleInput();
		void UpdateGame();
		void Render();
		
	private:
		SDL_Surface * background;
};





#endif