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