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