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
|
|
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
|
|
76 static int screen_w;
|
|
77 static int screen_h;
|
|
78
|
|
79 MainLoopPtr
|
|
80 Dandy::init(Viewer *sgroot_, int w, int h)
|
|
81 {
|
|
82 screen_w = w;
|
|
83 screen_h = h;
|
|
84 sgroot = sgroot_;
|
|
85 return sgroot;
|
|
86 }
|
|
87
|
|
88 Application *
|
|
89 application() {
|
|
90 return new Dandy();
|
|
91 }
|
|
92
|
|
93
|
|
94 static int opening(int gamef);
|
|
95 static int dandy_closing(int gamef);
|
|
96 static int dandy_main_loop(int gamef);
|
|
97 static int dandy_main_init(int gamef);
|
|
98 extern int init(TaskManager *manager, int argc, char *argv[]);
|
|
99 extern void task_initialize();
|
|
100 static void TMend(TaskManager *manager);
|
|
101
|
|
102 bool
|
|
103 Dandy::app_loop(Viewer *viewer){
|
|
104 // don't use allExecute
|
|
105 return 0;
|
|
106 };
|
|
107
|
|
108 static int gamef = 0;
|
|
109
|
|
110 HTaskPtr
|
|
111 Dandy::application_task(HTaskPtr next, Viewer* viewer){
|
|
112 // printf("gamef = %d\n",gamef);
|
|
113 switch (gamef) {
|
|
114 case 0: gamef= dandy_main_init(gamef); break;
|
|
115 case 1: gamef= gamesyokika(gamef); break;
|
|
116 case 2: gamef= opening(gamef); break;
|
|
117 case 3: gamef= dandy_main_loop(gamef); break;
|
|
118 case 4: gamef= dandy_closing(gamef); break;
|
|
119 }
|
|
120 return next;
|
|
121 };
|
|
122
|
|
123
|
|
124
|
|
125
|
|
126 static void
|
|
127 task_init()
|
|
128 {
|
|
129 }
|
|
130
|
|
131 int
|
|
132 TMmain(TaskManager *manager,int argc, char *argv[])
|
|
133 {
|
|
134 task_init();
|
|
135 task_initialize();
|
|
136 manager->set_TMend(TMend);
|
|
137
|
|
138 return init(manager,argc, argv);
|
|
139 }
|
|
140
|
|
141 void
|
|
142 TMend(TaskManager *manager)
|
|
143 {
|
|
144 printf("game end\n");
|
|
145 }
|
|
146
|
|
147 static int light_sysswitch = 1;
|
|
148 static int light_num = 4;
|
|
149
|
|
150 static void
|
|
151 LightSysSwitch(Viewer *sgroot) {
|
|
152 if (light_sysswitch == 1) {
|
|
153 sgroot->OnLightSysSwitch();
|
|
154 for (int i = 0; i < light_num; i++) {
|
|
155 SceneGraphPtr light = sgroot->getLight(i);
|
|
156 sgroot->OnLightSwitch(i);
|
|
157 light->xyz[0] = screen_w / 2;
|
|
158 light->xyz[1] = screen_h / 2;
|
|
159 light->xyz[2] = -100;
|
|
160 }
|
|
161 } else if (light_sysswitch == 0) {
|
|
162 sgroot->OffLightSysSwitch();
|
|
163 }
|
|
164 }
|
|
165
|
|
166
|
|
167 static int
|
|
168 dandy_main_init(int gamef)
|
|
169 {
|
|
170 //Timeprof timeprof_move;
|
|
171 //timeprof_move = timeprof_new();
|
|
172 dbg_init("/dev/stdout");
|
|
173
|
|
174 /**
|
|
175 * timeprof があるんだけどね
|
|
176 */
|
|
177
|
|
178 sgroot->createFromXMLfile("xml/character.xml");
|
|
179 sgroot->createFromXMLfile("xml/font.xml");
|
|
180 sgroot->createFromXMLfile("xml/effect.xml");
|
|
181 sgroot->createFromXMLfile("xml/boss.xml");
|
|
182
|
|
183 LightSysSwitch(sgroot);
|
|
184
|
|
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();
|
|
219
|
|
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();
|
|
245 root->xyz[0] = screen_w/2;
|
|
246 root->xyz[1] = screen_h/2;;
|
|
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);
|
|
272
|
|
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;
|
|
533 m->tex_w = power_of_two(sptable[number].w);
|
|
534 m->tex_h = power_of_two(sptable[number].h);
|
|
535 //texMinX[number] = 0.0f;
|
|
536 //texMinY[number] = 0.0f;
|
|
537 //texMaxX[number] = (GLfloat)sptable[number].w / sptable[number].tex_w;
|
|
538 //texMaxY[number] = (GLfloat)sptable[number].h / sptable[number].tex_h;
|
|
539 // printf("texMaxX = %f, w = %d, tex_w = %d\n", texMaxX[number], sptable[number].w, sptable[number].tex_w);
|
|
540 m->texture = (int *)name;
|
|
541
|
|
542 }
|
|
543
|
|
544 void
|
|
545 PutSprite(int zorder, short x, short y, int number)
|
|
546 {
|
|
547 SpriteTable *m = &sptable[number];
|
|
548 char *name = (char *) m->texture;
|
|
549 if (!name) {
|
|
550 printf("PutSprite %d unknown\n",number);
|
|
551 return;
|
|
552 }
|
|
553 SceneGraphPtr object = sgroot->createSceneGraph(name);
|
|
554 object->xyz[0] = x;
|
|
555 object->xyz[1] = y;
|
|
556 object->xyz[2] = 0;
|
|
557 root->addChild(object);
|
|
558
|
|
559 float scale[] = {5,5,1};
|
|
560 /*親の回転、座標から、子の回転、座標を算出*/
|
|
561 get_matrix(object->matrix, object->angle, object->xyz, scale, root->matrix);
|
|
562 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
|
|
563 get_matrix(object->real_matrix, object->angle, object->xyz, scale, root->real_matrix);
|
|
564
|
|
565 }
|
|
566
|
|
567 void
|
|
568 PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle)
|
|
569 {
|
|
570 SpriteTable *m = &sptable[number];
|
|
571 char *name = (char *) m->texture;
|
|
572 if (!name) {
|
|
573 printf("PutSpriteEx %d unknown\n",number);
|
|
574 return;
|
|
575 }
|
|
576 SceneGraphPtr object = sgroot->createSceneGraph(name);
|
|
577 object->xyz[0] = x;
|
|
578 object->xyz[1] = y;
|
|
579 object->xyz[2] = 0;
|
|
580 object->c_xyz[0] = m->mx;
|
|
581 object->c_xyz[1] = m->my;
|
|
582 object->angle[3] = angle;
|
|
583 root->addChild(object);
|
|
584
|
|
585 float scale[] = {5*scalex,5*scaley,1};
|
|
586 /*親の回転、座標から、子の回転、座標を算出*/
|
|
587 get_matrix(object->matrix, object->angle, object->xyz, scale, root->matrix);
|
|
588 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
|
|
589 get_matrix(object->real_matrix, object->angle, object->xyz, scale, root->real_matrix);
|
|
590 }
|
|
591
|
|
592
|
|
593 struct SGO_PAD pad[2];
|
|
594
|
|
595
|
|
596 /* コントローラ状態の読み込み */
|
|
597 void Pad(SDL_Joystick *joy)
|
|
598 {
|
|
599 Sint16 axis;
|
|
600
|
|
601 SDL_JoystickUpdate();
|
|
602
|
|
603 if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED)
|
|
604 pad[0].k0++;
|
|
605 else
|
|
606 pad[0].k0=0;
|
|
607
|
|
608 if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED)
|
|
609 pad[0].k1++;
|
|
610 else
|
|
611 pad[0].k1=0;
|
|
612
|
|
613 if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED)
|
|
614 pad[0].k3++;
|
|
615 else
|
|
616 pad[0].k3=0;
|
|
617
|
|
618 if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED)
|
|
619 pad[0].k4++;
|
|
620 else
|
|
621 pad[0].k4=0;
|
|
622
|
|
623 if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED)
|
|
624 pad[0].l1++;
|
|
625 else
|
|
626 pad[0].l1=0;
|
|
627
|
|
628 if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED)
|
|
629 pad[0].r1++;
|
|
630 else
|
|
631 pad[0].r1=0;
|
|
632
|
|
633 if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED)
|
|
634 pad[0].l2++;
|
|
635 else
|
|
636 pad[0].l2=0;
|
|
637
|
|
638 if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED)
|
|
639 pad[0].r2++;
|
|
640 else
|
|
641 pad[0].r2=0;
|
|
642
|
|
643 if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED)
|
|
644 pad[0].st++;
|
|
645 else
|
|
646 pad[0].st=0;
|
|
647
|
|
648 if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED)
|
|
649 pad[0].se++;
|
|
650 else
|
|
651 pad[0].se=0;
|
|
652
|
|
653 if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED)
|
|
654 pad[0].l3++;
|
|
655 else
|
|
656 pad[0].l3=0;
|
|
657
|
|
658 if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED)
|
|
659 pad[0].r3++;
|
|
660 else
|
|
661 pad[0].r3=0;
|
|
662 //x
|
|
663 axis=SDL_JoystickGetAxis(joy,0);
|
|
664 if(axis>=3200){
|
|
665 pad[0].left=0;
|
|
666 pad[0].right++;
|
|
667 }
|
|
668 else if(axis<=-3200){
|
|
669 pad[0].right=0;
|
|
670 pad[0].left++;
|
|
671 }
|
|
672 else {
|
|
673 pad[0].right=0;
|
|
674 pad[0].left=0;
|
|
675 }
|
|
676 //y
|
|
677 axis=SDL_JoystickGetAxis(joy,1);
|
|
678 if(axis>=3200){
|
|
679 pad[0].up=0;
|
|
680 pad[0].down++;
|
|
681 }
|
|
682 else if(axis<=-3200){
|
|
683 pad[0].down=0;
|
|
684 pad[0].up++;
|
|
685 }
|
|
686 else {
|
|
687 pad[0].down=0;
|
|
688 pad[0].up=0;
|
|
689 }
|
|
690
|
|
691 if ((pad[0].l1 != 0) && (pad[0].r1 != 0) &&
|
|
692 (pad[0].l2 != 0) && (pad[0].r2 != 0) &&
|
|
693 (pad[0].st != 0) && (pad[0].se != 0)) {
|
|
694 pad[0].quit = 1;
|
|
695 } else {
|
|
696 pad[0].quit = 0;
|
|
697 }
|
|
698
|
|
699 }
|
|
700
|
|
701
|
|
702 void keybord()
|
|
703 {
|
|
704 SDL_PumpEvents();
|
|
705 Uint8 *keys = SDL_GetKeyState(NULL);
|
|
706
|
|
707 if (keys[SDLK_UP]) {
|
|
708 pad[0].up++;
|
|
709 } else {
|
|
710 pad[0].up = 0;
|
|
711 }
|
|
712 if (keys[SDLK_DOWN]) {
|
|
713 pad[0].down++;
|
|
714 } else {
|
|
715 pad[0].down = 0;
|
|
716 }
|
|
717
|
|
718 if (keys[SDLK_RIGHT]) {
|
|
719 pad[0].right++;
|
|
720 } else {
|
|
721 pad[0].right = 0;
|
|
722 }
|
|
723
|
|
724 if (keys[SDLK_LEFT]) {
|
|
725 pad[0].left++;
|
|
726 } else {
|
|
727 pad[0].left = 0;
|
|
728 }
|
|
729
|
|
730 if (keys[SDLK_a]) {
|
|
731 pad[0].k0++;
|
|
732 } else {
|
|
733 pad[0].k0 = 0;
|
|
734 }
|
|
735
|
|
736 if (keys[SDLK_z]) {
|
|
737 pad[0].k1++;
|
|
738 } else {
|
|
739 pad[0].k1 = 0;
|
|
740 }
|
|
741
|
|
742 if (keys[SDLK_s]) {
|
|
743 pad[0].k3++;
|
|
744 } else {
|
|
745 pad[0].k3 = 0;
|
|
746 }
|
|
747
|
|
748 if (keys[SDLK_x]) {
|
|
749 pad[0].k4++;
|
|
750 } else {
|
|
751 pad[0].k4 = 0;
|
|
752 }
|
|
753
|
|
754 if (keys[SDLK_r]) {
|
|
755 pad[0].r2++;
|
|
756 } else {
|
|
757 pad[0].r2 = 0;
|
|
758 }
|
|
759
|
|
760 if (keys[SDLK_e]) {
|
|
761 pad[0].r1++;
|
|
762 } else {
|
|
763 pad[0].r1 = 0;
|
|
764 }
|
|
765
|
|
766 if (keys[SDLK_w]) {
|
|
767 pad[0].l1++;
|
|
768 } else {
|
|
769 pad[0].l1 = 0;
|
|
770 }
|
|
771
|
|
772 if (keys[SDLK_q]) {
|
|
773 pad[0].l2++;
|
|
774 } else {
|
|
775 pad[0].l2 = 0;
|
|
776 }
|
|
777
|
|
778 // START ボタンは Return が似合う気がする
|
|
779 //if(keys[SDLK_1])
|
|
780 if (keys[SDLK_RETURN]) {
|
|
781 pad[0].st++;
|
|
782 } else {
|
|
783 pad[0].st = 0;
|
|
784 }
|
|
785
|
|
786 if (keys[SDLK_2]) {
|
|
787 pad[0].se++;
|
|
788 } else {
|
|
789 pad[0].se = 0;
|
|
790 }
|
|
791
|
|
792 if (keys[SDLK_ESCAPE]) {
|
|
793 SDL_Quit();
|
|
794 exit(1);
|
|
795 //pad[0].st = 1;
|
|
796 //pad[0].se = 1;
|
|
797 }
|
|
798
|
|
799 if (keys[SDLK_0]) {
|
|
800 pad[0].quit = 1;
|
|
801 } else {
|
|
802 pad[0].quit = 0;
|
|
803 }
|
|
804 }
|
|
805
|
|
806
|
|
807 /* end */
|