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