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