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