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. 42
      src/games/snake/snake_game.c

1
src/animations/config.in

@ -9,7 +9,6 @@ comment "Animations"
bool "Joern1" ANIMATION_JOERN1
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 Termination Delay" SNAKE_TERMINATION_DELAY 60
uint "Snake Max Length" SNAKE_MAX_LENGTH 64

8
src/games/config.in

@ -7,7 +7,13 @@ comment "Games"
endmenu
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 "Kart" GAME_KART $JOYSTICK_SUPPORT $RANDOM_SUPPORT
endmenu

42
src/games/snake/snake_game.c

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

Loading…
Cancel
Save