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
|
88
|
27 #define MAXCAR 3 // 選択可能機体
|
|
28 #define MAXFIELD 2 // 選択可能コース
|
|
29 #define MAXRAP 3 // ラップ数
|
0
|
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 {
|
88
|
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 /**
|
88
|
132 * 通信対戦専用
|
|
133 * 全ユーザが接続するまで待つ
|
44
|
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 /**
|
88
|
143 * 通信対戦専用
|
|
144 * 全ユーザの接続を確認したら呼び出す
|
44
|
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
|
68
|
248 set_schedule_assumption(sche_game_ready);
|
44
|
249
|
|
250 SELECT_COURSE:
|
|
251 return;
|
|
252
|
2
|
253 }
|
|
254
|
|
255 void
|
|
256 sche_game_ready()
|
|
257 {
|
|
258 static int blink_count = 0;
|
|
259
|
|
260 gSprite_PutSprite(27+game.play_id,265,10);
|
|
261 gSprite_PutSpriteEx(SP_SEL_CAR+game.car_id, 50, 120, 1.5, 1.5);
|
|
262 gSprite_PutSpriteEx(SP_SEL_COURSE+game.course_id, 340, 120, 1.7, 1.8);
|
|
263
|
88
|
264 /* 点滅 */
|
2
|
265 if (blink_count < 35) {
|
|
266 gFont_SetString("GAME START !!", 170, 380);
|
|
267 }
|
|
268 blink_count = (blink_count > 70) ? 0 : blink_count + 1;
|
|
269
|
62
|
270 set_schedule_assumption(sche_game_main_init);
|
52
|
271
|
|
272 /*
|
|
273 if (pad.st == 1) {
|
58
|
274 set_schedule_assumption(sche_game_main_init);
|
2
|
275 }
|
|
276 if (pad.cross > 0) {
|
58
|
277 set_schedule_assumption(sche_game_select_car);
|
2
|
278 }
|
52
|
279 */
|
2
|
280 }
|
|
281
|
|
282 void
|
|
283 sche_game_main_init()
|
|
284 {
|
|
285 if (!game.jiki)
|
|
286 play_init();
|
|
287 RUNNIG=0;
|
52
|
288
|
72
|
289 set_schedule_assumption(sche_game_main_ready);
|
|
290 }
|
|
291
|
|
292 static void
|
|
293 sche_game_main_ready()
|
|
294 {
|
75
|
295 gFont_SetString("Loading....", 180, 100);
|
58
|
296 set_schedule_assumption(sche_game_main);
|
2
|
297 }
|
|
298
|
72
|
299 static void
|
2
|
300 sche_game_main()
|
|
301 {
|
|
302
|
|
303 /** begin: dispaly RAP TIME **/
|
|
304 if(RUNNIG==0){
|
|
305 start_time = game_time_get_msec();
|
|
306 RUNNIG=1;
|
|
307 }
|
|
308
|
|
309 time_count = game_time_get_msec() - start_time;
|
|
310 game_time_set_raptime(raptime,time_count);
|
|
311 gFont_SetString("TIME",300,20);
|
|
312 gFont_SetString(raptime,400,20);
|
|
313 /** end: dispaly RAP TIME **/
|
|
314
|
|
315 light_init(&l);
|
|
316 set_light(&l);
|
|
317
|
|
318 car_update(game.jiki);
|
|
319 field_update(game.jiki);
|
|
320 camera_update(game.jiki->body->transfer);
|
|
321 carNode_draw();
|
20
|
322
|
2
|
323 gFont_SetStringInt(game.rap, 50, 100);
|
|
324
|
88
|
325 /* スピードメーター */
|
2
|
326 gSprite_DefSprite(23, 1, 1,(int)(106.0*(game.jiki->speed/game.jiki->speed_max)), 34);
|
|
327 gSprite_PutSprite(23, 400, 400);
|
|
328 /* km/h */
|
|
329 gSprite_PutSprite(26, 470, 350);
|
|
330 /* Rap */
|
|
331 gSprite_PutSprite(27, 80, 100);
|
|
332
|
|
333 if (game.rap > MAXRAP) {
|
|
334 ranking = 1;
|
58
|
335 set_schedule_assumption(sche_game_main_goal);
|
2
|
336 }
|
|
337
|
|
338 gFont_SetStringInt((int)(100.0*game.jiki->speed), 380, 350);
|
20
|
339
|
2
|
340 if ((pad.right > 0) && ((game.jiki->speed != 0) || (pad.circle > 0))) {
|
|
341 car_swerve(game.jiki, 1);
|
|
342 }
|
|
343 if ((pad.left > 0) && ((game.jiki->speed != 0) || (pad.circle > 0))) {
|
|
344 car_swerve(game.jiki, -1);
|
|
345 }
|
|
346 if (pad.circle > 0) {
|
|
347 car_accelerate(game.jiki, 1);
|
|
348 }
|
|
349 if (pad.cross > 0) {
|
|
350 car_accelerate(game.jiki, -1);
|
|
351 }
|
20
|
352
|
2
|
353 if (pad.r1 == 1) {
|
|
354 game.camera_type = !game.camera_type;
|
|
355 }
|
|
356 if (pad.st == 1) {
|
58
|
357 set_schedule_assumption(sche_game_main_pause);
|
2
|
358 }
|
|
359 }
|
|
360
|
|
361 void
|
|
362 sche_game_main_pause()
|
|
363 {
|
26
|
364 static int select = 0;
|
|
365
|
2
|
366 field_update(game.jiki);
|
|
367 carNode_draw();
|
|
368
|
|
369 if (game.play_id == 1) {
|
88
|
370 /* 選択マーク */
|
26
|
371 gSprite_PutSprite(17, 100, 190+select*100);
|
2
|
372
|
|
373 gFont_SetString("BACK TO GAME", 200, 200);
|
|
374 gFont_SetString("GO TO TITLE", 200, 300);
|
|
375 } else {
|
|
376 gFont_SetString("Pause ...", 200, 200);
|
|
377 }
|
|
378
|
|
379 if (pad.circle == 1) {
|
26
|
380 if (select == 0) {
|
58
|
381 set_schedule_assumption(sche_game_main);
|
2
|
382 } else {
|
58
|
383 set_schedule_assumption(sche_game_main_finish);
|
2
|
384 }
|
27
|
385 } else if (pad.st == 1) {
|
58
|
386 set_schedule_assumption(sche_game_main);
|
27
|
387 } else if (pad.up == 1 || pad.down == 1) {
|
26
|
388 select = !select;
|
2
|
389 }
|
|
390 }
|
|
391
|
|
392 void
|
|
393 sche_game_main_goal()
|
|
394 {
|
|
395 /** dispaly TOTAL TIME **/
|
|
396 game_time_set_raptime(raptime,time_count);
|
|
397
|
|
398 gFont_SetString("TOTAL TIME",150,20);
|
|
399 gFont_SetString(raptime,400,20);
|
|
400 gFont_SetString("GOAL !!", 220, 150);
|
|
401
|
|
402 #ifdef LINDA
|
|
403 if (ranking == 1)
|
|
404 gFont_SetString("You WIN!!", 200, 250);
|
|
405 else
|
|
406 gFont_SetString("You Lose...", 200, 250);
|
|
407 #endif
|
|
408
|
|
409 car_update(game.jiki);
|
|
410 field_update(game.jiki);
|
|
411 carNode_draw();
|
|
412 camera_update(game.jiki->body->transfer);
|
|
413 if (pad.st == 1) {
|
58
|
414 set_schedule_assumption(sche_game_main_finish);
|
2
|
415 }
|
|
416 }
|
|
417
|
|
418 void
|
|
419 sche_game_main_finish()
|
|
420 {
|
30
|
421 field_destroy();
|
|
422 carNode_destroy();
|
|
423 game_env_init();
|
|
424
|
58
|
425 set_schedule_assumption(sche_game_main_finish2);
|
30
|
426 }
|
|
427
|
|
428 void
|
|
429 sche_game_main_finish2()
|
|
430 {
|
2
|
431 gFont_SetString("GAME OVER ...", 200, 200);
|
|
432
|
|
433 if (pad.st == 1) {
|
58
|
434 set_schedule_assumption(sche_game_opening);
|
2
|
435 }
|
|
436 }
|
3
|
437
|
|
438
|
|
439 void
|
|
440 schedule()
|
|
441 {
|
58
|
442 sche_func();
|
3
|
443
|
58
|
444 if (linda_update(change_state) == TRUE)
|
|
445 set_schedule();
|
62
|
446 else
|
|
447 unset_schedule();
|
58
|
448
|
3
|
449 wait_sync();
|
|
450 swap_dbuff();
|
|
451 sjoy_poll();
|
|
452
|
|
453 ps2util_sprite_Draw();
|
|
454 gSprite_Draw_Reset();
|
|
455 gFont_Draw_Reset();
|
|
456 }
|