Mercurial > hg > Members > koba > t_dandy
annotate Dandy.cc @ 46:fce767bb5e25
keep up with scale_matrix(not work)
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 18 Jan 2011 02:20:10 +0900 |
parents | e01948ce859a |
children | b99e4366b913 |
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 sgroot->sgroot->lightCalc(); | |
304 | |
305 root = sgroot->createSceneGraph(); | |
19 | 306 root->xyz[0] = 0; |
307 root->xyz[1] = 0; | |
0 | 308 root->xyz[2] = 30.0f; |
309 | |
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のコンストラクタで、単位行列にしている)*/ |
46
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
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; | |
45 | 611 |
33 | 612 if (!name) { |
45 | 613 // printf("PutSprite %d unknown\n",number); |
33 | 614 return; |
615 } | |
45 | 616 |
0 | 617 SceneGraphPtr object = sgroot->createSceneGraph(name); |
46
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
618 object->xyz[0] = x; |
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
619 object->xyz[1] = y; |
0 | 620 object->xyz[2] = 0; |
621 root->addChild(object); | |
622 | |
33 | 623 float scale[] = {my_scale,my_scale,1}; |
0 | 624 /*親の回転、座標から、子の回転、座標を算出*/ |
46
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
625 get_matrix(object->matrix, object->angle, object->xyz, root->matrix); |
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
626 scale_matrix(object->matrix, scale, object->c_xyz); |
0 | 627 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ |
46
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
628 get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix); |
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
629 scale_matrix(object->real_matrix, scale, object->c_xyz); |
0 | 630 } |
631 | |
632 void | |
633 PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle) | |
634 { | |
635 SpriteTable *m = &sptable[number]; | |
636 char *name = (char *) m->texture; | |
45 | 637 if (!name) { |
638 // printf("PutSpriteEx %d unknown\n",number); | |
639 return; | |
640 } | |
641 | |
0 | 642 SceneGraphPtr object = sgroot->createSceneGraph(name); |
46
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
643 object->xyz[0] = x - m->w*my_scale; |
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
644 object->xyz[1] = y - m->h*my_scale; |
0 | 645 object->xyz[2] = 0; |
646 object->c_xyz[0] = m->mx; | |
647 object->c_xyz[1] = m->my; | |
648 object->angle[3] = angle; | |
649 root->addChild(object); | |
650 | |
651 float scale[] = {5*scalex,5*scaley,1}; | |
652 /*親の回転、座標から、子の回転、座標を算出*/ | |
46
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
653 get_matrix(object->matrix, object->angle, object->xyz, root->matrix); |
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
654 scale_matrix(object->matrix, scale, object->c_xyz); |
0 | 655 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ |
46
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
656 get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix); |
fce767bb5e25
keep up with scale_matrix(not work)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
657 scale_matrix(object->real_matrix, scale, object->c_xyz); |
0 | 658 } |
659 | |
660 | |
661 struct SGO_PAD pad[2]; | |
662 | |
663 | |
664 /* コントローラ状態の読み込み */ | |
665 void Pad(SDL_Joystick *joy) | |
666 { | |
667 Sint16 axis; | |
668 | |
669 SDL_JoystickUpdate(); | |
670 | |
671 if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED) | |
672 pad[0].k0++; | |
673 else | |
674 pad[0].k0=0; | |
675 | |
676 if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED) | |
677 pad[0].k1++; | |
678 else | |
679 pad[0].k1=0; | |
680 | |
681 if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED) | |
682 pad[0].k3++; | |
683 else | |
684 pad[0].k3=0; | |
685 | |
686 if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED) | |
687 pad[0].k4++; | |
688 else | |
689 pad[0].k4=0; | |
690 | |
691 if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED) | |
692 pad[0].l1++; | |
693 else | |
694 pad[0].l1=0; | |
695 | |
696 if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED) | |
697 pad[0].r1++; | |
698 else | |
699 pad[0].r1=0; | |
700 | |
701 if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED) | |
702 pad[0].l2++; | |
703 else | |
704 pad[0].l2=0; | |
705 | |
706 if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED) | |
707 pad[0].r2++; | |
708 else | |
709 pad[0].r2=0; | |
710 | |
711 if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED) | |
712 pad[0].st++; | |
713 else | |
714 pad[0].st=0; | |
715 | |
716 if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED) | |
717 pad[0].se++; | |
718 else | |
719 pad[0].se=0; | |
720 | |
721 if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED) | |
722 pad[0].l3++; | |
723 else | |
724 pad[0].l3=0; | |
725 | |
726 if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED) | |
727 pad[0].r3++; | |
728 else | |
729 pad[0].r3=0; | |
730 //x | |
731 axis=SDL_JoystickGetAxis(joy,0); | |
732 if(axis>=3200){ | |
733 pad[0].left=0; | |
734 pad[0].right++; | |
735 } | |
736 else if(axis<=-3200){ | |
737 pad[0].right=0; | |
738 pad[0].left++; | |
739 } | |
740 else { | |
741 pad[0].right=0; | |
742 pad[0].left=0; | |
743 } | |
744 //y | |
745 axis=SDL_JoystickGetAxis(joy,1); | |
746 if(axis>=3200){ | |
747 pad[0].up=0; | |
748 pad[0].down++; | |
749 } | |
750 else if(axis<=-3200){ | |
751 pad[0].down=0; | |
752 pad[0].up++; | |
753 } | |
754 else { | |
755 pad[0].down=0; | |
756 pad[0].up=0; | |
757 } | |
758 | |
759 if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && | |
760 (pad[0].l2 != 0) && (pad[0].r2 != 0) && | |
761 (pad[0].st != 0) && (pad[0].se != 0)) { | |
762 pad[0].quit = 1; | |
763 } else { | |
764 pad[0].quit = 0; | |
765 } | |
766 | |
767 } | |
768 | |
769 | |
770 void keybord() | |
771 { | |
772 SDL_PumpEvents(); | |
773 Uint8 *keys = SDL_GetKeyState(NULL); | |
774 | |
775 if (keys[SDLK_UP]) { | |
776 pad[0].up++; | |
777 } else { | |
778 pad[0].up = 0; | |
779 } | |
780 if (keys[SDLK_DOWN]) { | |
781 pad[0].down++; | |
782 } else { | |
783 pad[0].down = 0; | |
784 } | |
785 | |
786 if (keys[SDLK_RIGHT]) { | |
787 pad[0].right++; | |
788 } else { | |
789 pad[0].right = 0; | |
790 } | |
791 | |
792 if (keys[SDLK_LEFT]) { | |
793 pad[0].left++; | |
794 } else { | |
795 pad[0].left = 0; | |
796 } | |
797 | |
798 if (keys[SDLK_a]) { | |
799 pad[0].k0++; | |
800 } else { | |
801 pad[0].k0 = 0; | |
802 } | |
803 | |
804 if (keys[SDLK_z]) { | |
805 pad[0].k1++; | |
806 } else { | |
807 pad[0].k1 = 0; | |
808 } | |
809 | |
810 if (keys[SDLK_s]) { | |
811 pad[0].k3++; | |
812 } else { | |
813 pad[0].k3 = 0; | |
814 } | |
815 | |
816 if (keys[SDLK_x]) { | |
817 pad[0].k4++; | |
818 } else { | |
819 pad[0].k4 = 0; | |
820 } | |
821 | |
822 if (keys[SDLK_r]) { | |
823 pad[0].r2++; | |
824 } else { | |
825 pad[0].r2 = 0; | |
826 } | |
827 | |
828 if (keys[SDLK_e]) { | |
829 pad[0].r1++; | |
830 } else { | |
831 pad[0].r1 = 0; | |
832 } | |
833 | |
834 if (keys[SDLK_w]) { | |
835 pad[0].l1++; | |
836 } else { | |
837 pad[0].l1 = 0; | |
838 } | |
839 | |
840 if (keys[SDLK_q]) { | |
841 pad[0].l2++; | |
842 } else { | |
843 pad[0].l2 = 0; | |
844 } | |
845 | |
846 // START ボタンは Return が似合う気がする | |
847 //if(keys[SDLK_1]) | |
848 if (keys[SDLK_RETURN]) { | |
849 pad[0].st++; | |
850 } else { | |
851 pad[0].st = 0; | |
852 } | |
853 | |
854 if (keys[SDLK_2]) { | |
855 pad[0].se++; | |
856 } else { | |
857 pad[0].se = 0; | |
858 } | |
859 | |
860 if (keys[SDLK_ESCAPE]) { | |
44 | 861 pad[0].quit = 1; |
0 | 862 } |
863 | |
864 if (keys[SDLK_0]) { | |
865 pad[0].quit = 1; | |
866 } else { | |
867 pad[0].quit = 0; | |
868 } | |
869 } | |
870 | |
871 | |
44 | 872 static void |
873 KeyAssign(int runmode, TraceBuffPtr buff, SDL_Joystick *joy, SGO_PAD *pad) | |
874 { | |
875 switch (runmode) { | |
876 case 0: | |
877 if (use_keybord) { | |
878 keybord(); | |
879 } else { | |
880 Pad(joy); | |
881 } | |
882 break; | |
883 case 1: | |
884 if (use_keybord) { | |
885 keybord(); | |
886 } else { | |
887 Pad(joy); | |
888 } | |
889 t_buff = CapturePad(t_buff, pad); | |
890 break; | |
891 case 2: | |
892 t_buff = TracePad(t_buff, pad); | |
893 break; | |
894 } | |
895 } | |
896 | |
0 | 897 /* end */ |