snake: better playability

This commit is contained in:
Christian Kroll 2014-05-27 08:27:27 +02:00
parent a722716bb4
commit 24cd3f5d1d
12 changed files with 90 additions and 43 deletions

View File

@ -65,7 +65,8 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5
# ANIMATION_JOERN1 is not set
ANIMATION_SNAKE=y
SNAKE_CYCLE_DELAY=40
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=40
SNAKE_TERMINATION_DELAY=30
SNAKE_MAX_LENGTH=64
SNAKE_MAX_APPLES=10

View File

@ -68,7 +68,8 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5
# ANIMATION_JOERN1 is not set
# ANIMATION_SNAKE is not set
SNAKE_CYCLE_DELAY=100
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=100
SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64
SNAKE_MAX_APPLES=10

View File

@ -63,7 +63,8 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5
ANIMATION_JOERN1=y
ANIMATION_SNAKE=y
SNAKE_CYCLE_DELAY=100
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=100
SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64
SNAKE_MAX_APPLES=10

View File

@ -63,7 +63,8 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5
ANIMATION_JOERN1=y
ANIMATION_SNAKE=y
SNAKE_CYCLE_DELAY=100
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=100
SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64
SNAKE_MAX_APPLES=10

View File

@ -63,7 +63,8 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5
ANIMATION_JOERN1=y
ANIMATION_SNAKE=y
SNAKE_CYCLE_DELAY=100
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=100
SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64
SNAKE_MAX_APPLES=10

View File

@ -85,7 +85,8 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5
ANIMATION_JOERN1=y
ANIMATION_SNAKE=y
SNAKE_CYCLE_DELAY=100
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=100
SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64
SNAKE_MAX_APPLES=10

View File

@ -61,7 +61,8 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=20
ANIMATION_JOERN1=y
ANIMATION_SNAKE=y
SNAKE_CYCLE_DELAY=100
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=100
SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64
SNAKE_MAX_APPLES=10

View File

@ -82,7 +82,8 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5
ANIMATION_JOERN1=y
ANIMATION_SNAKE=y
SNAKE_CYCLE_DELAY=100
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=100
SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64
SNAKE_MAX_APPLES=10

View File

@ -74,7 +74,8 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5
ANIMATION_JOERN1=y
ANIMATION_SNAKE=y
SNAKE_CYCLE_DELAY=50
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=50
SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64
SNAKE_MAX_APPLES=10

View File

@ -78,7 +78,8 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5
ANIMATION_JOERN1=y
ANIMATION_SNAKE=y
SNAKE_CYCLE_DELAY=100
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=100
SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64
SNAKE_MAX_APPLES=10

View File

@ -9,7 +9,8 @@ comment "Animations"
bool "Joern1" ANIMATION_JOERN1
dep_bool_menu "Snake" ANIMATION_SNAKE $RANDOM_SUPPORT
int "Snake Round Delay" SNAKE_CYCLE_DELAY 100
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
int "Snake Max Apples" SNAKE_MAX_APPLES 10

View File

@ -51,9 +51,14 @@ game_descriptor_t snake_game_descriptor __attribute__((section(".game_descriptor
#define SNAKE_MAX_APPLES 10
#endif
#if !defined SNAKE_CYCLE_DELAY || defined DOXYGEN
#if !defined SNAKE_GAME_DELAY || defined DOXYGEN
/** Delay (in ms) between every state change. */
#define SNAKE_CYCLE_DELAY 100
#define SNAKE_GAME_DELAY 200
#endif
#if !defined SNAKE_ANIM_DELAY || defined DOXYGEN
/** Delay (in ms) between every state change. */
#define SNAKE_ANIM_DELAY 100
#endif
#if !defined SNAKE_TERMINATION_DELAY || defined DOXYGEN
@ -192,11 +197,21 @@ static snake_dir_t snake_queryJoystick(void)
*/
static void snake_initGameProtagonist(snake_protagonist_t *pprotSnake)
{
pprotSnake->aSegments[0] = (pixel){NUM_COLS / 2, NUM_ROWS / 2};
pprotSnake->aSegments[1] = (pixel){NUM_COLS / 2, NUM_ROWS / 2 - 1};
#if NUM_ROWS > NUM_COLS
pprotSnake->aSegments[0] =
(pixel){(NUM_COLS - 2) / 2 + 1, (NUM_ROWS - 2) / 2 + 1};
pprotSnake->aSegments[1] =
(pixel){(NUM_COLS - 2) / 2 + 1, (NUM_ROWS - 2) / 2};
pprotSnake->dir = SNAKE_DIR_DOWN;
#else
pprotSnake->aSegments[0] =
(pixel){(NUM_COLS - 2) / 2 + 1, (NUM_ROWS - 2) / 2 + 1};
pprotSnake->aSegments[1] =
(pixel){(NUM_COLS - 2) / 2 + 2, (NUM_ROWS - 2) / 2 + 1};
pprotSnake->dir = SNAKE_DIR_RIGHT;
#endif
pprotSnake->nTailIndex = 0;
pprotSnake->nHeadIndex = 1;
pprotSnake->dir = SNAKE_DIR_UP;
}
#ifdef GAME_SNAKE
@ -403,7 +418,7 @@ void snake_engine(uint8_t bDemoMode)
clear_screen(0);
snake_drawBorder();
for (uint8_t nAppleColor = 0; 1; nAppleColor ^= SNAKE_COLOR_APPLE)
for (uint8_t nTick = 0; 1; nTick ^= SNAKE_COLOR_APPLE)
{
// determine new direction
#if defined ANIMATION_SNAKE && defined GAME_SNAKE
@ -415,10 +430,13 @@ void snake_engine(uint8_t bDemoMode)
{
snake_userControl(&protSnake, &dirLast);
}
if (bDemoMode || nTick) {
#elif defined ANIMATION_SNAKE
snake_autoRoute(&protSnake, &apples);
{
#else
snake_userControl(&protSnake, &dirLast);
if (nTick) {
#endif
// actually move head
@ -449,14 +467,29 @@ void snake_engine(uint8_t bDemoMode)
// draw new head
setpixel(protSnake.aSegments[protSnake.nHeadIndex],
SNAKE_COLOR_PROTAGONIST);
}
// draw apples
for (uint8_t i = apples.nAppleCount; i--;)
{
setpixel(apples.aApples[i], nAppleColor);
// nTick also serves as blinking color
setpixel(apples.aApples[i], nTick);
}
wait(SNAKE_CYCLE_DELAY);
#if defined ANIMATION_SNAKE && defined GAME_SNAKE
if (bDemoMode)
{
wait(SNAKE_ANIM_DELAY);
}
else
{
wait(SNAKE_GAME_DELAY / 2);
}
#elif defined ANIMATION_SNAKE
wait(SNAKE_ANIM_DELAY);
#else
wait(SNAKE_GAME_DELAY / 2);
#endif
}
}
@ -466,6 +499,9 @@ void snake_engine(uint8_t bDemoMode)
void snake_game(void)
{
snake_engine(0);
#if defined GAME_SNAKE && defined SCROLLTEXT_SUPPORT
scrolltext("</#Game Over!");
#endif
}
/*@}*/