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