Mercurial > hg > Members > koba > t_dandy
annotate Dandy.cc @ 59:cd05eee90279
fix code.
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 07 Feb 2011 03:31:18 +0900 |
parents | b31bed246abd |
children |
rev | line source |
---|---|
0 | 1 #include "Dandy.h" |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 #include <string.h> | |
5 #include <ctype.h> | |
6 #include <math.h> | |
7 #include <time.h> | |
8 #include <SDL.h> | |
9 #include "SDL_opengl.h" | |
10 #include "object.h" | |
11 #include "tree_controll.h" | |
12 #include "xml.h" | |
13 #include "profile.h" | |
14 #include "syokika.h" | |
15 #include "sankaku.h" | |
16 #include "sgoex.h" | |
17 #include "sound.h" | |
18 #include "bool.h" | |
19 #include "bom.h" | |
20 #include "count2.h" | |
21 #include "tokuten.h" | |
22 #include "schedule.h" | |
23 #include "tama.h" | |
24 #include "debug.h" | |
25 #include "trace.h" | |
26 #include "LoadSprite.h" | |
27 #include <SDL_mixer.h> | |
28 #include "error.h" | |
29 #include "matrix_calc.h" | |
30 #include "Character.h" | |
31 #include "Character_state.h" | |
53 | 32 #include "Cheat.h" |
51 | 33 #include "debug_db.h" |
34 | |
53 | 35 |
51 | 36 DebugDB dtable[DEFOBJ]; |
0 | 37 |
44 | 38 static int use_keybord = 0; |
49 | 39 //static int cdp[20] = { 16, 16, 16, 17, 18, 0 }; |
40 static int i; | |
0 | 41 |
44 | 42 static int rswait = 0; |
43 static int cf = 0; | |
44 static int cc = 0; | |
0 | 45 |
46 //static SDL_Surface *screen; | |
47 // static Uint32 background; | |
48 // static char *pad_trace_file; | |
49 | |
59 | 50 extern int finish_flag; |
51 | |
0 | 52 extern void schedule(); |
53 extern void tokuten(); | |
54 extern void Pad(); | |
55 extern void keybord(); | |
56 static int gamesyokika(int gamef); | |
57 static int game_pause(int); | |
44 | 58 static void KeyAssign(int runmode, TraceBuffPtr buff, SDL_Joystick *joy, SGO_PAD *pad); |
4 | 59 |
44 | 60 static int runmode = 0; |
61 static TraceBuffPtr t_buff; | |
62 static TraceBuffPtr first; | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
63 static char *pad_trace_file; |
0 | 64 |
65 /** | |
66 * runmode: | |
67 * 0 - normal game | |
68 * 1 - capture mode | |
69 * program will capture all pad traces on a play and | |
70 * dump it into a file | |
71 * 2 - trace mode | |
72 * program will run with a trace file which is generated | |
73 * by capture-mode | |
74 */ | |
75 | |
44 | 76 static SDL_Joystick *joy; |
0 | 77 |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
78 #define SCMP_SIZ 8 |
0 | 79 |
80 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ | |
81 -length Number of data (default DATA_NUM (Func.h))\n\ | |
82 -count Number of task (default 1)\n"; | |
83 | |
84 static Viewer *sgroot; | |
85 | |
1 | 86 TaskManager *tmanager; |
87 | |
0 | 88 static int screen_w; |
89 static int screen_h; | |
90 | |
91 MainLoopPtr | |
92 Dandy::init(Viewer *sgroot_, int w, int h) | |
93 { | |
94 screen_w = w; | |
95 screen_h = h; | |
96 sgroot = sgroot_; | |
1 | 97 tmanager = sgroot->manager; |
0 | 98 return sgroot; |
99 } | |
100 | |
101 Application * | |
102 application() { | |
103 return new Dandy(); | |
104 } | |
105 | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
106 static void print_usage(); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
107 static int get_option(int argc, char *argv[]); |
0 | 108 static int opening(int gamef); |
109 static int dandy_closing(int gamef); | |
110 static int dandy_main_loop(int gamef); | |
111 static int dandy_main_init(int gamef); | |
112 extern int init(TaskManager *manager, int argc, char *argv[]); | |
113 extern void task_initialize(); | |
114 static void TMend(TaskManager *manager); | |
115 | |
116 bool | |
117 Dandy::app_loop(Viewer *viewer){ | |
118 // don't use allExecute | |
119 return 0; | |
120 }; | |
121 | |
122 static int gamef = 0; | |
123 | |
124 HTaskPtr | |
125 Dandy::application_task(HTaskPtr next, Viewer* viewer){ | |
126 // printf("gamef = %d\n",gamef); | |
127 switch (gamef) { | |
128 case 0: gamef= dandy_main_init(gamef); break; | |
129 case 1: gamef= gamesyokika(gamef); break; | |
130 case 2: gamef= opening(gamef); break; | |
131 case 3: gamef= dandy_main_loop(gamef); break; | |
132 case 4: gamef= dandy_closing(gamef); break; | |
133 } | |
134 return next; | |
1 | 135 }; |
0 | 136 |
6
9a92435eaee6
divide SG Dandy and Task Dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
137 void |
9a92435eaee6
divide SG Dandy and Task Dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
138 task_init() |
9a92435eaee6
divide SG Dandy and Task Dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
139 { |
9a92435eaee6
divide SG Dandy and Task Dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
140 |
9a92435eaee6
divide SG Dandy and Task Dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
141 } |
9a92435eaee6
divide SG Dandy and Task Dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
142 |
0 | 143 int |
144 TMmain(TaskManager *manager,int argc, char *argv[]) | |
145 { | |
146 task_init(); | |
147 task_initialize(); | |
148 manager->set_TMend(TMend); | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
149 if (get_option(argc, argv)) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
150 print_usage(); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
151 } |
0 | 152 |
153 return init(manager,argc, argv); | |
154 } | |
155 | |
156 void | |
157 TMend(TaskManager *manager) | |
158 { | |
159 printf("game end\n"); | |
160 } | |
161 | |
162 static int light_sysswitch = 1; | |
163 static int light_num = 4; | |
164 | |
165 static void | |
1 | 166 _LightSysSwitch(Viewer *sgroot) { |
0 | 167 if (light_sysswitch == 1) { |
19 | 168 sgroot->OffLightSysSwitch(); |
0 | 169 for (int i = 0; i < light_num; i++) { |
170 SceneGraphPtr light = sgroot->getLight(i); | |
171 sgroot->OnLightSwitch(i); | |
172 light->xyz[0] = screen_w / 2; | |
173 light->xyz[1] = screen_h / 2; | |
174 light->xyz[2] = -100; | |
175 } | |
176 } else if (light_sysswitch == 0) { | |
177 sgroot->OffLightSysSwitch(); | |
178 } | |
179 } | |
180 | |
181 | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
182 static void |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
183 print_usage() |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
184 { |
44 | 185 printf("usage: ./exe_file [-h|-help|--help][-capture filename][-trace filename]\n"); |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
186 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
187 |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
188 |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
189 static int |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
190 get_option(int argc, char *argv[]) |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
191 { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
192 int i; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
193 if (argc < 2) { |
44 | 194 runmode = 0; |
195 return 0; | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
196 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
197 for (i = 0; i < argc; i++) { |
44 | 198 if (!strncmp(argv[i], "-capture", SCMP_SIZ)) { |
199 if (++i >= argc) { | |
200 return 1; | |
201 } | |
202 printf("Start Capture mode.\n"); | |
203 t_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff)); | |
204 t_buff->next = NULL; | |
205 pad_trace_file = argv[i]; | |
206 runmode = 1; | |
207 return 0; | |
208 } else if (!strncmp(argv[i], "-trace", SCMP_SIZ)) { | |
209 if (++i >= argc) { | |
210 return 1; | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
211 } |
44 | 212 printf("Start Trace mode.\n"); |
213 t_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff)); | |
214 t_buff->next = NULL; | |
215 pad_trace_file = argv[i]; | |
216 runmode = 2; | |
217 return 0; | |
218 } else if (!strncmp(argv[i], "--help", SCMP_SIZ) || | |
219 !strncmp(argv[i], "-help", SCMP_SIZ) || | |
220 !strncmp(argv[i], "-h", SCMP_SIZ)) { | |
221 return 1; | |
222 } | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
223 } |
44 | 224 |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
225 return 1; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
226 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
227 |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
228 |
0 | 229 static int |
230 dandy_main_init(int gamef) | |
231 { | |
232 //Timeprof timeprof_move; | |
233 //timeprof_move = timeprof_new(); | |
234 dbg_init("/dev/stdout"); | |
235 | |
236 /** | |
237 * timeprof があるんだけどね | |
238 */ | |
44 | 239 if ((runmode == 1)||(runmode ==2)) { |
240 if (!PadfileOpen(pad_trace_file)) { | |
241 runmode = 0; | |
242 } else if(runmode == 2) { | |
243 PadfileRead(t_buff); | |
244 } | |
245 first = t_buff; | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
246 } |
0 | 247 |
248 sgroot->createFromXMLfile("xml/character.xml"); | |
249 sgroot->createFromXMLfile("xml/font.xml"); | |
250 sgroot->createFromXMLfile("xml/effect.xml"); | |
251 sgroot->createFromXMLfile("xml/boss.xml"); | |
252 | |
1 | 253 _LightSysSwitch(sgroot); |
0 | 254 |
255 init_sprite(0,0,0,0); | |
256 | |
257 __debug("syokikaが呼びだされました\n"); | |
258 joy=SDL_JoystickOpen(0); | |
259 if(!joy) { | |
260 fprintf(stderr,"failed to open joystick 0\n"); | |
261 use_keybord = 1; | |
262 } | |
263 | |
264 /** | |
265 * sound.c に移しました | |
266 * 代わりに InitSdlMixer(void); を使います。 | |
267 * まあ中身一緒なんだけどね | |
268 */ | |
269 /** | |
270 if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY,MIX_DEFAULT_FORMAT,2,1024) < 0) { | |
271 fprintf(stderr,"failed to initialize SDL_mixer.\n"); | |
272 SDL_Quit(); | |
273 exit(-1); | |
274 } | |
275 */ | |
276 | |
277 // SDL_mixer とかいろいろ初期化 | |
278 // もし Init に失敗したら | |
279 // 以後の Mixer 関連の関数を呼び出しても | |
280 // 中では何も行われないとかいう小細工を入れました。 | |
281 InitSdlMixer(); | |
282 | |
283 // 音楽ファイルの読み込み | |
284 LoadSdlMixer(); | |
285 | |
286 // ボリューム調整 | |
287 InitVolume(); | |
1 | 288 |
0 | 289 // 音出しテスト |
290 PlaySdlMixer(-1, BGM); | |
291 | |
292 if(!(init_chara_list(1024))){ | |
293 __debug("failed to init_chara_list\n"); | |
294 } | |
295 | |
296 __debug("finished init_chara_list\n"); | |
297 | |
298 return 1; | |
299 } | |
300 | |
301 SceneGraphPtr root; | |
302 | |
303 // extern void get_matrix(float *matrix, float *rxyz, float *txyz, float *scale, float *stack); | |
304 | |
305 static void | |
306 flip() | |
307 { | |
308 CameraPtr camera = sgroot->sgroot->getCamera(); | |
309 | |
310 sgroot->sgroot->flip(); | |
311 sgroot->sgroot->lightCalc(); | |
312 | |
313 root = sgroot->createSceneGraph(); | |
19 | 314 root->xyz[0] = 0; |
315 root->xyz[1] = 0; | |
0 | 316 root->xyz[2] = 30.0f; |
317 | |
318 /*親の回転、座標から、子の回転、座標を算出*/ | |
319 get_matrix(root->matrix, root->angle, root->xyz, root->scale, camera->matrix); | |
320 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
321 get_matrix(root->real_matrix, root->angle, root->xyz, root->scale, camera->real_matrix); | |
322 | |
323 sgroot->setSceneData(root); | |
324 } | |
325 | |
326 | |
327 static int | |
328 dandy_main_loop(int gamef) | |
329 { | |
330 if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && | |
331 (pad[0].l2 != 0) && (pad[0].r2 != 0)) { | |
332 gamef = gamesyokika(gamef); | |
333 } | |
334 | |
59 | 335 if (pad[0].quit != 0||finish_flag == 1) { |
0 | 336 gamef = 4; |
337 } | |
338 flip(); | |
339 | |
340 //SDL_FillRect(screen, NULL, background); | |
1 | 341 |
0 | 342 schedule(); |
343 enemyfaste = count; | |
344 | |
345 // timeprof_begin(timeprof_move); | |
346 //Move(); //enemy move | |
347 collision_detect(); | |
348 outofwindow(); | |
349 // timeprof_end(timeprof_move); | |
350 state_update(); | |
351 asteroidi = 0; | |
352 //charpatern(); | |
353 //bosguage(); | |
354 | |
355 if (jiki.bf == TRUE) { | |
356 Player(0); | |
357 count++; | |
358 PutSprite(count, jiki.x, jiki.y, jiki.ch); | |
359 } | |
360 | |
361 Putbom(); | |
362 tokuten(); | |
363 | |
49 | 364 //count++; |
0 | 365 //PutSprite(count, 0, 960 - 96, 10); |
366 /*インフレゲージ */ | |
49 | 367 //count++; |
0 | 368 //PutSprite(count, 0, 0, 48); |
369 | |
370 obj_draw(); | |
371 gamef = game_pause(gamef); | |
372 | |
44 | 373 KeyAssign(runmode, t_buff, joy, pad); |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
374 |
0 | 375 filpcount++; |
376 count = 0; | |
377 | |
378 return gamef; | |
379 } | |
380 | |
381 static int | |
382 dandy_closing(int gamef) | |
383 { | |
44 | 384 if (runmode == 1) { |
385 PadfileWrite(first); | |
386 PadfileClose(first); | |
387 } else if (runmode == 2) { | |
388 PadfileClose(first); | |
389 } | |
49 | 390 SDL_Event usr_event; |
391 usr_event.type = SDL_QUIT; | |
392 | |
393 SDL_PushEvent(&usr_event); | |
0 | 394 |
395 //_______________________________________________ | |
396 // SDL_mixerの後始末 | |
397 Mix_CloseAudio(); | |
398 Mix_HaltMusic(); | |
399 FreeSdlMixer() ; | |
400 //_______________________________________________ | |
401 return 0; | |
402 } | |
403 | |
404 | |
405 static int | |
406 gamesyokika(int gamef) | |
407 { | |
408 laser_lv3[0].r = 62; | |
409 laser_lv3[0].r = 62; | |
410 for (i = 0; i < 3; i++) { | |
411 tlv3[i].y = -1; | |
412 } | |
413 filpcount = 0; | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
414 stage = 0; |
0 | 415 //for (i = 0; i < 300; i++) |
416 //enemy[i].f = FALSE; | |
417 jiki.zanki = 3; | |
418 jiki.x = 60; | |
419 jiki.y = 200; | |
420 jiki.ch = 3; | |
421 jiki.point = 0; | |
422 jiki.bf = FALSE; | |
423 jiki.muteki = 120; | |
424 enemycount = 0; | |
425 lg.stg = 4096; | |
426 pg.stg = 4096; | |
427 infg.stg = 0; | |
428 infg_level = 0; | |
429 //kyeenemyno = -1; | |
430 fastebos = 0; | |
431 jiki.ccount = 99; | |
432 p_extend = 200000; | |
433 pad[0].up=0; | |
434 pad[0].down=0; | |
435 pad[0].right=0; | |
436 pad[0].left=0; | |
437 pad[0].st=0; | |
438 pad[0].se=0; | |
439 | |
440 SoundStop(); | |
441 SoundPlay(7); | |
442 gamef = 2; | |
443 flip(); | |
444 return gamef; | |
445 } | |
446 | |
447 static int | |
448 opening(int gamef) | |
449 { | |
450 if(use_keybord == 1) { | |
451 keybord(); | |
452 } else { | |
453 Pad(joy); | |
454 } | |
455 | |
456 count = 1; | |
457 | |
458 PutSprite(count, 700, 480, 53); // put `push start' string on screen. | |
459 count++; | |
460 PutSprite(count, 224, 776, 119); // put `super dandy' | |
461 count++; | |
462 // PutSprite(count, 200, 64, 190); | |
463 // PutSpriteEx(count, 8192, 8192, 0); | |
464 PutSpriteEx(190, 800, 264, 2, 2, 5); | |
465 count++; | |
466 PutSprite(count, 396, 432, 191); | |
467 //PutSpriteEx(count, 8192, 8192, 0); | |
468 count++; | |
469 PutSprite(count, 640, 640, 192); | |
470 //PutSpriteEx(count, 8192, 8192, 0); | |
471 | |
49 | 472 if ((pad[0].st > 1)||(runmode == 2)) { |
0 | 473 jiki.bf = TRUE; |
474 | |
475 //CdPlay(1,&cdp[0],0); | |
476 SoundStop(); | |
477 SoundPlay(0); | |
478 | |
479 gamef = 3; | |
480 pad[0].st = 1; | |
481 } else if ((pad[0].se > 0) && (pad[0].st > 0)) { | |
482 gamef = 2; | |
483 } | |
484 flip(); | |
485 return gamef; | |
486 } | |
487 | |
488 static int | |
489 game_pause(int gamef) | |
490 { | |
491 if (jiki.zanki != 0 && jiki.bf != FALSE) { | |
492 if (pad[0].se == 1) { | |
493 //Mix_Pause(BGM); | |
494 PauseSdlMixer(BGM); | |
495 while(1){ | |
496 if(use_keybord == 1) { | |
497 keybord(); | |
498 } else { | |
499 Pad(joy); | |
500 } | |
501 if(pad[0].st == 0) | |
502 continue; | |
503 pad[0].up=0; | |
504 pad[0].down=0; | |
505 pad[0].right=0; | |
506 pad[0].left=0; | |
507 pad[0].se=0; | |
508 pad[0].st=0; | |
509 //Mix_Resume(BGM); | |
510 ResumeSdlMixer(BGM); | |
511 break; | |
512 } | |
513 } | |
514 } | |
515 if (jiki.zanki == 0) { | |
516 // RECT *recp; | |
517 if ((jiki.ccount > 0) && (cf == 0)) { | |
518 cf = 1; | |
519 count++; | |
520 //cgcg(2); | |
521 PutSprite(2, 480, 480, 110); | |
522 count++; | |
523 //cgcg(1); | |
524 } | |
525 if ((jiki.ccount > 0) && (cf == 1)) { | |
526 while (1) { | |
527 if (pad[0].st > 0) { | |
528 cf = 0; | |
529 jiki.ccount--; | |
530 jiki.zanki = 3; | |
531 enemycount++; | |
532 cc = 0; | |
533 for (i = 0; i < 4; i++) { | |
534 clear_result[i] = 0; | |
535 } | |
536 goto f; | |
537 } | |
538 cc++; | |
539 if (29 - cc / 60 < 20) { | |
540 cc = 0; | |
541 cf = 3; | |
542 break; | |
543 } | |
544 SDL_Delay(100); | |
545 PutSprite(1, 640, 640, 29 - cc / 60); | |
53 | 546 //PutSpriteEx(1, 409 * ((cc % 60) + 1), 409 * ((cc % 60) + 1), 0); |
0 | 547 |
53 | 548 if(use_keybord == 1) { |
549 keybord(); | |
550 } else { | |
551 Pad(joy); | |
552 } | |
553 | |
0 | 554 flip(); // this is not correct |
555 } | |
556 } | |
557 if (rswait > 60 * 6) { | |
558 cf = 0; | |
559 rswait = 0; | |
560 gamef = gamesyokika(gamef); | |
561 } | |
562 rswait++; | |
563 count++; | |
564 //cgcg(1); | |
565 PutSprite(1, 480, 480, 19); | |
566 return gamef; | |
567 } | |
568 if (jiki.bf == FALSE) { | |
569 f: | |
570 if (rswait < 80) { | |
571 rswait++; | |
572 return gamef; | |
573 } else { | |
574 rswait = 0; | |
575 jiki.x = 60; | |
576 jiki.y = 200; | |
577 jiki.bf = TRUE; | |
578 | |
579 pad[0].st = 0; | |
580 lg.stg = 4096; | |
581 pg.stg = 4096; | |
582 laser_lv3[0].r = 62; | |
583 tlv3[0].r = 0; | |
584 tlv3[0].y = -1; | |
585 return gamef; | |
586 // sb_size = -1; | |
587 } | |
588 } | |
589 return gamef; | |
590 } | |
591 | |
592 | |
593 SpriteTable sptable[DEFOBJ]; | |
594 | |
595 | |
596 void | |
597 DefSpriteEx(int number, short middlex, short middley) | |
598 { | |
599 sptable[number].mx = middlex; | |
600 sptable[number].my = middley; | |
601 } | |
602 | |
603 | |
604 void | |
605 DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj) | |
606 { | |
51 | 607 dtable[number].name = name; |
608 dtable[number].count = 0; | |
609 | |
0 | 610 SpriteTable *m = &sptable[number]; |
611 m->w = w; | |
612 m->h = h; | |
613 m->color = (color & 32); | |
614 m->mx = w / 2; | |
615 m->my = h / 2; | |
33 | 616 m->tex_w = power_of_two(m->w); |
617 m->tex_h = power_of_two(m->h); | |
618 | |
0 | 619 m->texture = (int *)name; |
620 | |
621 } | |
622 | |
33 | 623 static float my_scale = 5; |
624 | |
0 | 625 void |
626 PutSprite(int zorder, short x, short y, int number) | |
627 { | |
628 SpriteTable *m = &sptable[number]; | |
629 char *name = (char *) m->texture; | |
45 | 630 |
33 | 631 if (!name) { |
45 | 632 // printf("PutSprite %d unknown\n",number); |
33 | 633 return; |
634 } | |
45 | 635 |
0 | 636 SceneGraphPtr object = sgroot->createSceneGraph(name); |
33 | 637 object->xyz[0] = x - object->c_xyz[0]*my_scale; |
638 object->xyz[1] = y - object->c_xyz[1]*my_scale; | |
0 | 639 object->xyz[2] = 0; |
640 root->addChild(object); | |
641 | |
33 | 642 float scale[] = {my_scale,my_scale,1}; |
0 | 643 /*親の回転、座標から、子の回転、座標を算出*/ |
644 get_matrix(object->matrix, object->angle, object->xyz, scale, root->matrix); | |
645 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
646 get_matrix(object->real_matrix, object->angle, object->xyz, scale, root->real_matrix); | |
647 | |
648 } | |
649 | |
650 void | |
651 PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle) | |
652 { | |
653 SpriteTable *m = &sptable[number]; | |
654 char *name = (char *) m->texture; | |
45 | 655 if (!name) { |
656 // printf("PutSpriteEx %d unknown\n",number); | |
657 return; | |
658 } | |
659 | |
0 | 660 SceneGraphPtr object = sgroot->createSceneGraph(name); |
33 | 661 object->xyz[0] = x - object->c_xyz[0]*my_scale - m->w*my_scale; |
662 object->xyz[1] = y - object->c_xyz[0]*my_scale - m->w*my_scale; | |
0 | 663 object->xyz[2] = 0; |
664 object->c_xyz[0] = m->mx; | |
665 object->c_xyz[1] = m->my; | |
666 object->angle[3] = angle; | |
667 root->addChild(object); | |
668 | |
669 float scale[] = {5*scalex,5*scaley,1}; | |
670 /*親の回転、座標から、子の回転、座標を算出*/ | |
671 get_matrix(object->matrix, object->angle, object->xyz, scale, root->matrix); | |
672 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
673 get_matrix(object->real_matrix, object->angle, object->xyz, scale, root->real_matrix); | |
674 } | |
675 | |
676 | |
677 struct SGO_PAD pad[2]; | |
678 | |
679 | |
680 /* コントローラ状態の読み込み */ | |
681 void Pad(SDL_Joystick *joy) | |
682 { | |
683 Sint16 axis; | |
684 | |
685 SDL_JoystickUpdate(); | |
686 | |
687 if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED) | |
688 pad[0].k0++; | |
689 else | |
690 pad[0].k0=0; | |
691 | |
692 if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED) | |
693 pad[0].k1++; | |
694 else | |
695 pad[0].k1=0; | |
696 | |
697 if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED) | |
698 pad[0].k3++; | |
699 else | |
700 pad[0].k3=0; | |
701 | |
702 if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED) | |
703 pad[0].k4++; | |
704 else | |
705 pad[0].k4=0; | |
706 | |
707 if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED) | |
708 pad[0].l1++; | |
709 else | |
710 pad[0].l1=0; | |
711 | |
712 if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED) | |
713 pad[0].r1++; | |
714 else | |
715 pad[0].r1=0; | |
716 | |
717 if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED) | |
718 pad[0].l2++; | |
719 else | |
720 pad[0].l2=0; | |
721 | |
722 if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED) | |
723 pad[0].r2++; | |
724 else | |
725 pad[0].r2=0; | |
726 | |
727 if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED) | |
728 pad[0].st++; | |
729 else | |
730 pad[0].st=0; | |
731 | |
732 if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED) | |
733 pad[0].se++; | |
734 else | |
735 pad[0].se=0; | |
736 | |
737 if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED) | |
738 pad[0].l3++; | |
739 else | |
740 pad[0].l3=0; | |
741 | |
742 if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED) | |
743 pad[0].r3++; | |
744 else | |
745 pad[0].r3=0; | |
746 //x | |
747 axis=SDL_JoystickGetAxis(joy,0); | |
748 if(axis>=3200){ | |
749 pad[0].left=0; | |
750 pad[0].right++; | |
751 } | |
752 else if(axis<=-3200){ | |
753 pad[0].right=0; | |
754 pad[0].left++; | |
755 } | |
756 else { | |
757 pad[0].right=0; | |
758 pad[0].left=0; | |
759 } | |
760 //y | |
761 axis=SDL_JoystickGetAxis(joy,1); | |
762 if(axis>=3200){ | |
763 pad[0].up=0; | |
764 pad[0].down++; | |
765 } | |
766 else if(axis<=-3200){ | |
767 pad[0].down=0; | |
768 pad[0].up++; | |
769 } | |
770 else { | |
771 pad[0].down=0; | |
772 pad[0].up=0; | |
773 } | |
774 | |
775 if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && | |
776 (pad[0].l2 != 0) && (pad[0].r2 != 0) && | |
777 (pad[0].st != 0) && (pad[0].se != 0)) { | |
778 pad[0].quit = 1; | |
779 } else { | |
780 pad[0].quit = 0; | |
781 } | |
782 | |
783 } | |
784 | |
785 | |
786 void keybord() | |
787 { | |
788 SDL_PumpEvents(); | |
789 Uint8 *keys = SDL_GetKeyState(NULL); | |
790 | |
791 if (keys[SDLK_UP]) { | |
792 pad[0].up++; | |
793 } else { | |
794 pad[0].up = 0; | |
795 } | |
796 if (keys[SDLK_DOWN]) { | |
797 pad[0].down++; | |
798 } else { | |
799 pad[0].down = 0; | |
800 } | |
801 | |
802 if (keys[SDLK_RIGHT]) { | |
803 pad[0].right++; | |
804 } else { | |
805 pad[0].right = 0; | |
806 } | |
807 | |
808 if (keys[SDLK_LEFT]) { | |
809 pad[0].left++; | |
810 } else { | |
811 pad[0].left = 0; | |
812 } | |
813 | |
814 if (keys[SDLK_a]) { | |
815 pad[0].k0++; | |
816 } else { | |
817 pad[0].k0 = 0; | |
818 } | |
819 | |
820 if (keys[SDLK_z]) { | |
821 pad[0].k1++; | |
822 } else { | |
823 pad[0].k1 = 0; | |
824 } | |
825 | |
826 if (keys[SDLK_s]) { | |
827 pad[0].k3++; | |
828 } else { | |
829 pad[0].k3 = 0; | |
830 } | |
831 | |
832 if (keys[SDLK_x]) { | |
833 pad[0].k4++; | |
834 } else { | |
835 pad[0].k4 = 0; | |
836 } | |
837 | |
838 if (keys[SDLK_r]) { | |
839 pad[0].r2++; | |
840 } else { | |
841 pad[0].r2 = 0; | |
842 } | |
843 | |
844 if (keys[SDLK_e]) { | |
845 pad[0].r1++; | |
846 } else { | |
847 pad[0].r1 = 0; | |
848 } | |
849 | |
850 if (keys[SDLK_w]) { | |
851 pad[0].l1++; | |
852 } else { | |
853 pad[0].l1 = 0; | |
854 } | |
855 | |
856 if (keys[SDLK_q]) { | |
857 pad[0].l2++; | |
858 } else { | |
859 pad[0].l2 = 0; | |
860 } | |
861 | |
862 // START ボタンは Return が似合う気がする | |
863 //if(keys[SDLK_1]) | |
864 if (keys[SDLK_RETURN]) { | |
865 pad[0].st++; | |
866 } else { | |
867 pad[0].st = 0; | |
868 } | |
869 | |
870 if (keys[SDLK_2]) { | |
871 pad[0].se++; | |
872 } else { | |
873 pad[0].se = 0; | |
874 } | |
875 | |
876 if (keys[SDLK_ESCAPE]) { | |
44 | 877 pad[0].quit = 1; |
0 | 878 } |
879 | |
880 if (keys[SDLK_0]) { | |
881 pad[0].quit = 1; | |
882 } else { | |
883 pad[0].quit = 0; | |
884 } | |
885 } | |
886 | |
887 | |
44 | 888 static void |
889 KeyAssign(int runmode, TraceBuffPtr buff, SDL_Joystick *joy, SGO_PAD *pad) | |
890 { | |
891 switch (runmode) { | |
892 case 0: | |
893 if (use_keybord) { | |
894 keybord(); | |
895 } else { | |
896 Pad(joy); | |
897 } | |
898 break; | |
899 case 1: | |
900 if (use_keybord) { | |
901 keybord(); | |
902 } else { | |
903 Pad(joy); | |
904 } | |
53 | 905 cheat(); |
44 | 906 t_buff = CapturePad(t_buff, pad); |
907 break; | |
908 case 2: | |
909 t_buff = TracePad(t_buff, pad); | |
53 | 910 cheat(); |
44 | 911 break; |
912 } | |
913 } | |
914 | |
0 | 915 /* end */ |