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