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