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
|
58
|
124 set_schedule_assumption(sche_game_wait);
|
46
|
125 #else
|
58
|
126 set_schedule_assumption(sche_game_opening);
|
46
|
127 #endif
|
2
|
128 }
|
|
129
|
44
|
130 /**
|
|
131 * 通信対戦専用
|
|
132 * 全ユーザが接続するまで待つ
|
|
133 */
|
|
134 static void
|
|
135 sche_game_wait()
|
|
136 {
|
|
137 gFont_SetString("WAITING...", 200, 100);
|
62
|
138 set_schedule_assumption(sche_game_wait_ready);
|
44
|
139 }
|
|
140
|
|
141 /**
|
|
142 * 通信対戦専用
|
|
143 * 全ユーザの接続を確認したら呼び出す
|
|
144 */
|
|
145 static void
|
|
146 sche_game_wait_ready()
|
|
147 {
|
|
148 gFont_SetString("CONNECT OK!!", 170, 300);
|
|
149 if (game.play_id == 1) {
|
|
150 gFont_SetString(" PUSH START ", 170, 400);
|
|
151 if (pad.st != 1) { goto WAIT_READY; }
|
|
152 }
|
|
153
|
62
|
154 set_schedule_assumption(sche_game_opening);
|
44
|
155
|
|
156 WAIT_READY:
|
|
157 return;
|
|
158 }
|
|
159
|
2
|
160 void
|
|
161 sche_game_opening()
|
|
162 {
|
|
163 static int blink_count = 0;
|
|
164 if (game.play_id==1){
|
|
165 if (blink_count < 35) {
|
|
166 gFont_SetString("PUSH START !!", 170, 380);
|
|
167 }
|
20
|
168 blink_count = (blink_count > 70) ? 0 : blink_count + 1;
|
44
|
169
|
46
|
170 if (pad.st != 1) { goto OPENING; }
|
2
|
171 }
|
|
172
|
62
|
173
|
58
|
174 set_schedule_assumption(sche_game_select_car);
|
44
|
175
|
|
176 OPENING:
|
|
177 return;
|
2
|
178
|
|
179 /*
|
|
180 if (game.play_id == 1) {
|
|
181 if (title_scene() < 0){
|
|
182 }
|
|
183 } else if (game.play_id == 2) {
|
|
184 if (i==0){
|
|
185 title_init_call();
|
|
186 i=1;
|
|
187 }
|
|
188 }
|
|
189 */
|
|
190 }
|
|
191
|
|
192 void
|
|
193 sche_game_select_car()
|
|
194 {
|
|
195 if (i==1){
|
|
196 title_finish_call();
|
|
197 i=2;
|
|
198 }
|
|
199 gSprite_PutSpriteEx(SP_SEL_CAR+game.car_id, 190, 200, 1.5, 1.5);
|
|
200 gSprite_PutSprite(24, 460, 300);
|
|
201 gSprite_PutSprite(25, 120, 300);
|
|
202 gFont_SetString("SELECT CAR", 180, 50);
|
|
203
|
|
204 if (pad.right == 1) {
|
|
205 game.car_id =
|
|
206 (game.car_id > MAXCAR-1) ? 1 : game.car_id + 1;
|
|
207 }
|
|
208 if (pad.left == 1) {
|
|
209 game.car_id =
|
|
210 (game.car_id < 2) ? MAXCAR : game.car_id - 1;
|
|
211 }
|
44
|
212
|
|
213 if (game.play_id == 1)
|
|
214 if (pad.circle != 1) { goto SELECT_CAR; }
|
|
215
|
62
|
216
|
58
|
217 set_schedule_assumption(sche_game_select_course);
|
44
|
218
|
|
219 SELECT_CAR:
|
|
220 return;
|
2
|
221 }
|
|
222
|
|
223 void
|
|
224 sche_game_select_course()
|
|
225 {
|
|
226 gSprite_PutSpriteEx(SP_SEL_COURSE+game.course_id, 190, 200, 1.7, 1.8);
|
|
227 gSprite_PutSprite(24, 460, 300);
|
|
228 gSprite_PutSprite(25, 120, 300);
|
|
229
|
|
230 gFont_SetString("SELECT COURSE", 150, 50);
|
44
|
231
|
46
|
232 if (game.play_id == 1) {
|
44
|
233 if (pad.right == 1) {
|
|
234 game.course_id =
|
|
235 (game.course_id > MAXFIELD-1) ? 1 : game.course_id + 1;
|
|
236 game.linda_exec();
|
|
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 game.linda_exec();
|
|
243 goto SELECT_COURSE;
|
|
244 }
|
46
|
245
|
|
246 if (pad.circle != 1) { goto SELECT_COURSE; }
|
2
|
247 }
|
44
|
248
|
62
|
249
|
58
|
250 set_schedule_assumption(sche_game_ready);
|
44
|
251
|
|
252 SELECT_COURSE:
|
|
253 return;
|
|
254
|
2
|
255 }
|
|
256
|
|
257 void
|
|
258 sche_game_ready()
|
|
259 {
|
|
260 static int blink_count = 0;
|
|
261
|
|
262 gSprite_PutSprite(27+game.play_id,265,10);
|
|
263 gSprite_PutSpriteEx(SP_SEL_CAR+game.car_id, 50, 120, 1.5, 1.5);
|
|
264 gSprite_PutSpriteEx(SP_SEL_COURSE+game.course_id, 340, 120, 1.7, 1.8);
|
|
265
|
|
266 /* 点滅 */
|
|
267 if (blink_count < 35) {
|
|
268 gFont_SetString("GAME START !!", 170, 380);
|
|
269 }
|
|
270 blink_count = (blink_count > 70) ? 0 : blink_count + 1;
|
|
271
|
62
|
272 set_schedule_assumption(sche_game_main_init);
|
52
|
273
|
|
274 /*
|
|
275 if (pad.st == 1) {
|
58
|
276 set_schedule_assumption(sche_game_main_init);
|
2
|
277 }
|
|
278 if (pad.cross > 0) {
|
58
|
279 set_schedule_assumption(sche_game_select_car);
|
2
|
280 }
|
52
|
281 */
|
2
|
282 }
|
|
283
|
55
|
284 extern FILE *main_fp;
|
2
|
285 void
|
|
286 sche_game_main_init()
|
|
287 {
|
|
288 if (!game.jiki)
|
|
289 play_init();
|
|
290 RUNNIG=0;
|
52
|
291
|
58
|
292 set_schedule_assumption(sche_game_main);
|
2
|
293 }
|
|
294
|
|
295 void
|
|
296 sche_game_main()
|
|
297 {
|
|
298
|
|
299 /** begin: dispaly RAP TIME **/
|
|
300 if(RUNNIG==0){
|
|
301 start_time = game_time_get_msec();
|
|
302 RUNNIG=1;
|
|
303 }
|
|
304
|
|
305 time_count = game_time_get_msec() - start_time;
|
|
306 game_time_set_raptime(raptime,time_count);
|
|
307 gFont_SetString("TIME",300,20);
|
|
308 gFont_SetString(raptime,400,20);
|
|
309 /** end: dispaly RAP TIME **/
|
|
310
|
|
311 light_init(&l);
|
|
312 set_light(&l);
|
|
313
|
|
314 car_update(game.jiki);
|
|
315 field_update(game.jiki);
|
|
316 camera_update(game.jiki->body->transfer);
|
|
317 carNode_draw();
|
20
|
318
|
2
|
319 gFont_SetStringInt(game.rap, 50, 100);
|
|
320
|
|
321 /* スピードメーター */
|
|
322 gSprite_DefSprite(23, 1, 1,(int)(106.0*(game.jiki->speed/game.jiki->speed_max)), 34);
|
|
323 gSprite_PutSprite(23, 400, 400);
|
|
324 /* km/h */
|
|
325 gSprite_PutSprite(26, 470, 350);
|
|
326 /* Rap */
|
|
327 gSprite_PutSprite(27, 80, 100);
|
|
328
|
|
329 if (game.rap > MAXRAP) {
|
|
330 ranking = 1;
|
58
|
331 set_schedule_assumption(sche_game_main_goal);
|
2
|
332 }
|
|
333
|
|
334 gFont_SetStringInt((int)(100.0*game.jiki->speed), 380, 350);
|
20
|
335
|
2
|
336 if ((pad.right > 0) && ((game.jiki->speed != 0) || (pad.circle > 0))) {
|
|
337 car_swerve(game.jiki, 1);
|
|
338 }
|
|
339 if ((pad.left > 0) && ((game.jiki->speed != 0) || (pad.circle > 0))) {
|
|
340 car_swerve(game.jiki, -1);
|
|
341 }
|
|
342 if (pad.circle > 0) {
|
|
343 car_accelerate(game.jiki, 1);
|
|
344 }
|
|
345 if (pad.cross > 0) {
|
|
346 car_accelerate(game.jiki, -1);
|
|
347 }
|
20
|
348
|
52
|
349 game.linda_exec();
|
|
350
|
2
|
351 if (pad.r1 == 1) {
|
|
352 game.camera_type = !game.camera_type;
|
|
353 }
|
|
354 if (pad.st == 1) {
|
58
|
355 set_schedule_assumption(sche_game_main_pause);
|
2
|
356 }
|
|
357 }
|
|
358
|
|
359 void
|
|
360 sche_game_main_pause()
|
|
361 {
|
26
|
362 static int select = 0;
|
|
363
|
2
|
364 field_update(game.jiki);
|
|
365 carNode_draw();
|
|
366
|
|
367 if (game.play_id == 1) {
|
|
368 /* 選択マーク */
|
26
|
369 gSprite_PutSprite(17, 100, 190+select*100);
|
2
|
370
|
|
371 gFont_SetString("BACK TO GAME", 200, 200);
|
|
372 gFont_SetString("GO TO TITLE", 200, 300);
|
|
373 } else {
|
|
374 gFont_SetString("Pause ...", 200, 200);
|
|
375 }
|
|
376
|
|
377 if (pad.circle == 1) {
|
26
|
378 if (select == 0) {
|
58
|
379 set_schedule_assumption(sche_game_main);
|
2
|
380 } else {
|
58
|
381 set_schedule_assumption(sche_game_main_finish);
|
2
|
382 }
|
27
|
383 } else if (pad.st == 1) {
|
58
|
384 set_schedule_assumption(sche_game_main);
|
27
|
385 } else if (pad.up == 1 || pad.down == 1) {
|
26
|
386 select = !select;
|
2
|
387 }
|
|
388 }
|
|
389
|
|
390 void
|
|
391 sche_game_main_goal()
|
|
392 {
|
|
393 /** dispaly TOTAL TIME **/
|
|
394 game_time_set_raptime(raptime,time_count);
|
|
395
|
|
396 gFont_SetString("TOTAL TIME",150,20);
|
|
397 gFont_SetString(raptime,400,20);
|
|
398 gFont_SetString("GOAL !!", 220, 150);
|
|
399
|
|
400 #ifdef LINDA
|
|
401 if (ranking == 1)
|
|
402 gFont_SetString("You WIN!!", 200, 250);
|
|
403 else
|
|
404 gFont_SetString("You Lose...", 200, 250);
|
|
405 #endif
|
|
406
|
|
407 car_update(game.jiki);
|
|
408 field_update(game.jiki);
|
|
409 carNode_draw();
|
|
410 camera_update(game.jiki->body->transfer);
|
|
411 if (pad.st == 1) {
|
58
|
412 set_schedule_assumption(sche_game_main_finish);
|
2
|
413 }
|
|
414 }
|
|
415
|
|
416 void
|
|
417 sche_game_main_finish()
|
|
418 {
|
30
|
419 field_destroy();
|
|
420 carNode_destroy();
|
|
421 game_env_init();
|
|
422
|
58
|
423 set_schedule_assumption(sche_game_main_finish2);
|
30
|
424 }
|
|
425
|
|
426 void
|
|
427 sche_game_main_finish2()
|
|
428 {
|
2
|
429 gFont_SetString("GAME OVER ...", 200, 200);
|
|
430
|
|
431 if (pad.st == 1) {
|
58
|
432 set_schedule_assumption(sche_game_opening);
|
2
|
433 }
|
|
434 }
|
3
|
435
|
|
436
|
|
437 void
|
|
438 schedule()
|
|
439 {
|
58
|
440 sche_func();
|
3
|
441
|
58
|
442 if (linda_update(change_state) == TRUE)
|
|
443 set_schedule();
|
62
|
444 else
|
|
445 unset_schedule();
|
58
|
446
|
3
|
447 wait_sync();
|
|
448 swap_dbuff();
|
|
449 sjoy_poll();
|
|
450
|
|
451 ps2util_sprite_Draw();
|
|
452 gSprite_Draw_Reset();
|
|
453 gFont_Draw_Reset();
|
|
454 }
|