-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrr.c
381 lines (347 loc) · 6.97 KB
/
rr.c
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/*
* $Id: rr.c 333 2005-12-16 06:41:21Z mrbrown $
*
* Copyright 2003 Kenta Cho. All rights reserved.
*/
/**
* rRootage main routine.
*
* @version $Revision: 333 $
*/
#include "SDL.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "rr.h"
#include "screen.h"
#include "vector.h"
#include "foe_mtd.h"
#include "brgmng_mtd.h"
#include "degutil.h"
#include "boss_mtd.h"
#include "ship.h"
#include "laser.h"
#include "frag.h"
#include "shot.h"
#include "background.h"
#include "soundmanager.h"
#include "attractmanager.h"
#ifdef PSP
#include <pspkernel.h>
#if PSP_FW_VERSION >= 371
#undef SDL_main
#endif
PSP_MODULE_INFO("rRootage", PSP_MODULE_USER, 0, 1);
PSP_HEAP_SIZE_KB(-128);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | PSP_THREAD_ATTR_VFPU);
#endif
static int noSound = 0;
// Initialize and load preference.
static void initFirst() {
time_t timer;
time(&timer);
srand(timer);
loadPreference();
initBarragemanager();
initAttractManager();
if ( !noSound ) initSound();
initGameStateFirst();
}
// Quit and save preference.
void quitLast() {
if ( !noSound ) closeSound();
savePreference();
closeFoes();
closeBarragemanager();
closeSDL();
SDL_Quit();
#ifdef PSP
sceKernelExitGame();
#else
exit(1);
#endif
}
int status;
static int musicEnabled = 1;
void initTitleStage(int stg) {
initFoes();
initStageState(stg);
}
void initTitle() {
int stg;
status = TITLE;
stg = initTitleAtr();
initBoss();
initShip();
initLasers();
initFrags();
initShots();
initBackground(0);
initTitleStage(stg);
left = -1;
}
void initGame(int stg) {
int sn;
status = IN_GAME;
initBoss();
initFoes();
initShip();
initLasers();
initFrags();
initShots();
initGameState(stg);
sn = stg%SAME_RANK_STAGE_NUM;
initBackground(sn);
if ( sn == SAME_RANK_STAGE_NUM-1 ) {
playMusic(rand()%(SAME_RANK_STAGE_NUM-1));
} else {
playMusic(sn);
}
if ( !musicEnabled ) {
Mix_PauseMusic();
}
}
void initGameover() {
status = GAMEOVER;
initGameoverAtr();
}
static void move() {
switch ( status ) {
case TITLE:
moveTitleMenu();
moveBoss();
moveFoes();
moveBackground();
break;
case IN_GAME:
case STAGE_CLEAR:
moveShip();
moveBoss();
moveLasers();
moveShots();
moveFoes();
moveFrags();
moveBackground();
break;
case GAMEOVER:
moveGameover();
moveBoss();
moveFoes();
moveFrags();
moveBackground();
break;
case PAUSE:
movePause();
break;
}
moveScreenShake();
}
static void draw() {
switch ( status ) {
case TITLE:
drawBackground();
drawBoss();
drawBulletsWake();
drawBullets();
startDrawBoards();
drawSideBoards();
drawTitle();
endDrawBoards();
break;
case IN_GAME:
case STAGE_CLEAR:
drawBackground();
drawBoss();
drawLasers();
drawShots();
drawBulletsWake();
drawFrags();
drawShip();
drawBullets();
startDrawBoards();
drawSideBoards();
drawBossState();
endDrawBoards();
break;
case GAMEOVER:
drawBackground();
drawBoss();
drawBulletsWake();
drawFrags();
drawBullets();
startDrawBoards();
drawSideBoards();
drawGameover();
endDrawBoards();
break;
case PAUSE:
drawBackground();
drawBoss();
drawLasers();
drawShots();
drawBulletsWake();
drawFrags();
drawShip();
drawBullets();
startDrawBoards();
drawSideBoards();
drawBossState();
drawPause();
endDrawBoards();
break;
}
}
static int accframe = 0;
static void usage(char *argv0) {
fprintf(stderr, "Usage: %s [-lowres] [-nosound] [-window] [-reverse] [-nowait] [-accframe]\n", argv0);
}
static void parseArgs(int argc, char *argv[]) {
int i;
for ( i=1 ; i<argc ; i++ ) {
if ( strcmp(argv[i], "-lowres") == 0 ) {
lowres = 1;
} else if ( strcmp(argv[i], "-nosound") == 0 ) {
noSound = 1;
} else if ( strcmp(argv[i], "-window") == 0 ) {
windowMode = 1;
} else if ( strcmp(argv[i], "-reverse") == 0 ) {
buttonReversed = 1;
}
/* else if ( (strcmp(argv[i], "-brightness") == 0) && argv[i+1] ) {
i++;
brightness = (int)atoi(argv[i]);
if ( brightness < 0 || brightness > 256 ) {
brightness = DEFAULT_BRIGHTNESS;
}
}*/
else if ( strcmp(argv[i], "-nowait") == 0 ) {
nowait = 1;
} else if ( strcmp(argv[i], "-accframe") == 0 ) {
accframe = 1;
} else {
usage(argv[0]);
exit(1);
}
}
}
int interval = INTERVAL_BASE;
int tick = 0;
static int pPrsd = 1;
static int mPrsd = 1;
#ifdef PSP
extern _DisableFPUExceptions();
#endif
int done = 0;
int exitCB(int arg1, int arg2, void *common)
{
done = 1;
return 0;
}
int callbackThread(SceSize args, void *argp)
{
int exit_cbid = sceKernelCreateCallback("Exit Callback", exitCB, NULL);
if (exit_cbid < 0)
{
sceKernelExitGame();
}
else if (sceKernelRegisterExitCallback(exit_cbid) < 0)
{
sceKernelExitGame();
}
sceKernelSleepThreadCB();
return 0;
}
int main(int argc, char *argv[]) {
long prvTickCount = 0;
int i;
int btn;
SDL_Event event;
long nowTick;
int frame;
parseArgs(argc, argv);
#ifdef PSP
_DisableFPUExceptions();
int cb_thid = sceKernelCreateThread("Callback Thread", callbackThread, 80, 512, PSP_THREAD_ATTR_USER, NULL);
if (cb_thid < 0)
{
sceKernelExitGame();
}
else
{
sceKernelStartThread(cb_thid, 0, NULL);
}
#endif
initDegutil();
initSDL();
initFirst();
initTitle();
while ( !done ) {
SDL_PollEvent(&event);
keys = SDL_GetKeyState(NULL);
if ( keys[SDLK_ESCAPE] == SDL_PRESSED || event.type == SDL_QUIT ) done = 1;
btn = getButtonState();
if ( keys[SDLK_p] == SDL_PRESSED || (btn & PAD_START) || (btn & PAD_HOME) ) {
if ( !pPrsd ) {
if ( status == IN_GAME ) {
status = PAUSE;
} else if ( status == PAUSE && !(btn & PAD_HOME) ) {
status = IN_GAME;
}
}
pPrsd = 1;
} else {
pPrsd = 0;
}
if ( btn & PAD_SELECT ) {
if ( !mPrsd ) {
if ( musicEnabled ) {
Mix_PauseMusic();
musicEnabled = 0;
} else {
Mix_ResumeMusic();
musicEnabled = 1;
}
}
mPrsd = 1;
} else {
mPrsd = 0;
}
if ( (btn & (PAD_LTRIG|PAD_RTRIG)) == (PAD_LTRIG|PAD_RTRIG) ) {
if ( musicEnabled ) {
Mix_PauseMusic();
SDL_Delay(50);
}
screenshot("rRootage-");
if ( musicEnabled ) {
Mix_ResumeMusic();
}
}
nowTick = SDL_GetTicks();
frame = (int)(nowTick-prvTickCount) / interval;
if ( frame <= 0 ) {
frame = 1;
SDL_Delay(prvTickCount+interval-nowTick);
if ( accframe ) {
prvTickCount = SDL_GetTicks();
} else {
prvTickCount += interval;
}
} else if ( frame > 5 ) {
frame = 5;
prvTickCount = nowTick;
} else {
prvTickCount += frame*interval;
}
for ( i=0 ; i<frame ; i++ ) {
move();
tick++;
}
drawGLSceneStart();
draw();
drawGLSceneEnd();
swapGLScene();
}
quitLast();
return 0;
}