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