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