0
|
1 /*
|
17
|
2 * $Id$
|
0
|
3 */
|
|
4 #include <stdio.h>
|
|
5 #include <stdlib.h>
|
|
6 #include <string.h>
|
|
7 #include "libps2.h"
|
|
8 #include "ps2util.h"
|
|
9 #include "field.h"
|
|
10 #include "car.h"
|
|
11 #include "gSprite.h"
|
|
12 #include "gFont.h"
|
|
13 #include "game.h"
|
|
14 #include "controler.h"
|
|
15 #include "camera.h"
|
|
16 #include "light.h"
|
|
17 #include "title_scene.h"
|
|
18 #include "game_time.h"
|
45
|
19 #include "schedule.h"
|
0
|
20
|
62
|
21 #ifdef LINDA
|
|
22 extern Bool linda_update(int);
|
|
23 #else
|
|
24 #define linda_update(int) TRUE
|
|
25 #endif
|
0
|
26
|
|
27 #define MAXCAR 3 // 選択可能機体
|
|
28 #define MAXFIELD 2 // 選択可能コース
|
|
29 #define MAXRAP 3 // ラップ数
|
|
30 #define SP_SEL_CAR 50
|
|
31 #define SP_SEL_COURSE 80
|
4
|
32
|
0
|
33 /* --- car.c --- */
|
|
34 extern void car_update(CarPtr);
|
|
35 /* --- carNode.c */
|
|
36 extern void carNode_append(CarPtr);
|
|
37 extern void carNode_draw();
|
|
38 extern void carNode_destroy();
|
43
|
39 /* --- fielc.c */
|
0
|
40 extern void field_update(CarPtr);
|
|
41 /* --- mytype.c --- */
|
|
42 extern void wait_init();
|
|
43 extern Bool wait(double);
|
|
44 extern void time_RaceStart();
|
|
45 extern double time_RaceTime();
|
|
46 /* --- linda.c --- */
|
43
|
47 extern void linda_env_init();
|
0
|
48
|
46
|
49
|
|
50
|
20
|
51 /* timer */
|
|
52 static int start_time,time_count;
|
|
53 static int RUNNIG=0;
|
|
54 char raptime[10];
|
0
|
55
|
|
56 static int ranking = 0;
|
|
57 static LIGHT l;
|
|
58
|
|
59 static int i=0;
|
|
60
|
62
|
61 static void (*sche_func_assumption)();
|
|
62 static void (*sche_func)() = &sche_game_init;
|
58
|
63 static int change_state = 0;
|
|
64 static void
|
|
65 set_schedule_assumption(void *_func)
|
11
|
66 {
|
58
|
67 sche_func_assumption = _func;
|
|
68 change_state = 1;
|
|
69 }
|
|
70
|
|
71 static void
|
62
|
72 unset_schedule()
|
|
73 {
|
|
74 change_state = 0;
|
|
75 }
|
|
76
|
|
77 static void
|
58
|
78 set_schedule()
|
|
79 {
|
|
80 sche_func = sche_func_assumption;
|
|
81 change_state = 0;
|
11
|
82 }
|
0
|
83
|
|
84 static void
|
2
|
85 graphic_init()
|
0
|
86 {
|
2
|
87 gSprite_Init(); // グラフィック関連の初期化
|
|
88 gFont_Init(); // フォント関連の初期化
|
0
|
89 }
|
|
90
|
|
91 static void
|
|
92 play_init()
|
|
93 {
|
|
94 game.jiki = car_init(game.car_id);
|
|
95 carNode_append(game.jiki);
|
32
|
96 field_init(game.course_id);
|
0
|
97 }
|
|
98
|
|
99 static void
|
2
|
100 game_env_init()
|
0
|
101 {
|
|
102 game.car_id = 1;
|
|
103 game.course_id = 1;
|
|
104 game.camera_type = 0;
|
|
105 game.rap = 1;
|
|
106 game.jiki = NULL;
|
|
107
|
|
108 ranking = 0;
|
|
109
|
|
110 wait_init();
|
43
|
111 linda_env_init();
|
0
|
112 }
|
|
113
|
|
114
|
|
115
|
2
|
116 void
|
|
117 sche_game_init()
|
|
118 {
|
|
119 game_env_init();
|
|
120 graphic_init();
|
|
121 camera_init();
|
8
|
122
|
46
|
123 #ifdef LINDA
|
64
|
124 sche_func = &sche_game_wait;
|
|
125 //set_schedule_assumption(sche_game_wait);
|
46
|
126 #else
|
58
|
127 set_schedule_assumption(sche_game_opening);
|
46
|
128 #endif
|
2
|
129 }
|
|
130
|
44
|
131 /**
|
|
132 * 通信対戦専用
|
|
133 * 全ユーザが接続するまで待つ
|
|
134 */
|
|
135 static void
|
|
136 sche_game_wait()
|
|
137 {
|
|
138 gFont_SetString("WAITING...", 200, 100);
|
62
|
139 set_schedule_assumption(sche_game_wait_ready);
|
44
|
140 }
|
|
141
|
|
142 /**
|
|
143 * 通信対戦専用
|
|
144 * 全ユーザの接続を確認したら呼び出す
|
|
145 */
|
|
146 static void
|
|
147 sche_game_wait_ready()
|
|
148 {
|
|
149 gFont_SetString("CONNECT OK!!", 170, 300);
|
|
150 if (game.play_id == 1) {
|
|
151 gFont_SetString(" PUSH START ", 170, 400);
|
|
152 if (pad.st != 1) { goto WAIT_READY; }
|
|
153 }
|
|
154
|
62
|
155 set_schedule_assumption(sche_game_opening);
|
44
|
156
|
|
157 WAIT_READY:
|
|
158 return;
|
|
159 }
|
|
160
|
2
|
161 void
|
|
162 sche_game_opening()
|
|
163 {
|
|
164 static int blink_count = 0;
|
|
165 if (game.play_id==1){
|
|
166 if (blink_count < 35) {
|
|
167 gFont_SetString("PUSH START !!", 170, 380);
|
|
168 }
|
20
|
169 blink_count = (blink_count > 70) ? 0 : blink_count + 1;
|
44
|
170
|
46
|
171 if (pad.st != 1) { goto OPENING; }
|
2
|
172 }
|
|
173
|
62
|
174
|
58
|
175 set_schedule_assumption(sche_game_select_car);
|
44
|
176
|
|
177 OPENING:
|
|
178 return;
|
2
|
179
|
|
180 /*
|
|
181 if (game.play_id == 1) {
|
|
182 if (title_scene() < 0){
|
|
183 }
|
|
184 } else if (game.play_id == 2) {
|
|
185 if (i==0){
|
|
186 title_init_call();
|
|
187 i=1;
|
|
188 }
|
|
189 }
|
|
190 */
|
|
191 }
|
|
192
|
|
193 void
|
|
194 sche_game_select_car()
|
|
195 {
|
|
196 if (i==1){
|
|
197 title_finish_call();
|
|
198 i=2;
|
|
199 }
|
|
200 gSprite_PutSpriteEx(SP_SEL_CAR+game.car_id, 190, 200, 1.5, 1.5);
|
|
201 gSprite_PutSprite(24, 460, 300);
|
|
202 gSprite_PutSprite(25, 120, 300);
|
|
203 gFont_SetString("SELECT CAR", 180, 50);
|
|
204
|
|
205 if (pad.right == 1) {
|
|
206 game.car_id =
|
|
207 (game.car_id > MAXCAR-1) ? 1 : game.car_id + 1;
|
|
208 }
|
|
209 if (pad.left == 1) {
|
|
210 game.car_id =
|
|
211 (game.car_id < 2) ? MAXCAR : game.car_id - 1;
|
|
212 }
|
44
|
213
|
|
214 if (game.play_id == 1)
|
|
215 if (pad.circle != 1) { goto SELECT_CAR; }
|
|
216
|
62
|
217
|
58
|
218 set_schedule_assumption(sche_game_select_course);
|
44
|
219
|
|
220 SELECT_CAR:
|
|
221 return;
|
2
|
222 }
|
|
223
|
|
224 void
|
|
225 sche_game_select_course()
|
|
226 {
|
|
227 gSprite_PutSpriteEx(SP_SEL_COURSE+game.course_id, 190, 200, 1.7, 1.8);
|
|
228 gSprite_PutSprite(24, 460, 300);
|
|
229 gSprite_PutSprite(25, 120, 300);
|
|
230
|
|
231 gFont_SetString("SELECT COURSE", 150, 50);
|
44
|
232
|
46
|
233 if (game.play_id == 1) {
|
44
|
234 if (pad.right == 1) {
|
|
235 game.course_id =
|
|
236 (game.course_id > MAXFIELD-1) ? 1 : game.course_id + 1;
|
|
237 goto SELECT_COURSE;
|
|
238 }
|
|
239 if (pad.left == 1) {
|
|
240 game.course_id =
|
|
241 (game.course_id < 2) ? MAXFIELD : game.course_id - 1;
|
|
242 goto SELECT_COURSE;
|
|
243 }
|
46
|
244
|
|
245 if (pad.circle != 1) { goto SELECT_COURSE; }
|
2
|
246 }
|
44
|
247
|
62
|
248
|
58
|
249 set_schedule_assumption(sche_game_ready);
|
44
|
250
|
|
251 SELECT_COURSE:
|
|
252 return;
|
|
253
|
2
|
254 }
|
|
255
|
|
256 void
|
|
257 sche_game_ready()
|
|
258 {
|
|
259 static int blink_count = 0;
|
|
260
|
|
261 gSprite_PutSprite(27+game.play_id,265,10);
|
|
262 gSprite_PutSpriteEx(SP_SEL_CAR+game.car_id, 50, 120, 1.5, 1.5);
|
|
263 gSprite_PutSpriteEx(SP_SEL_COURSE+game.course_id, 340, 120, 1.7, 1.8);
|
|
264
|
|
265 /* 点滅 */
|
|
266 if (blink_count < 35) {
|
|
267 gFont_SetString("GAME START !!", 170, 380);
|
|
268 }
|
|
269 blink_count = (blink_count > 70) ? 0 : blink_count + 1;
|
|
270
|
62
|
271 set_schedule_assumption(sche_game_main_init);
|
52
|
272
|
|
273 /*
|
|
274 if (pad.st == 1) {
|
58
|
275 set_schedule_assumption(sche_game_main_init);
|
2
|
276 }
|
|
277 if (pad.cross > 0) {
|
58
|
278 set_schedule_assumption(sche_game_select_car);
|
2
|
279 }
|
52
|
280 */
|
2
|
281 }
|
|
282
|
55
|
283 extern FILE *main_fp;
|
2
|
284 void
|
|
285 sche_game_main_init()
|
|
286 {
|
|
287 if (!game.jiki)
|
|
288 play_init();
|
|
289 RUNNIG=0;
|
52
|
290
|
58
|
291 set_schedule_assumption(sche_game_main);
|
2
|
292 }
|
|
293
|
|
294 void
|
|
295 sche_game_main()
|
|
296 {
|
|
297
|
|
298 /** begin: dispaly RAP TIME **/
|
|
299 if(RUNNIG==0){
|
|
300 start_time = game_time_get_msec();
|
|
301 RUNNIG=1;
|
|
302 }
|
|
303
|
|
304 time_count = game_time_get_msec() - start_time;
|
|
305 game_time_set_raptime(raptime,time_count);
|
|
306 gFont_SetString("TIME",300,20);
|
|
307 gFont_SetString(raptime,400,20);
|
|
308 /** end: dispaly RAP TIME **/
|
|
309
|
|
310 light_init(&l);
|
|
311 set_light(&l);
|
|
312
|
|
313 car_update(game.jiki);
|
|
314 field_update(game.jiki);
|
|
315 camera_update(game.jiki->body->transfer);
|
|
316 carNode_draw();
|
20
|
317
|
2
|
318 gFont_SetStringInt(game.rap, 50, 100);
|
|
319
|
|
320 /* スピードメーター */
|
|
321 gSprite_DefSprite(23, 1, 1,(int)(106.0*(game.jiki->speed/game.jiki->speed_max)), 34);
|
|
322 gSprite_PutSprite(23, 400, 400);
|
|
323 /* km/h */
|
|
324 gSprite_PutSprite(26, 470, 350);
|
|
325 /* Rap */
|
|
326 gSprite_PutSprite(27, 80, 100);
|
|
327
|
|
328 if (game.rap > MAXRAP) {
|
|
329 ranking = 1;
|
58
|
330 set_schedule_assumption(sche_game_main_goal);
|
2
|
331 }
|
|
332
|
|
333 gFont_SetStringInt((int)(100.0*game.jiki->speed), 380, 350);
|
20
|
334
|
2
|
335 if ((pad.right > 0) && ((game.jiki->speed != 0) || (pad.circle > 0))) {
|
|
336 car_swerve(game.jiki, 1);
|
|
337 }
|
|
338 if ((pad.left > 0) && ((game.jiki->speed != 0) || (pad.circle > 0))) {
|
|
339 car_swerve(game.jiki, -1);
|
|
340 }
|
|
341 if (pad.circle > 0) {
|
|
342 car_accelerate(game.jiki, 1);
|
|
343 }
|
|
344 if (pad.cross > 0) {
|
|
345 car_accelerate(game.jiki, -1);
|
|
346 }
|
20
|
347
|
2
|
348 if (pad.r1 == 1) {
|
|
349 game.camera_type = !game.camera_type;
|
|
350 }
|
|
351 if (pad.st == 1) {
|
58
|
352 set_schedule_assumption(sche_game_main_pause);
|
2
|
353 }
|
|
354 }
|
|
355
|
|
356 void
|
|
357 sche_game_main_pause()
|
|
358 {
|
26
|
359 static int select = 0;
|
|
360
|
2
|
361 field_update(game.jiki);
|
|
362 carNode_draw();
|
|
363
|
|
364 if (game.play_id == 1) {
|
|
365 /* 選択マーク */
|
26
|
366 gSprite_PutSprite(17, 100, 190+select*100);
|
2
|
367
|
|
368 gFont_SetString("BACK TO GAME", 200, 200);
|
|
369 gFont_SetString("GO TO TITLE", 200, 300);
|
|
370 } else {
|
|
371 gFont_SetString("Pause ...", 200, 200);
|
|
372 }
|
|
373
|
|
374 if (pad.circle == 1) {
|
26
|
375 if (select == 0) {
|
58
|
376 set_schedule_assumption(sche_game_main);
|
2
|
377 } else {
|
58
|
378 set_schedule_assumption(sche_game_main_finish);
|
2
|
379 }
|
27
|
380 } else if (pad.st == 1) {
|
58
|
381 set_schedule_assumption(sche_game_main);
|
27
|
382 } else if (pad.up == 1 || pad.down == 1) {
|
26
|
383 select = !select;
|
2
|
384 }
|
|
385 }
|
|
386
|
|
387 void
|
|
388 sche_game_main_goal()
|
|
389 {
|
|
390 /** dispaly TOTAL TIME **/
|
|
391 game_time_set_raptime(raptime,time_count);
|
|
392
|
|
393 gFont_SetString("TOTAL TIME",150,20);
|
|
394 gFont_SetString(raptime,400,20);
|
|
395 gFont_SetString("GOAL !!", 220, 150);
|
|
396
|
|
397 #ifdef LINDA
|
|
398 if (ranking == 1)
|
|
399 gFont_SetString("You WIN!!", 200, 250);
|
|
400 else
|
|
401 gFont_SetString("You Lose...", 200, 250);
|
|
402 #endif
|
|
403
|
|
404 car_update(game.jiki);
|
|
405 field_update(game.jiki);
|
|
406 carNode_draw();
|
|
407 camera_update(game.jiki->body->transfer);
|
|
408 if (pad.st == 1) {
|
58
|
409 set_schedule_assumption(sche_game_main_finish);
|
2
|
410 }
|
|
411 }
|
|
412
|
|
413 void
|
|
414 sche_game_main_finish()
|
|
415 {
|
30
|
416 field_destroy();
|
|
417 carNode_destroy();
|
|
418 game_env_init();
|
|
419
|
58
|
420 set_schedule_assumption(sche_game_main_finish2);
|
30
|
421 }
|
|
422
|
|
423 void
|
|
424 sche_game_main_finish2()
|
|
425 {
|
2
|
426 gFont_SetString("GAME OVER ...", 200, 200);
|
|
427
|
|
428 if (pad.st == 1) {
|
58
|
429 set_schedule_assumption(sche_game_opening);
|
2
|
430 }
|
|
431 }
|
3
|
432
|
|
433
|
|
434 void
|
|
435 schedule()
|
|
436 {
|
58
|
437 sche_func();
|
3
|
438
|
58
|
439 if (linda_update(change_state) == TRUE)
|
|
440 set_schedule();
|
62
|
441 else
|
|
442 unset_schedule();
|
58
|
443
|
3
|
444 wait_sync();
|
|
445 swap_dbuff();
|
|
446 sjoy_poll();
|
|
447
|
|
448 ps2util_sprite_Draw();
|
|
449 gSprite_Draw_Reset();
|
|
450 gFont_Draw_Reset();
|
|
451 }
|