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