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