File: thegame.c

package info (click to toggle)
ketm 0.0.6-17sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 9,356 kB
  • ctags: 875
  • sloc: ansic: 7,303; sh: 410; makefile: 185
file content (190 lines) | stat: -rw-r--r-- 4,273 bytes parent folder | download | duplicates (3)
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "thegame.h"

extern SDL_Surface *screen;
extern int keyboard[];
extern SPRITE *player;
extern GAMESTATE state;
extern KEYCONFIG keyconfig;
extern HSC_LIST hsc_table[];
extern int lastscore;
extern LEVELENTRY *leveltab;

int world_y;
int world_dir=1;
int gframe;
int gameover_delay;
Uint32 level_start_time;
Uint32 game_start_time;
Uint32 level_pause_start;

void thegame_init()
{
	int level;

	gframe=0;
	gameover_delay=100;
	controller_remove_all();
	player_init();
	game_start_time=SDL_GetTicks();
	level_start_time=SDL_GetTicks();
	level_pause_start=0;

	level=((PLAYER_DATA *)player->data)->level;

	if(loadlv(level)==0)
		error(ERR_WARN,"no entrys for level %d",level);
}


void thegame_work()
{
	PLAYER_DATA *d=(PLAYER_DATA *)player->data;
	Uint32 gt;
	LEVELENTRY *l;
	int *level=&d->level;

	if(state.mainstate!=ST_GAME_PLAY || state.newstate==1) return;

	/* gt=Zeit seit Spielbeginn in 1/10 sec. */
	if(level_pause_start>0) {
		level_start_time+=SDL_GetTicks()-level_pause_start;
		level_pause_start=0;
	}
	gt=(SDL_GetTicks()-level_start_time)/100;

	if(d->lives>0) {
		if(keyboard[keyconfig.e]) {
			level_pause_start=SDL_GetTicks();
			newstate(ST_MENU,MEN_PAUSE,1);
		}

		l=leveltab;
		while(l!=NULL) {
			if((gt>=l->time)&&(l->done==0)) {
				thegame_level(l);
				l->done=1;
			}
			l=l->next;
		}

		if(((PLAYER_DATA *)player->data)->bossmode==2) {
			((PLAYER_DATA *)player->data)->bossmode=0;
			level_start_time=SDL_GetTicks();
			(*level)++;
			if(*level==4) {
				error(ERR_DEBUG,"sorry, no more levels in this alpha-version");
				d->lives=0;
				return;
			}
			/* Load next level */
			if(loadlv(*level)==0)
				error(ERR_WARN,"no entrys for level %d",*level);
		}
			
		
		bg_work();
		sprite_work(SP_SHOW_ALL);
		sprite_display(SP_SHOW_ALL);
		controller_work();
		parsys_display();
		score_display();
		gframe++;

	} else {
		player->flags&=~SP_FLAG_VISIBLE;
		if(gameover_delay) {
			gameover_delay--;
			bg_work();
			controller_work();
			sprite_work(SP_SHOW_ALL);
			sprite_display(SP_SHOW_ALL);
			parsys_display();
			score_display();
		} else {
			bg_destroy();
			lastscore=((PLAYER_DATA *)player->data)->score;
			controller_remove_all();
			sprite_remove_all(SP_SHOW_ALL);
			parsys_remove_all();
			score_cleanup();
			newstate(ST_GAME_OVER,0,1);
		}
	}
}


void thegame_level(LEVELENTRY *l)
{
	switch(l->command) {
	case 'E':
		/* add enemy */
		if(!strcmp(l->para1,"XEV")) {
			enemy_xev_add(l->para2);
		} else if(!strcmp(l->para1,"CRUSHER")) {
			enemy_crusher_add(l->para2);
		} else if(!strcmp(l->para1,"EYEFO")) {
			enemy_eyefo_add(l->para2);
		} else if(!strcmp(l->para1,"CUBE")) {
			enemy_cube_add(l->para2);
		} else if(!strcmp(l->para1,"DRAGER")) {
			enemy_drager_add(l->para2);
		} else if(!strcmp(l->para1,"MINE")) {
			enemy_mine_add(l->para2);
		} else if(!strcmp(l->para1,"RWINGX")) {
			enemy_rwingx_add(l->para2);
		} else if(!strcmp(l->para1,"CIR")) {
			enemy_cir_add(l->para2);
		} else if(!strcmp(l->para1,"ZATAK")) {
			enemy_zatak_add(l->para2);
		} else if(!strcmp(l->para1,"BADGUY")) {
			enemy_badguy_add(l->para2);
		} else if(!strcmp(l->para1,"PROBALL")) {
			enemy_proball_add(l->para2);
		} else if(!strcmp(l->para1,"PLASMABALL")) {
			enemy_plasmaball_add(l->para2);
		} else if(!strcmp(l->para1,"MING")) {
			enemy_ming_add(l->para2);
		} else if(!strcmp(l->para1,"GREETER")) {
			enemy_greeter_add(l->para2);
		} else if(!strcmp(l->para1,"CURVER")) {
			enemy_curver_add(l->para2);
		} else if(!strcmp(l->para1,"BOSS01")) {
			enemy_boss01_add(l->para2);
		} else if(!strcmp(l->para1,"BOSS02")) {
			enemy_boss02_add(l->para2);
		} else if(!strcmp(l->para1,"BOSS03")) {
			enemy_boss03_add(l->para2);
		} else {
			error(ERR_WARN,"unknown enemy '%s'",l->para1);
		}

		break;
	case 'T':
		/* text */
		enemy_gametext_add(l->para1,l->para2);
		break;
	case 'B':
		/* Background */
		bg_destroy();
		switch(l->para2) {
		case 0: /* Clouds */
			bg_init(BG_CLOUDS);
			break;
		case 1: /* Stars */
			bg_init(BG_STARS);
			break;
		case 2: /* Tile */
			bg_init(BG_TILE);
			break;
		default:
			error(ERR_WARN,"unknown background %d, using clouds",l->para2);
			bg_init(BG_CLOUDS);
			break;
		}
		break;
			
	default:
		error(ERR_WARN,"unknown command '%c' in levelfile",l->command);
	}
}