Allow snake to have more intuitive joystick control.

This commit is contained in:
kju 2010-01-12 21:32:25 +00:00
parent c1295224ee
commit a130f2b36b
1 changed files with 19 additions and 1 deletions

View File

@ -7,6 +7,11 @@
#include "../../util.h" #include "../../util.h"
#include "../../joystick/joystick.h" #include "../../joystick/joystick.h"
// if defined, joystick controls are NOT as "seen"
// by the snake but absolute, that is, if pressing
// up, snake goes up, etc.
#define GAME_SNAKE_NEWCONTROL
// MSB is leftmost pixel // MSB is leftmost pixel
static uint8_t icon[8] PROGMEM = static uint8_t icon[8] PROGMEM =
{0xff, 0x81, 0xbd, 0xa5, 0xa5, 0xad, 0xa1, 0xbf}; // Snake icon {0xff, 0x81, 0xbd, 0xa5, 0xa5, 0xad, 0xa1, 0xbf}; // Snake icon
@ -54,6 +59,12 @@ void snake_game() {
if (head == pixels + 64) if (head == pixels + 64)
head = pixels; head = pixels;
#ifdef GAME_SNAKE_NEWCONTROL
if (joy_cmd != 0xff)
{
dir = joy_cmd;
}
#else
if (joy_cmd == right) { if (joy_cmd == right) {
dir = direction_r(dir); dir = direction_r(dir);
joy_cmd = 0xff; joy_cmd = 0xff;
@ -63,6 +74,7 @@ void snake_game() {
dir = direction_r(dir); dir = direction_r(dir);
joy_cmd = 0xff; joy_cmd = 0xff;
} }
#endif
// kopf einen weiter bewegen // kopf einen weiter bewegen
*head = next_pixel(old_head, dir); *head = next_pixel(old_head, dir);
@ -125,6 +137,12 @@ void snake_game() {
joy = left; joy = left;
}else if(JOYISRIGHT){ }else if(JOYISRIGHT){
joy = right; joy = right;
#ifdef GAME_SNAKE_NEWCONTROL
}else if(JOYISUP) {
joy = up;
} else if(JOYISDOWN) {
joy = down;
#endif
}else{ }else{
joy = 0xff; joy = 0xff;
} }