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 "field.h"
|
|
10 #include "car.h"
|
|
11 #include "gSprite.h"
|
|
12 #include "gFont.h"
|
|
13 #include "game.h"
|
|
14 #include "controler.h"
|
|
15 #include "camera.h"
|
|
16 #include "light.h"
|
|
17 #include "title_scene.h"
|
|
18 #include "game_time.h"
|
45
|
19 #include "schedule.h"
|
0
|
20
|
|
21
|
|
22 #define MAXCAR 3 // 選択可能機体
|
|
23 #define MAXFIELD 2 // 選択可能コース
|
|
24 #define MAXRAP 3 // ラップ数
|
|
25 #define SP_SEL_CAR 50
|
|
26 #define SP_SEL_COURSE 80
|
4
|
27
|
0
|
28 /* --- car.c --- */
|
|
29 extern void car_update(CarPtr);
|
|
30 /* --- carNode.c */
|
|
31 extern void carNode_append(CarPtr);
|
|
32 extern void carNode_draw();
|
|
33 extern void carNode_destroy();
|
43
|
34 /* --- fielc.c */
|
0
|
35 extern void field_update(CarPtr);
|
|
36 /* --- mytype.c --- */
|
|
37 extern void wait_init();
|
|
38 extern Bool wait(double);
|
|
39 extern void time_RaceStart();
|
|
40 extern double time_RaceTime();
|
|
41 /* --- linda.c --- */
|
43
|
42 extern void linda_env_init();
|
0
|
43
|
46
|
44
|
|
45
|
20
|
46 /* timer */
|
|
47 static int start_time,time_count;
|
|
48 static int RUNNIG=0;
|
|
49 char raptime[10];
|
0
|
50
|
|
51 static int ranking = 0;
|
|
52 static LIGHT l;
|
|
53
|
|
54 static int i=0;
|
|
55
|
12
|
56 void
|
20
|
57 set_schedule(void *func)
|
11
|
58 {
|
|
59 game.exec = func;
|
|
60 }
|
0
|
61
|
|
62 static void
|
2
|
63 graphic_init()
|
0
|
64 {
|
2
|
65 gSprite_Init(); // グラフィック関連の初期化
|
|
66 gFont_Init(); // フォント関連の初期化
|
0
|
67 }
|
|
68
|
|
69 static void
|
|
70 play_init()
|
|
71 {
|
|
72 game.jiki = car_init(game.car_id);
|
|
73 carNode_append(game.jiki);
|
32
|
74 field_init(game.course_id);
|
0
|
75 }
|
|
76
|
|
77 static void
|
2
|
78 game_env_init()
|
0
|
79 {
|
|
80 game.car_id = 1;
|
|
81 game.course_id = 1;
|
|
82 game.camera_type = 0;
|
|
83 game.rap = 1;
|
|
84 game.jiki = NULL;
|
|
85
|
|
86 ranking = 0;
|
|
87
|
|
88 wait_init();
|
43
|
89 linda_env_init();
|
0
|
90 }
|
|
91
|
|
92
|
|
93
|
2
|
94 void
|
|
95 sche_game_init()
|
|
96 {
|
|
97 game_env_init();
|
|
98 graphic_init();
|
|
99 camera_init();
|
8
|
100
|
46
|
101 #ifdef LINDA
|
|
102 set_schedule(sche_game_wait);
|
|
103 #else
|
20
|
104 set_schedule(sche_game_opening);
|
46
|
105 #endif
|
2
|
106 }
|
|
107
|
44
|
108 /**
|
|
109 * 通信対戦専用
|
|
110 * 全ユーザが接続するまで待つ
|
|
111 */
|
|
112 static void
|
|
113 sche_game_wait()
|
|
114 {
|
|
115 gFont_SetString("WAITING...", 200, 100);
|
|
116 if (game.linda_exec() == TRUE)
|
|
117 set_schedule(sche_game_wait_ready);
|
|
118 }
|
|
119
|
|
120 /**
|
|
121 * 通信対戦専用
|
|
122 * 全ユーザの接続を確認したら呼び出す
|
|
123 */
|
|
124 static void
|
|
125 sche_game_wait_ready()
|
|
126 {
|
|
127 gFont_SetString("CONNECT OK!!", 170, 300);
|
|
128 if (game.play_id == 1) {
|
|
129 gFont_SetString(" PUSH START ", 170, 400);
|
|
130 if (pad.st != 1) { goto WAIT_READY; }
|
|
131 }
|
|
132
|
|
133 if (game.linda_exec() == TRUE)
|
46
|
134 set_schedule(sche_game_opening);
|
44
|
135
|
|
136 WAIT_READY:
|
|
137 return;
|
|
138 }
|
|
139
|
2
|
140 void
|
|
141 sche_game_opening()
|
|
142 {
|
|
143 static int blink_count = 0;
|
|
144 if (game.play_id==1){
|
|
145 if (blink_count < 35) {
|
|
146 gFont_SetString("PUSH START !!", 170, 380);
|
|
147 }
|
20
|
148 blink_count = (blink_count > 70) ? 0 : blink_count + 1;
|
44
|
149
|
46
|
150 if (pad.st != 1) { goto OPENING; }
|
2
|
151 }
|
|
152
|
44
|
153 if (game.linda_exec() == TRUE)
|
20
|
154 set_schedule(sche_game_select_car);
|
44
|
155
|
|
156 OPENING:
|
|
157 return;
|
2
|
158
|
|
159 /*
|
|
160 if (game.play_id == 1) {
|
|
161 if (title_scene() < 0){
|
|
162 }
|
|
163 } else if (game.play_id == 2) {
|
|
164 if (i==0){
|
|
165 title_init_call();
|
|
166 i=1;
|
|
167 }
|
|
168 }
|
|
169 */
|
|
170 }
|
|
171
|
|
172 void
|
|
173 sche_game_select_car()
|
|
174 {
|
|
175 if (i==1){
|
|
176 title_finish_call();
|
|
177 i=2;
|
|
178 }
|
|
179 gSprite_PutSpriteEx(SP_SEL_CAR+game.car_id, 190, 200, 1.5, 1.5);
|
|
180 gSprite_PutSprite(24, 460, 300);
|
|
181 gSprite_PutSprite(25, 120, 300);
|
|
182 gFont_SetString("SELECT CAR", 180, 50);
|
|
183
|
|
184 if (pad.right == 1) {
|
|
185 game.car_id =
|
|
186 (game.car_id > MAXCAR-1) ? 1 : game.car_id + 1;
|
|
187 }
|
|
188 if (pad.left == 1) {
|
|
189 game.car_id =
|
|
190 (game.car_id < 2) ? MAXCAR : game.car_id - 1;
|
|
191 }
|
44
|
192
|
|
193 if (game.play_id == 1)
|
|
194 if (pad.circle != 1) { goto SELECT_CAR; }
|
|
195
|
|
196 if (game.linda_exec() == TRUE)
|
20
|
197 set_schedule(sche_game_select_course);
|
44
|
198
|
|
199 SELECT_CAR:
|
|
200 return;
|
2
|
201 }
|
|
202
|
|
203 void
|
|
204 sche_game_select_course()
|
|
205 {
|
|
206 gSprite_PutSpriteEx(SP_SEL_COURSE+game.course_id, 190, 200, 1.7, 1.8);
|
|
207 gSprite_PutSprite(24, 460, 300);
|
|
208 gSprite_PutSprite(25, 120, 300);
|
|
209
|
|
210 gFont_SetString("SELECT COURSE", 150, 50);
|
44
|
211
|
46
|
212 if (game.play_id == 1) {
|
44
|
213 if (pad.right == 1) {
|
|
214 game.course_id =
|
|
215 (game.course_id > MAXFIELD-1) ? 1 : game.course_id + 1;
|
|
216 game.linda_exec();
|
|
217 goto SELECT_COURSE;
|
|
218 }
|
|
219 if (pad.left == 1) {
|
|
220 game.course_id =
|
|
221 (game.course_id < 2) ? MAXFIELD : game.course_id - 1;
|
|
222 game.linda_exec();
|
|
223 goto SELECT_COURSE;
|
|
224 }
|
46
|
225
|
|
226 if (pad.circle != 1) { goto SELECT_COURSE; }
|
2
|
227 }
|
44
|
228
|
|
229 if (game.linda_exec() == TRUE)
|
46
|
230 set_schedule(sche_game_ready);
|
44
|
231
|
|
232 SELECT_COURSE:
|
|
233 return;
|
|
234
|
2
|
235 }
|
|
236
|
|
237 void
|
|
238 sche_game_ready()
|
|
239 {
|
|
240 static int blink_count = 0;
|
|
241
|
|
242 gSprite_PutSprite(27+game.play_id,265,10);
|
|
243 gSprite_PutSpriteEx(SP_SEL_CAR+game.car_id, 50, 120, 1.5, 1.5);
|
|
244 gSprite_PutSpriteEx(SP_SEL_COURSE+game.course_id, 340, 120, 1.7, 1.8);
|
|
245
|
|
246 /* 点滅 */
|
|
247 if (blink_count < 35) {
|
|
248 gFont_SetString("GAME START !!", 170, 380);
|
|
249 }
|
|
250 blink_count = (blink_count > 70) ? 0 : blink_count + 1;
|
|
251
|
52
|
252 if (game.linda_exec() == TRUE)
|
|
253 set_schedule(sche_game_main_init);
|
|
254
|
|
255 /*
|
|
256 if (pad.st == 1) {
|
20
|
257 set_schedule(sche_game_main_init);
|
2
|
258 }
|
|
259 if (pad.cross > 0) {
|
20
|
260 set_schedule(sche_game_select_car);
|
2
|
261 }
|
52
|
262 */
|
2
|
263 }
|
|
264
|
|
265 void
|
|
266 sche_game_main_init()
|
|
267 {
|
|
268 if (!game.jiki)
|
|
269 play_init();
|
|
270 RUNNIG=0;
|
52
|
271
|
20
|
272 set_schedule(sche_game_main);
|
2
|
273 }
|
|
274
|
|
275 void
|
|
276 sche_game_main()
|
|
277 {
|
|
278
|
|
279 /** begin: dispaly RAP TIME **/
|
|
280 if(RUNNIG==0){
|
|
281 start_time = game_time_get_msec();
|
|
282 RUNNIG=1;
|
|
283 }
|
|
284
|
|
285 time_count = game_time_get_msec() - start_time;
|
|
286 game_time_set_raptime(raptime,time_count);
|
|
287 gFont_SetString("TIME",300,20);
|
|
288 gFont_SetString(raptime,400,20);
|
|
289 /** end: dispaly RAP TIME **/
|
|
290
|
|
291 light_init(&l);
|
|
292 set_light(&l);
|
|
293
|
|
294 car_update(game.jiki);
|
|
295 field_update(game.jiki);
|
|
296 camera_update(game.jiki->body->transfer);
|
|
297 carNode_draw();
|
20
|
298
|
2
|
299 gFont_SetStringInt(game.rap, 50, 100);
|
|
300
|
|
301 /* スピードメーター */
|
|
302 gSprite_DefSprite(23, 1, 1,(int)(106.0*(game.jiki->speed/game.jiki->speed_max)), 34);
|
|
303 gSprite_PutSprite(23, 400, 400);
|
|
304 /* km/h */
|
|
305 gSprite_PutSprite(26, 470, 350);
|
|
306 /* Rap */
|
|
307 gSprite_PutSprite(27, 80, 100);
|
|
308
|
|
309 if (game.rap > MAXRAP) {
|
|
310 ranking = 1;
|
20
|
311 set_schedule(sche_game_main_goal);
|
2
|
312 }
|
|
313
|
|
314 gFont_SetStringInt((int)(100.0*game.jiki->speed), 380, 350);
|
20
|
315
|
2
|
316 if ((pad.right > 0) && ((game.jiki->speed != 0) || (pad.circle > 0))) {
|
|
317 car_swerve(game.jiki, 1);
|
|
318 }
|
|
319 if ((pad.left > 0) && ((game.jiki->speed != 0) || (pad.circle > 0))) {
|
|
320 car_swerve(game.jiki, -1);
|
|
321 }
|
|
322 if (pad.circle > 0) {
|
|
323 car_accelerate(game.jiki, 1);
|
|
324 }
|
|
325 if (pad.cross > 0) {
|
|
326 car_accelerate(game.jiki, -1);
|
|
327 }
|
20
|
328
|
52
|
329 game.linda_exec();
|
|
330
|
2
|
331 if (pad.r1 == 1) {
|
|
332 game.camera_type = !game.camera_type;
|
|
333 }
|
|
334 if (pad.st == 1) {
|
20
|
335 set_schedule(sche_game_main_pause);
|
2
|
336 }
|
|
337 }
|
|
338
|
|
339 void
|
|
340 sche_game_main_pause()
|
|
341 {
|
26
|
342 static int select = 0;
|
|
343
|
2
|
344 field_update(game.jiki);
|
|
345 carNode_draw();
|
|
346
|
|
347 if (game.play_id == 1) {
|
|
348 /* 選択マーク */
|
26
|
349 gSprite_PutSprite(17, 100, 190+select*100);
|
2
|
350
|
|
351 gFont_SetString("BACK TO GAME", 200, 200);
|
|
352 gFont_SetString("GO TO TITLE", 200, 300);
|
|
353 } else {
|
|
354 gFont_SetString("Pause ...", 200, 200);
|
|
355 }
|
|
356
|
|
357 if (pad.circle == 1) {
|
26
|
358 if (select == 0) {
|
20
|
359 set_schedule(sche_game_main);
|
2
|
360 } else {
|
20
|
361 set_schedule(sche_game_main_finish);
|
2
|
362 }
|
27
|
363 } else if (pad.st == 1) {
|
20
|
364 set_schedule(sche_game_main);
|
27
|
365 } else if (pad.up == 1 || pad.down == 1) {
|
26
|
366 select = !select;
|
2
|
367 }
|
|
368 }
|
|
369
|
|
370 void
|
|
371 sche_game_main_goal()
|
|
372 {
|
|
373 /** dispaly TOTAL TIME **/
|
|
374 game_time_set_raptime(raptime,time_count);
|
|
375
|
|
376 gFont_SetString("TOTAL TIME",150,20);
|
|
377 gFont_SetString(raptime,400,20);
|
|
378 gFont_SetString("GOAL !!", 220, 150);
|
|
379
|
|
380 #ifdef LINDA
|
|
381 if (ranking == 1)
|
|
382 gFont_SetString("You WIN!!", 200, 250);
|
|
383 else
|
|
384 gFont_SetString("You Lose...", 200, 250);
|
|
385 #endif
|
|
386
|
|
387 car_update(game.jiki);
|
|
388 field_update(game.jiki);
|
|
389 carNode_draw();
|
|
390 camera_update(game.jiki->body->transfer);
|
|
391 if (pad.st == 1) {
|
20
|
392 set_schedule(sche_game_main_finish);
|
2
|
393 }
|
|
394 }
|
|
395
|
|
396 void
|
|
397 sche_game_main_finish()
|
|
398 {
|
30
|
399 field_destroy();
|
|
400 carNode_destroy();
|
|
401 game_env_init();
|
|
402
|
|
403 set_schedule(sche_game_main_finish2);
|
|
404 }
|
|
405
|
|
406 void
|
|
407 sche_game_main_finish2()
|
|
408 {
|
2
|
409 gFont_SetString("GAME OVER ...", 200, 200);
|
|
410
|
|
411 if (pad.st == 1) {
|
20
|
412 set_schedule(sche_game_opening);
|
2
|
413 }
|
|
414 }
|
3
|
415
|
|
416
|
|
417 void
|
|
418 schedule()
|
|
419 {
|
8
|
420 game.exec();
|
3
|
421
|
|
422 wait_sync();
|
|
423 swap_dbuff();
|
|
424 sjoy_poll();
|
|
425
|
|
426 ps2util_sprite_Draw();
|
|
427 gSprite_Draw_Reset();
|
|
428 gFont_Draw_Reset();
|
|
429 }
|