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