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