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