-
Notifications
You must be signed in to change notification settings - Fork 0
/
ship.c
398 lines (376 loc) · 9.28 KB
/
ship.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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/*
* $Id: ship.c 264 2005-11-06 17:43:44Z mrbrown $
*
* Copyright 2003 Kenta Cho. All rights reserved.
*/
/**
* Players ship.
*
* @version $Revision: 264 $
*/
#include "SDL.h"
#include <stdlib.h>
#include <stdio.h>
#include "rr.h"
#include "genmcr.h"
#include "screen.h"
#include "vector.h"
#include "ship.h"
#include "degutil.h"
#include "laser.h"
#include "shot.h"
#include "soundmanager.h"
#include "foe_mtd.h"
#include "frag.h"
#include "attractmanager.h"
#include "boss_mtd.h"
Ship ship;
int bonusScore;
int bomb;
#define SHIP_SPEED 1000
#define SHIP_SLOW_SPEED 500
#define SHIP_SLOW_DOWN 50
#define SHIP_ROLLING_SPEED 300
#define SHIP_IKAGW_SPEED 800
#define SHIP_INVINCIBLE_CNT_BASE 240
#define GRZ_WIDTH 5000
#define FLD_WIDTH 8000
#define RF_WIDTH 10000
#define RF_METER_MAX 2000
#define RF_METER_DEC 50
#define RF_METER_INC 5
static void resetPlayer() {
bonusScore = 10;
bomb = 3;
ship.grzInvCnt = ship.rollingCnt = ship.grzf = 0;
ship.grzWdt = GRZ_WIDTH;
ship.absEng = 0;
ship.rfCnt = ship.rfMtrDec = 0;
ship.rfMtr = RF_METER_MAX;
ship.reflects = 0;
}
static int btn2f;
void initShip() {
ship.pos.x = 0; ship.pos.y = FIELD_HEIGHT_8/5*2;
ship.cnt = 0; ship.laserCnt = 0;
ship.invCnt = SHIP_INVINCIBLE_CNT_BASE;
ship.bombCnt = 0;
ship.d = 0;
ship.grzCnt = 0;
ship.color = ship.colorChgCnt = 0; ship.fldWdt = FLD_WIDTH;
btn2f = 0;
switch ( mode ) {
case NORMAL_MODE:
ship.speed = SHIP_SPEED;
break;
case PSY_MODE:
ship.speed = SHIP_SLOW_SPEED;
break;
case IKA_MODE:
case GW_MODE:
ship.speed = SHIP_IKAGW_SPEED;
break;
}
resetPlayer();
}
#define SHOT_INTERVAL 3
#define SHIP_FIELD_WIDTH 1024
#define SHIP_SCREEN_EDGE_WIDTH 3
#define BOMB_SPEED 1280
#define BOMB_UP_SPEED 128
#define BOMB_CNT 160
#define BOMB_NEXT_READY_CNT 90
#define ROLLING_CNT_BASE 45
#define INVINCIBLE_GRZ_NUM 2000
#define INVINCIBLE_GRZ_CNT 120
#define COLOR_CHG_CNT 20
#define ABSENG_CNT 1
static int shipMv[8][2] = {
{0, -256}, {181, -181}, {256, 0}, {181, 181}, {0, 256}, {-181, 181}, {-256, 0}, {-181, -181},
};
void moveShip() {
int pad = getPadState();
int btn = getButtonState();
int sd = -1;
Vector *bossPos;
if ( pad & PAD_RIGHT ) {
sd = 2;
}
if ( pad & PAD_LEFT ) {
sd = 6;
}
if ( pad & PAD_DOWN ) {
switch ( sd ) {
case 2:
sd = 3;
break;
case 6:
sd = 5;
break;
default:
sd = 4;
break;
}
}
if ( pad & PAD_UP ) {
switch ( sd ) {
case 2:
sd = 1;
break;
case 6:
sd = 7;
break;
default:
sd = 0;
break;
}
}
if ( btn & PAD_BUTTON1 ) {
if ( status == IN_GAME ) {
addLaser();
if ( ship.laserCnt == 0 ) {
playChunk(0);
} else {
if ( (ship.laserCnt&15) == 1 ) playChunk(1);
}
ship.laserCnt++;
}
switch ( mode ) {
case NORMAL_MODE:
if ( ship.speed > SHIP_SLOW_SPEED ) {
ship.speed -= SHIP_SLOW_DOWN;
}
break;
}
} else {
switch ( mode ) {
case NORMAL_MODE:
if ( ship.speed < SHIP_SPEED ) {
ship.speed += SHIP_SLOW_DOWN;
}
break;
}
if ( ship.laserCnt > 0 ) {
haltChunk(1);
ship.laserCnt = 0;
}
}
if ( (btn & PAD_BUTTON2) && status == IN_GAME ) {
switch ( mode ) {
case NORMAL_MODE:
if ( bomb > 0 && (ship.bombCnt <= 0 || ship.bombCnt > BOMB_NEXT_READY_CNT ) &&
ship.invCnt < SHIP_INVINCIBLE_CNT_BASE-30 ) {
bomb--; bombUsed++;
ship.bombCnt = 1; ship.bombWdt = 0; ship.bombPos = ship.pos;
ship.invCnt = SHIP_INVINCIBLE_CNT_BASE/2;
playChunk(3);
}
break;
case PSY_MODE:
ship.rollingCnt = ROLLING_CNT_BASE;
if ( ship.speed > SHIP_ROLLING_SPEED ) {
ship.speed -= SHIP_SLOW_DOWN;
}
break;
case IKA_MODE:
if ( btn2f && ship.colorChgCnt <= 0 ) {
ship.colorChgCnt = COLOR_CHG_CNT;
btn2f = 0;
playChunk(12);
}
break;
case GW_MODE:
if ( ship.rfMtr >= RF_METER_MAX ) {
ship.rfMtrDec += RF_METER_DEC;
if ( ship.rfMtrDec >= RF_METER_MAX ) {
ship.rfMtrDec = ship.rfMtr = 0;
ship.rfCnt = 120;
ship.invCnt = 150;
playChunk(13);
}
}
}
} else {
switch ( mode ) {
case PSY_MODE:
if ( ship.rollingCnt > 0 ) {
ship.rollingCnt--;
if ( ship.speed < SHIP_SPEED ) {
ship.speed += SHIP_SLOW_DOWN;
}
} else {
if ( ship.speed < SHIP_SLOW_SPEED ) {
ship.speed += SHIP_SLOW_DOWN;
} else if ( ship.speed > SHIP_SLOW_SPEED ) {
ship.speed -= SHIP_SLOW_DOWN;
}
}
break;
case IKA_MODE:
btn2f = 1;
break;
case GW_MODE:
ship.rfMtrDec = 0;
break;
}
}
switch ( mode ) {
case NORMAL_MODE:
if ( ship.bombCnt > 0 ) {
ship.bombCnt++;
ship.bombPos.y -= BOMB_UP_SPEED;
if ( ship.bombCnt < 20 ) {
ship.bombWdt += BOMB_SPEED;
} else if ( ship.bombCnt > BOMB_CNT-20 ) {
ship.bombWdt -= BOMB_SPEED;
}
wipeBullets(&(ship.bombPos), ship.bombWdt);
if ( ship.bombCnt > BOMB_CNT ) ship.bombCnt = 0;
}
ship.d += 2.8;
break;
case PSY_MODE:
if ( ship.rollingCnt > 0 && ship.grzWdt == GRZ_WIDTH ) {
ship.grzWdt = GRZ_WIDTH*2;
} else {
ship.grzWdt = GRZ_WIDTH;
}
if ( ship.grzCnt >= INVINCIBLE_GRZ_NUM ) {
int i;
ship.grzCnt -= INVINCIBLE_GRZ_NUM;
ship.grzInvCnt = INVINCIBLE_GRZ_CNT;
for ( i=0 ; i<32 ; i++ ) {
addGrazeFrag(ship.pos.x, ship.pos.y, randNS(30000), randNS(30000));
}
ship.invCnt = 0;
playChunk(10);
}
if ( ship.grzInvCnt > 0 ) {
ship.grzInvCnt--;
}
ship.d += ship.rollingCnt*0.3;
if ( ship.grzf ) {
playChunk(9);
ship.grzf = 0;
}
break;
case IKA_MODE:
if ( ship.colorChgCnt > 0 ) {
ship.colorChgCnt--;
if ( ship.colorChgCnt == COLOR_CHG_CNT/2 ) {
ship.color ^= 1;
}
if ( ship.colorChgCnt < COLOR_CHG_CNT/2 ) {
ship.fldWdt = (COLOR_CHG_CNT/2-ship.colorChgCnt)*FLD_WIDTH/(COLOR_CHG_CNT/2);
} else {
ship.fldWdt = (ship.colorChgCnt-COLOR_CHG_CNT/2)*FLD_WIDTH/(COLOR_CHG_CNT/2);
}
}
if ( ship.absEng >= ABSENG_CNT ) {
ship.absEng -= ABSENG_CNT;
bossPos = getBossPos();
addShot(ship.pos.x, ship.pos.y, bossPos->x-ship.pos.x, bossPos->y-ship.pos.y, ship.color);
playChunk(11);
}
ship.d += 1.5;
break;
case GW_MODE:
if ( ship.rfCnt > 0 ) {
if ( ship.rfCnt > 20 ) {
ship.rfWdt = RF_WIDTH*(ship.rfCnt-20)/200 + RF_WIDTH/2;
} else {
ship.rfWdt = RF_WIDTH*(20-ship.rfCnt)/8 + RF_WIDTH/2;
if ( ship.rfCnt == 20 ) playChunk(14);
}
ship.rfCnt--;
} else if ( ship.rfMtr < RF_METER_MAX ) {
ship.rfMtr += RF_METER_INC;
if ( ship.rfMtr >= RF_METER_MAX ) {
ship.rfMtr = RF_METER_MAX;
playChunk(15);
}
}
if ( ship.reflects ) {
ship.reflects = 0;
playChunk(11);
}
ship.d += 3.2;
break;
}
if ( sd >= 0 ) {
ship.pos.x += (ship.speed*shipMv[sd][0])>>8;
ship.pos.y += (ship.speed*shipMv[sd][1])>>8;
if ( ship.pos.x < -FIELD_WIDTH_8/2+SHIP_FIELD_WIDTH*SHIP_SCREEN_EDGE_WIDTH ) {
ship.pos.x = -FIELD_WIDTH_8/2+SHIP_FIELD_WIDTH*SHIP_SCREEN_EDGE_WIDTH;
} else if ( ship.pos.x > FIELD_WIDTH_8/2-SHIP_FIELD_WIDTH*SHIP_SCREEN_EDGE_WIDTH ) {
ship.pos.x = FIELD_WIDTH_8/2-SHIP_FIELD_WIDTH*SHIP_SCREEN_EDGE_WIDTH;
}
if ( ship.pos.y < -FIELD_HEIGHT_8/2+SHIP_FIELD_WIDTH*SHIP_SCREEN_EDGE_WIDTH ) {
ship.pos.y = -FIELD_HEIGHT_8/2+SHIP_FIELD_WIDTH*SHIP_SCREEN_EDGE_WIDTH;
} else if ( ship.pos.y > FIELD_HEIGHT_8/2-SHIP_FIELD_WIDTH*SHIP_SCREEN_EDGE_WIDTH ) {
ship.pos.y = FIELD_HEIGHT_8/2-SHIP_FIELD_WIDTH*SHIP_SCREEN_EDGE_WIDTH;
}
}
ship.cnt++;
if ( ship.invCnt > 0 ) ship.invCnt--;
}
#define SHIP_DRAW_WIDTH 6
#define SHIP_DRUM_WIDTH 15
#define SHIP_DRUM_SIZE 4
void drawShip() {
float x, y, bx, by;
int inv = 0, ic;
x = (float)ship.pos.x / FIELD_SCREEN_RATIO;
y = -(float)ship.pos.y / FIELD_SCREEN_RATIO;
switch ( mode ) {
case NORMAL_MODE:
if ( ship.bombCnt > 0 ) {
bx = (float)ship.bombPos.x / FIELD_SCREEN_RATIO;
by = -(float)ship.bombPos.y / FIELD_SCREEN_RATIO;
drawBomb(bx, by, (float)ship.bombWdt / FIELD_SCREEN_RATIO, ship.bombCnt);
}
break;
case PSY_MODE:
if ( ship.grzInvCnt > 0 ) {
drawCircle(x, y, 0.01f * ship.grzInvCnt, ship.grzInvCnt, 150, 180, 240, 220, 220, 230);
}
break;
case IKA_MODE:
if ( ship.color == 0 ) {
drawCircle(x, y, (float)ship.fldWdt/FIELD_SCREEN_RATIO, ship.cnt,
120, 120, 150, 255, 255, 255);
} else {
drawCircle(x, y, (float)ship.fldWdt/FIELD_SCREEN_RATIO, ship.cnt,
200, 0, 0, 100, 0, 0);
}
break;
case GW_MODE:
if ( ship.rfCnt > 0 ) {
drawCircle(x, y, (float)ship.rfWdt/FIELD_SCREEN_RATIO, ship.cnt,
200, 250, 200, 100, 200, 100);
}
break;
}
ic = ship.invCnt&31;
if ( ic > 0 && ic < 16 ) inv = 1;
drawShipShape(x, y, ship.d, inv);
}
void destroyShip() {
float x, y;
if ( status != IN_GAME || ship.invCnt > 0 || ship.grzInvCnt > 0 ) return;
x = (float)ship.pos.x / FIELD_SCREEN_RATIO;
y = -(float)ship.pos.y / FIELD_SCREEN_RATIO;
addShipFrag(x, y);
playChunk(7);
shipUsed++;
resetPlayer();
if ( decrementShip() ) {
initGameover();
} else {
ship.invCnt = SHIP_INVINCIBLE_CNT_BASE;
clearFoesZako();
}
}
int getPlayerDeg(int x, int y) {
return getDeg(ship.pos.x - x, ship.pos.y - y);
}