Mercurial > hg > Members > koba > t_dandy
annotate Dandy.cc @ 44:2c85322348cf
add print log.
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 14 Jan 2011 23:49:23 +0900 |
parents | cbe5bb9068c3 |
children | e01948ce859a |
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; |
34 static int cdp[20] = { 16, 16, 16, 17, 18, 0 }; | |
35 static int d, 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 | |
357 count++; | |
358 //PutSprite(count, 0, 960 - 96, 10); | |
359 /*インフレゲージ */ | |
360 count++; | |
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 } | |
0 | 383 |
384 //_______________________________________________ | |
385 // SDL_mixerの後始末 | |
386 Mix_CloseAudio(); | |
387 Mix_HaltMusic(); | |
388 FreeSdlMixer() ; | |
389 //_______________________________________________ | |
390 return 0; | |
391 } | |
392 | |
393 | |
394 static int | |
395 gamesyokika(int gamef) | |
396 { | |
397 laser_lv3[0].r = 62; | |
398 laser_lv3[0].r = 62; | |
399 for (i = 0; i < 3; i++) { | |
400 tlv3[i].y = -1; | |
401 } | |
402 filpcount = 0; | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
403 stage = 0; |
0 | 404 //for (i = 0; i < 300; i++) |
405 //enemy[i].f = FALSE; | |
406 jiki.zanki = 3; | |
407 jiki.x = 60; | |
408 jiki.y = 200; | |
409 jiki.ch = 3; | |
410 jiki.point = 0; | |
411 jiki.bf = FALSE; | |
412 jiki.muteki = 120; | |
413 enemycount = 0; | |
414 lg.stg = 4096; | |
415 pg.stg = 4096; | |
416 infg.stg = 0; | |
417 infg_level = 0; | |
418 //kyeenemyno = -1; | |
419 fastebos = 0; | |
420 jiki.ccount = 99; | |
421 p_extend = 200000; | |
422 pad[0].up=0; | |
423 pad[0].down=0; | |
424 pad[0].right=0; | |
425 pad[0].left=0; | |
426 pad[0].st=0; | |
427 pad[0].se=0; | |
428 | |
429 SoundStop(); | |
430 SoundPlay(7); | |
431 gamef = 2; | |
432 flip(); | |
433 return gamef; | |
434 } | |
435 | |
436 static int | |
437 opening(int gamef) | |
438 { | |
439 if(use_keybord == 1) { | |
440 keybord(); | |
441 } else { | |
442 Pad(joy); | |
443 } | |
444 | |
445 count = 1; | |
446 | |
447 PutSprite(count, 700, 480, 53); // put `push start' string on screen. | |
448 count++; | |
449 PutSprite(count, 224, 776, 119); // put `super dandy' | |
450 count++; | |
451 // PutSprite(count, 200, 64, 190); | |
452 // PutSpriteEx(count, 8192, 8192, 0); | |
453 PutSpriteEx(190, 800, 264, 2, 2, 5); | |
454 count++; | |
455 PutSprite(count, 396, 432, 191); | |
456 //PutSpriteEx(count, 8192, 8192, 0); | |
457 count++; | |
458 PutSprite(count, 640, 640, 192); | |
459 //PutSpriteEx(count, 8192, 8192, 0); | |
460 | |
461 if (pad[0].st > 1) { | |
462 jiki.bf = TRUE; | |
463 | |
464 //CdPlay(1,&cdp[0],0); | |
465 SoundStop(); | |
466 SoundPlay(0); | |
467 | |
468 gamef = 3; | |
469 pad[0].st = 1; | |
470 } else if ((pad[0].se > 0) && (pad[0].st > 0)) { | |
471 gamef = 2; | |
472 } | |
473 flip(); | |
474 return gamef; | |
475 } | |
476 | |
477 static int | |
478 game_pause(int gamef) | |
479 { | |
480 gamef = 3; | |
481 if (jiki.zanki != 0 && jiki.bf != FALSE) { | |
482 if (pad[0].se == 1) { | |
483 //Mix_Pause(BGM); | |
484 PauseSdlMixer(BGM); | |
485 while(1){ | |
486 if(use_keybord == 1) { | |
487 keybord(); | |
488 } else { | |
489 Pad(joy); | |
490 } | |
491 if(pad[0].st == 0) | |
492 continue; | |
493 pad[0].up=0; | |
494 pad[0].down=0; | |
495 pad[0].right=0; | |
496 pad[0].left=0; | |
497 pad[0].se=0; | |
498 pad[0].st=0; | |
499 //Mix_Resume(BGM); | |
500 ResumeSdlMixer(BGM); | |
501 break; | |
502 } | |
503 } | |
504 } | |
505 if (jiki.zanki == 0) { | |
506 // RECT *recp; | |
507 if ((jiki.ccount > 0) && (cf == 0)) { | |
508 cf = 1; | |
509 count++; | |
510 //cgcg(2); | |
511 PutSprite(2, 480, 480, 110); | |
512 count++; | |
513 //cgcg(1); | |
514 } | |
515 if ((jiki.ccount > 0) && (cf == 1)) { | |
516 while (1) { | |
517 if (pad[0].st > 0) { | |
518 cf = 0; | |
519 jiki.ccount--; | |
520 jiki.zanki = 3; | |
521 enemycount++; | |
522 cc = 0; | |
523 for (i = 0; i < 4; i++) { | |
524 clear_result[i] = 0; | |
525 } | |
526 goto f; | |
527 } | |
528 cc++; | |
529 if (29 - cc / 60 < 20) { | |
530 cc = 0; | |
531 cf = 3; | |
532 break; | |
533 } | |
534 SDL_Delay(100); | |
535 PutSprite(1, 640, 640, 29 - cc / 60); | |
536 // PutSpriteEx(1, 409 * ((cc % 60) + 1), 409 * ((cc % 60) + 1), 0); | |
537 | |
538 Pad(joy); | |
539 flip(); // this is not correct | |
540 } | |
541 } | |
542 if (rswait > 60 * 6) { | |
543 cf = 0; | |
544 rswait = 0; | |
545 gamef = gamesyokika(gamef); | |
546 } | |
547 rswait++; | |
548 count++; | |
549 //cgcg(1); | |
550 PutSprite(1, 480, 480, 19); | |
551 return gamef; | |
552 } | |
553 if (jiki.bf == FALSE) { | |
554 f: | |
555 if (rswait < 80) { | |
556 rswait++; | |
557 return gamef; | |
558 } else { | |
559 rswait = 0; | |
560 jiki.x = 60; | |
561 jiki.y = 200; | |
562 jiki.bf = TRUE; | |
563 | |
564 pad[0].st = 0; | |
565 lg.stg = 4096; | |
566 pg.stg = 4096; | |
567 laser_lv3[0].r = 62; | |
568 tlv3[0].r = 0; | |
569 tlv3[0].y = -1; | |
570 return gamef; | |
571 // sb_size = -1; | |
572 } | |
573 } | |
574 return gamef; | |
575 } | |
576 | |
577 | |
578 SpriteTable sptable[DEFOBJ]; | |
579 | |
580 | |
581 void | |
582 DefSpriteEx(int number, short middlex, short middley) | |
583 { | |
584 sptable[number].mx = middlex; | |
585 sptable[number].my = middley; | |
586 } | |
587 | |
588 | |
589 void | |
590 DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj) | |
591 { | |
592 SpriteTable *m = &sptable[number]; | |
593 m->w = w; | |
594 m->h = h; | |
595 m->color = (color & 32); | |
596 m->mx = w / 2; | |
597 m->my = h / 2; | |
33 | 598 m->tex_w = power_of_two(m->w); |
599 m->tex_h = power_of_two(m->h); | |
600 | |
0 | 601 m->texture = (int *)name; |
602 | |
603 } | |
604 | |
33 | 605 static float my_scale = 5; |
606 | |
0 | 607 void |
608 PutSprite(int zorder, short x, short y, int number) | |
609 { | |
610 SpriteTable *m = &sptable[number]; | |
611 char *name = (char *) m->texture; | |
33 | 612 if (!name) { |
613 printf("PutSprite %d unknown\n",number); | |
614 return; | |
615 } | |
0 | 616 SceneGraphPtr object = sgroot->createSceneGraph(name); |
33 | 617 object->xyz[0] = x - object->c_xyz[0]*my_scale; |
618 object->xyz[1] = y - object->c_xyz[1]*my_scale; | |
0 | 619 object->xyz[2] = 0; |
620 root->addChild(object); | |
621 | |
33 | 622 float scale[] = {my_scale,my_scale,1}; |
0 | 623 /*親の回転、座標から、子の回転、座標を算出*/ |
624 get_matrix(object->matrix, object->angle, object->xyz, scale, root->matrix); | |
625 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
626 get_matrix(object->real_matrix, object->angle, object->xyz, scale, root->real_matrix); | |
627 | |
628 } | |
629 | |
630 void | |
631 PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle) | |
632 { | |
633 SpriteTable *m = &sptable[number]; | |
634 char *name = (char *) m->texture; | |
635 if (!name) { | |
636 printf("PutSpriteEx %d unknown\n",number); | |
637 return; | |
638 } | |
639 SceneGraphPtr object = sgroot->createSceneGraph(name); | |
33 | 640 object->xyz[0] = x - object->c_xyz[0]*my_scale - m->w*my_scale; |
641 object->xyz[1] = y - object->c_xyz[0]*my_scale - m->w*my_scale; | |
0 | 642 object->xyz[2] = 0; |
643 object->c_xyz[0] = m->mx; | |
644 object->c_xyz[1] = m->my; | |
645 object->angle[3] = angle; | |
646 root->addChild(object); | |
647 | |
648 float scale[] = {5*scalex,5*scaley,1}; | |
649 /*親の回転、座標から、子の回転、座標を算出*/ | |
650 get_matrix(object->matrix, object->angle, object->xyz, scale, root->matrix); | |
651 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
652 get_matrix(object->real_matrix, object->angle, object->xyz, scale, root->real_matrix); | |
653 } | |
654 | |
655 | |
656 struct SGO_PAD pad[2]; | |
657 | |
658 | |
659 /* コントローラ状態の読み込み */ | |
660 void Pad(SDL_Joystick *joy) | |
661 { | |
662 Sint16 axis; | |
663 | |
664 SDL_JoystickUpdate(); | |
665 | |
666 if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED) | |
667 pad[0].k0++; | |
668 else | |
669 pad[0].k0=0; | |
670 | |
671 if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED) | |
672 pad[0].k1++; | |
673 else | |
674 pad[0].k1=0; | |
675 | |
676 if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED) | |
677 pad[0].k3++; | |
678 else | |
679 pad[0].k3=0; | |
680 | |
681 if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED) | |
682 pad[0].k4++; | |
683 else | |
684 pad[0].k4=0; | |
685 | |
686 if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED) | |
687 pad[0].l1++; | |
688 else | |
689 pad[0].l1=0; | |
690 | |
691 if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED) | |
692 pad[0].r1++; | |
693 else | |
694 pad[0].r1=0; | |
695 | |
696 if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED) | |
697 pad[0].l2++; | |
698 else | |
699 pad[0].l2=0; | |
700 | |
701 if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED) | |
702 pad[0].r2++; | |
703 else | |
704 pad[0].r2=0; | |
705 | |
706 if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED) | |
707 pad[0].st++; | |
708 else | |
709 pad[0].st=0; | |
710 | |
711 if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED) | |
712 pad[0].se++; | |
713 else | |
714 pad[0].se=0; | |
715 | |
716 if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED) | |
717 pad[0].l3++; | |
718 else | |
719 pad[0].l3=0; | |
720 | |
721 if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED) | |
722 pad[0].r3++; | |
723 else | |
724 pad[0].r3=0; | |
725 //x | |
726 axis=SDL_JoystickGetAxis(joy,0); | |
727 if(axis>=3200){ | |
728 pad[0].left=0; | |
729 pad[0].right++; | |
730 } | |
731 else if(axis<=-3200){ | |
732 pad[0].right=0; | |
733 pad[0].left++; | |
734 } | |
735 else { | |
736 pad[0].right=0; | |
737 pad[0].left=0; | |
738 } | |
739 //y | |
740 axis=SDL_JoystickGetAxis(joy,1); | |
741 if(axis>=3200){ | |
742 pad[0].up=0; | |
743 pad[0].down++; | |
744 } | |
745 else if(axis<=-3200){ | |
746 pad[0].down=0; | |
747 pad[0].up++; | |
748 } | |
749 else { | |
750 pad[0].down=0; | |
751 pad[0].up=0; | |
752 } | |
753 | |
754 if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && | |
755 (pad[0].l2 != 0) && (pad[0].r2 != 0) && | |
756 (pad[0].st != 0) && (pad[0].se != 0)) { | |
757 pad[0].quit = 1; | |
758 } else { | |
759 pad[0].quit = 0; | |
760 } | |
761 | |
762 } | |
763 | |
764 | |
765 void keybord() | |
766 { | |
767 SDL_PumpEvents(); | |
768 Uint8 *keys = SDL_GetKeyState(NULL); | |
769 | |
770 if (keys[SDLK_UP]) { | |
771 pad[0].up++; | |
772 } else { | |
773 pad[0].up = 0; | |
774 } | |
775 if (keys[SDLK_DOWN]) { | |
776 pad[0].down++; | |
777 } else { | |
778 pad[0].down = 0; | |
779 } | |
780 | |
781 if (keys[SDLK_RIGHT]) { | |
782 pad[0].right++; | |
783 } else { | |
784 pad[0].right = 0; | |
785 } | |
786 | |
787 if (keys[SDLK_LEFT]) { | |
788 pad[0].left++; | |
789 } else { | |
790 pad[0].left = 0; | |
791 } | |
792 | |
793 if (keys[SDLK_a]) { | |
794 pad[0].k0++; | |
795 } else { | |
796 pad[0].k0 = 0; | |
797 } | |
798 | |
799 if (keys[SDLK_z]) { | |
800 pad[0].k1++; | |
801 } else { | |
802 pad[0].k1 = 0; | |
803 } | |
804 | |
805 if (keys[SDLK_s]) { | |
806 pad[0].k3++; | |
807 } else { | |
808 pad[0].k3 = 0; | |
809 } | |
810 | |
811 if (keys[SDLK_x]) { | |
812 pad[0].k4++; | |
813 } else { | |
814 pad[0].k4 = 0; | |
815 } | |
816 | |
817 if (keys[SDLK_r]) { | |
818 pad[0].r2++; | |
819 } else { | |
820 pad[0].r2 = 0; | |
821 } | |
822 | |
823 if (keys[SDLK_e]) { | |
824 pad[0].r1++; | |
825 } else { | |
826 pad[0].r1 = 0; | |
827 } | |
828 | |
829 if (keys[SDLK_w]) { | |
830 pad[0].l1++; | |
831 } else { | |
832 pad[0].l1 = 0; | |
833 } | |
834 | |
835 if (keys[SDLK_q]) { | |
836 pad[0].l2++; | |
837 } else { | |
838 pad[0].l2 = 0; | |
839 } | |
840 | |
841 // START ボタンは Return が似合う気がする | |
842 //if(keys[SDLK_1]) | |
843 if (keys[SDLK_RETURN]) { | |
844 pad[0].st++; | |
845 } else { | |
846 pad[0].st = 0; | |
847 } | |
848 | |
849 if (keys[SDLK_2]) { | |
850 pad[0].se++; | |
851 } else { | |
852 pad[0].se = 0; | |
853 } | |
854 | |
855 if (keys[SDLK_ESCAPE]) { | |
44 | 856 pad[0].quit = 1; |
0 | 857 } |
858 | |
859 if (keys[SDLK_0]) { | |
860 pad[0].quit = 1; | |
861 } else { | |
862 pad[0].quit = 0; | |
863 } | |
864 } | |
865 | |
866 | |
44 | 867 static void |
868 KeyAssign(int runmode, TraceBuffPtr buff, SDL_Joystick *joy, SGO_PAD *pad) | |
869 { | |
870 switch (runmode) { | |
871 case 0: | |
872 if (use_keybord) { | |
873 keybord(); | |
874 } else { | |
875 Pad(joy); | |
876 } | |
877 break; | |
878 case 1: | |
879 if (use_keybord) { | |
880 keybord(); | |
881 } else { | |
882 Pad(joy); | |
883 } | |
884 t_buff = CapturePad(t_buff, pad); | |
885 break; | |
886 case 2: | |
887 t_buff = TracePad(t_buff, pad); | |
888 break; | |
889 } | |
890 } | |
891 | |
0 | 892 /* end */ |