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