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