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