From 5ca1b807f42832f74aa2af28d595efbb4edb2225 Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Mon, 8 Sep 2014 00:35:12 +0200 Subject: [PATCH] provide Snake POV control option in Menuconfig --- src/animations/config.in | 1 - src/games/config.in | 8 ++++++- src/games/snake/snake_game.c | 46 ++++++++++++++++++++---------------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/animations/config.in b/src/animations/config.in index f41c9f3..45c8879 100644 --- a/src/animations/config.in +++ b/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 diff --git a/src/games/config.in b/src/games/config.in index 1612865..495d345 100644 --- a/src/games/config.in +++ b/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 diff --git a/src/games/snake/snake_game.c b/src/games/snake/snake_game.c index 7c7080a..2f40c65 100644 --- a/src/games/snake/snake_game.c +++ b/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. - */ -#define SNAKE_NEWCONTROL +#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_POV_CONTROL +#endif #if !defined USNAKE_MAX_LENGTH || defined DOXYGEN /** 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 dirJoystick = snake_queryJoystick(); -#ifdef SNAKE_NEWCONTROL - 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; - } -#else - if ((dirJoystick ^ *pdirLast) && (dirJoystick != SNAKE_DIR_NONE)) +# ifdef SNAKE_POV_CONTROL + + if ((dirJoystick ^ *pdirLast) && (dirJoystick != SNAKE_DIR_NONE) && + (!pprotSnake->bJoystickLocked)) { // only left or right movements are valid if (dirJoystick & 0x01) @@ -257,7 +248,20 @@ static void snake_userControl(snake_protagonist_t *pprotSnake, pprotSnake->bJoystickLocked = true; } *pdirLast = dirJoystick; -#endif +# 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