Browse Source

provide Snake POV control option in Menuconfig

feature/2015
Christian Kroll 10 years ago
parent
commit
5ca1b807f4
  1. 1
      src/animations/config.in
  2. 8
      src/games/config.in
  3. 36
      src/games/snake/snake_game.c

1
src/animations/config.in

@ -9,7 +9,6 @@ comment "Animations"
bool "Joern1" ANIMATION_JOERN1 bool "Joern1" ANIMATION_JOERN1
dep_bool_menu "Snake" ANIMATION_SNAKE $RANDOM_SUPPORT dep_bool_menu "Snake" ANIMATION_SNAKE $RANDOM_SUPPORT
int "Snake Game Round Delay" SNAKE_GAME_DELAY 200
int "Snake Anim Round Delay" SNAKE_ANIM_DELAY 100 int "Snake Anim Round Delay" SNAKE_ANIM_DELAY 100
int "Snake Termination Delay" SNAKE_TERMINATION_DELAY 60 int "Snake Termination Delay" SNAKE_TERMINATION_DELAY 60
uint "Snake Max Length" SNAKE_MAX_LENGTH 64 uint "Snake Max Length" SNAKE_MAX_LENGTH 64

8
src/games/config.in

@ -7,7 +7,13 @@ comment "Games"
endmenu endmenu
dep_bool "Space Invaders" GAME_SPACE_INVADERS $JOYSTICK_SUPPORT $RANDOM_SUPPORT dep_bool "Space Invaders" GAME_SPACE_INVADERS $JOYSTICK_SUPPORT $RANDOM_SUPPORT
dep_bool "Snake" GAME_SNAKE $JOYSTICK_SUPPORT $RANDOM_SUPPORT
dep_bool_menu "Snake" GAME_SNAKE y $JOYSTICK_SUPPORT $RANDOM_SUPPORT
bool "POV Controls" SNAKE_POV_CONTROL n
int "Snake Game Round Delay" SNAKE_GAME_DELAY 200
endmenu
dep_bool "Breakout" GAME_BREAKOUT $JOYSTICK_SUPPORT $RANDOM_SUPPORT dep_bool "Breakout" GAME_BREAKOUT $JOYSTICK_SUPPORT $RANDOM_SUPPORT
dep_bool "Kart" GAME_KART $JOYSTICK_SUPPORT $RANDOM_SUPPORT dep_bool "Kart" GAME_KART $JOYSTICK_SUPPORT $RANDOM_SUPPORT
endmenu endmenu

36
src/games/snake/snake_game.c

@ -37,11 +37,13 @@ game_descriptor_t snake_game_descriptor __attribute__((section(".game_descriptor
#endif #endif
#ifdef DOXYGEN
/** /**
* If defined, joystick controls are NOT as "seen" by the snake but absolute, * If defined, joystick controls are bound to the point of view of the
* that is, if pressing up, snake goes up, etc. * snake, i.e. only the left an right joystick direction can be used.
*/ */
#define SNAKE_NEWCONTROL #define SNAKE_POV_CONTROL
#endif
#if !defined USNAKE_MAX_LENGTH || defined DOXYGEN #if !defined USNAKE_MAX_LENGTH || defined DOXYGEN
/** The maximum length of the snake. */ /** The maximum length of the snake. */
@ -229,34 +231,36 @@ static void snake_userControl(snake_protagonist_t *pprotSnake,
snake_dir_t *pdirLast) snake_dir_t *pdirLast)
{ {
snake_dir_t dirJoystick = snake_queryJoystick(); snake_dir_t dirJoystick = snake_queryJoystick();
#ifdef SNAKE_NEWCONTROL # ifdef SNAKE_POV_CONTROL
if (dirJoystick != SNAKE_DIR_NONE)
if ((dirJoystick ^ *pdirLast) && (dirJoystick != SNAKE_DIR_NONE) &&
(!pprotSnake->bJoystickLocked))
{ {
// valid transitions can only be uneven // only left or right movements are valid
if (((pprotSnake->dir + dirJoystick) & 0x01) && if (dirJoystick & 0x01)
!pprotSnake->bJoystickLocked)
{ {
pprotSnake->dir = dirJoystick; // rotate through directions (either clockwise or counterclockwise)
pprotSnake->dir = (pprotSnake->dir +
(dirJoystick == SNAKE_DIR_LEFT ? 3 : 1)) % 4u;
} }
// we query the joystick twice as fast as we move the snake, so we // we query the joystick twice as fast as we move the snake, so we
// have to ensure that it does not bite its head with its head...uh // have to ensure that it does not bite its head with its head...uh
pprotSnake->bJoystickLocked = true; pprotSnake->bJoystickLocked = true;
} }
*pdirLast = dirJoystick;
# else # else
if ((dirJoystick ^ *pdirLast) && (dirJoystick != SNAKE_DIR_NONE)) if (dirJoystick != SNAKE_DIR_NONE)
{ {
// only left or right movements are valid // valid transitions can only be uneven
if (dirJoystick & 0x01) if (((pprotSnake->dir + dirJoystick) & 0x01) &&
!pprotSnake->bJoystickLocked)
{ {
// rotate through directions (either clockwise or counterclockwise) pprotSnake->dir = dirJoystick;
pprotSnake->dir = (pprotSnake->dir +
(dirJoystick == SNAKE_DIR_LEFT ? 3 : 1)) % 4u;
} }
// we query the joystick twice as fast as we move the snake, so we // we query the joystick twice as fast as we move the snake, so we
// have to ensure that it does not bite its head with its head...uh // have to ensure that it does not bite its head with its head...uh
pprotSnake->bJoystickLocked = true; pprotSnake->bJoystickLocked = true;
} }
*pdirLast = dirJoystick;
# endif # endif
} }
#endif #endif

Loading…
Cancel
Save