provide Snake POV control option in Menuconfig

This commit is contained in:
Christian Kroll 2014-09-08 00:35:12 +02:00
parent bf6b2d95dd
commit 5ca1b807f4
3 changed files with 32 additions and 23 deletions

View File

@ -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

View File

@ -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

View File

@ -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,21 +231,10 @@ 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) &&
// valid transitions can only be uneven (!pprotSnake->bJoystickLocked))
if (((pprotSnake->dir + dirJoystick) & 0x01) &&
!pprotSnake->bJoystickLocked)
{
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;
}
#else
if ((dirJoystick ^ *pdirLast) && (dirJoystick != SNAKE_DIR_NONE))
{ {
// only left or right movements are valid // only left or right movements are valid
if (dirJoystick & 0x01) if (dirJoystick & 0x01)
@ -257,6 +248,19 @@ static void snake_userControl(snake_protagonist_t *pprotSnake,
pprotSnake->bJoystickLocked = true; pprotSnake->bJoystickLocked = true;
} }
*pdirLast = dirJoystick; *pdirLast = dirJoystick;
# else
if (dirJoystick != SNAKE_DIR_NONE)
{
// valid transitions can only be uneven
if (((pprotSnake->dir + dirJoystick) & 0x01) &&
!pprotSnake->bJoystickLocked)
{
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;
}
# endif # endif
} }
#endif #endif