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