- PS3 SIXAXIS controller now works

- cannon now doens't affect caught monsters
This commit is contained in:
Rob Pearce 2008-10-16 05:37:57 +00:00
parent 6c7a61134e
commit d1dd171d43
2 changed files with 42 additions and 23 deletions

2
defs.h
View File

@ -173,6 +173,8 @@
#define MAXCARDS 5 // how many cards a player can have
#define MAXJOYBUTTONS 20
// Fixed text buffer sizes
#define BUFLEN 512
#define MIDBUFLEN 64

63
rc.c
View File

@ -26,7 +26,7 @@ TTF_Font *font[MAXLETTERHEIGHT];
SDL_Joystick *joy;
Uint8 *keys;
int joyx,joyy,joybut[2];
int joyx,joyy,joybut[MAXJOYBUTTONS];
Mix_Music *curmusic = NULL; // pointer to currently playing music
@ -5562,7 +5562,7 @@ void initsdl(void) {
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
joy = SDL_JoystickOpen(0);
if (joy) {
printf("Joystick detected and enabled.\n");
printf("%d joystick(s) detected and enabled.\n",SDL_NumJoysticks());
SDL_JoystickEventState(SDL_ENABLE);
} else {
printf("No joysticks found.\n");
@ -6305,7 +6305,7 @@ void handleinput(void) {
if (joy) {
joyx = SDL_JoystickGetAxis(joy,0);
joyy = SDL_JoystickGetAxis(joy,1);
for (i = 0; i < 2; i++) {
for (i = 0; i < MAXJOYBUTTONS; i++) {
joybut[i] = SDL_JoystickGetButton(joy,i);
}
}
@ -6634,18 +6634,19 @@ int keydown(int checkfor) {
return B_TRUE;
}
// check for joystick
if ((checkfor == SDLK_RIGHT) && (joyx >= 6000)) {
return B_TRUE;
} else if ((checkfor == SDLK_LEFT) && (joyx <= -6000)) {
return B_TRUE;
} else if ((checkfor == SDLK_UP) && (joyy <= -6000)) {
return B_TRUE;
} else if ((checkfor == SDLK_DOWN) && (joyy >= 6000)) {
return B_TRUE;
} else if ((checkfor == SDLK_z) && (joybut[0])) {
return B_TRUE;
} else if ((checkfor == SDLK_x) && (joybut[1])) {
return B_TRUE;
if (checkfor == SDLK_RIGHT) {
//if ((joyx >= 6000) || (joybut[5])) return B_TRUE;
if (joybut[5]) return B_TRUE;
} else if (checkfor == SDLK_LEFT) {
if (joybut[7]) return B_TRUE;
} else if (checkfor == SDLK_UP) {
if (joybut[4]) return B_TRUE;
} else if (checkfor == SDLK_DOWN) {
if (joybut[6]) return B_TRUE;
} else if (checkfor == SDLK_z) {
if (joybut[0] || joybut[14]) return B_TRUE;
} else if (checkfor == SDLK_x) {
if (joybut[1] || joybut[13]) return B_TRUE;
}
return B_FALSE;
@ -6690,10 +6691,12 @@ void docannoneffect(void) {
drawline16(screen,0,yy,640,yy,white);
for (s3 = sprite; s3 ; s3 = s3->next) {
if (ismonster(s3->id) && !s3->dead) {
if ((yy >= s3->y - s3->img->h) && (yy <= s3->y)) {
s3->willbecome = P_DIAMOND;
if (s3->id == P_SNAIL) s3->id = P_SLUG;
die(s3);
if (!s3->caughtby) {
if ((yy >= s3->y - s3->img->h) && (yy <= s3->y)) {
s3->willbecome = P_DIAMOND;
if (s3->id == P_SNAIL) s3->id = P_SLUG;
die(s3);
}
}
}
}
@ -6704,10 +6707,12 @@ void docannoneffect(void) {
drawline16(screen,xx,0,xx,480,white);
for (s3 = sprite; s3 ; s3 = s3->next) {
if (ismonster(s3->id) && !s3->dead) {
if ((xx >= s3->x - (s3->img->w/2)) && (xx <= s3->x + (s3->img->w/2))) {
s3->willbecome = P_DIAMOND;
if (s3->id == P_SNAIL) s3->id = P_SLUG;
die(s3);
if (!s3->caughtby) {
if ((xx >= s3->x - (s3->img->w/2)) && (xx <= s3->x + (s3->img->w/2))) {
s3->willbecome = P_DIAMOND;
if (s3->id == P_SNAIL) s3->id = P_SLUG;
die(s3);
}
}
}
}
@ -6732,6 +6737,7 @@ void dotitlescreen(void) {
SDL_Event event;
int done;
int timer = 0;
int i;
int texton = B_TRUE;
@ -6753,6 +6759,17 @@ void dotitlescreen(void) {
while (!done) {
SDL_PollEvent(&event);
switch (event.type) {
case SDL_JOYAXISMOTION:
joyx = SDL_JoystickGetAxis(joy,0);
joyy = SDL_JoystickGetAxis(joy,1);
for (i = 0; i < 20; i++) {
joybut[i] = SDL_JoystickGetButton(joy,i);
if (joybut[i]) printf("button %d down\n",i);
}
//printf("joystick coords are: %d,%d button0=%d, button1=%d\n",joyx,joyy,joybut[0],joybut[1]);
break;
case SDL_KEYDOWN:
keys = SDL_GetKeyState(NULL);
if (keys[SDLK_ESCAPE]) {