snake: better playability
This commit is contained in:
parent
a722716bb4
commit
24cd3f5d1d
|
@ -65,7 +65,8 @@ ANIMATION_SPIRAL=y
|
||||||
SPIRAL_DELAY=5
|
SPIRAL_DELAY=5
|
||||||
# ANIMATION_JOERN1 is not set
|
# ANIMATION_JOERN1 is not set
|
||||||
ANIMATION_SNAKE=y
|
ANIMATION_SNAKE=y
|
||||||
SNAKE_CYCLE_DELAY=40
|
SNAKE_GAME_DELAY=200
|
||||||
|
SNAKE_ANIM_DELAY=40
|
||||||
SNAKE_TERMINATION_DELAY=30
|
SNAKE_TERMINATION_DELAY=30
|
||||||
SNAKE_MAX_LENGTH=64
|
SNAKE_MAX_LENGTH=64
|
||||||
SNAKE_MAX_APPLES=10
|
SNAKE_MAX_APPLES=10
|
||||||
|
|
|
@ -68,7 +68,8 @@ ANIMATION_SPIRAL=y
|
||||||
SPIRAL_DELAY=5
|
SPIRAL_DELAY=5
|
||||||
# ANIMATION_JOERN1 is not set
|
# ANIMATION_JOERN1 is not set
|
||||||
# ANIMATION_SNAKE 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_TERMINATION_DELAY=60
|
||||||
SNAKE_MAX_LENGTH=64
|
SNAKE_MAX_LENGTH=64
|
||||||
SNAKE_MAX_APPLES=10
|
SNAKE_MAX_APPLES=10
|
||||||
|
|
|
@ -63,7 +63,8 @@ ANIMATION_SPIRAL=y
|
||||||
SPIRAL_DELAY=5
|
SPIRAL_DELAY=5
|
||||||
ANIMATION_JOERN1=y
|
ANIMATION_JOERN1=y
|
||||||
ANIMATION_SNAKE=y
|
ANIMATION_SNAKE=y
|
||||||
SNAKE_CYCLE_DELAY=100
|
SNAKE_GAME_DELAY=200
|
||||||
|
SNAKE_ANIM_DELAY=100
|
||||||
SNAKE_TERMINATION_DELAY=60
|
SNAKE_TERMINATION_DELAY=60
|
||||||
SNAKE_MAX_LENGTH=64
|
SNAKE_MAX_LENGTH=64
|
||||||
SNAKE_MAX_APPLES=10
|
SNAKE_MAX_APPLES=10
|
||||||
|
|
|
@ -63,7 +63,8 @@ ANIMATION_SPIRAL=y
|
||||||
SPIRAL_DELAY=5
|
SPIRAL_DELAY=5
|
||||||
ANIMATION_JOERN1=y
|
ANIMATION_JOERN1=y
|
||||||
ANIMATION_SNAKE=y
|
ANIMATION_SNAKE=y
|
||||||
SNAKE_CYCLE_DELAY=100
|
SNAKE_GAME_DELAY=200
|
||||||
|
SNAKE_ANIM_DELAY=100
|
||||||
SNAKE_TERMINATION_DELAY=60
|
SNAKE_TERMINATION_DELAY=60
|
||||||
SNAKE_MAX_LENGTH=64
|
SNAKE_MAX_LENGTH=64
|
||||||
SNAKE_MAX_APPLES=10
|
SNAKE_MAX_APPLES=10
|
||||||
|
|
|
@ -63,7 +63,8 @@ ANIMATION_SPIRAL=y
|
||||||
SPIRAL_DELAY=5
|
SPIRAL_DELAY=5
|
||||||
ANIMATION_JOERN1=y
|
ANIMATION_JOERN1=y
|
||||||
ANIMATION_SNAKE=y
|
ANIMATION_SNAKE=y
|
||||||
SNAKE_CYCLE_DELAY=100
|
SNAKE_GAME_DELAY=200
|
||||||
|
SNAKE_ANIM_DELAY=100
|
||||||
SNAKE_TERMINATION_DELAY=60
|
SNAKE_TERMINATION_DELAY=60
|
||||||
SNAKE_MAX_LENGTH=64
|
SNAKE_MAX_LENGTH=64
|
||||||
SNAKE_MAX_APPLES=10
|
SNAKE_MAX_APPLES=10
|
||||||
|
|
|
@ -85,7 +85,8 @@ ANIMATION_SPIRAL=y
|
||||||
SPIRAL_DELAY=5
|
SPIRAL_DELAY=5
|
||||||
ANIMATION_JOERN1=y
|
ANIMATION_JOERN1=y
|
||||||
ANIMATION_SNAKE=y
|
ANIMATION_SNAKE=y
|
||||||
SNAKE_CYCLE_DELAY=100
|
SNAKE_GAME_DELAY=200
|
||||||
|
SNAKE_ANIM_DELAY=100
|
||||||
SNAKE_TERMINATION_DELAY=60
|
SNAKE_TERMINATION_DELAY=60
|
||||||
SNAKE_MAX_LENGTH=64
|
SNAKE_MAX_LENGTH=64
|
||||||
SNAKE_MAX_APPLES=10
|
SNAKE_MAX_APPLES=10
|
||||||
|
|
|
@ -61,7 +61,8 @@ ANIMATION_SPIRAL=y
|
||||||
SPIRAL_DELAY=20
|
SPIRAL_DELAY=20
|
||||||
ANIMATION_JOERN1=y
|
ANIMATION_JOERN1=y
|
||||||
ANIMATION_SNAKE=y
|
ANIMATION_SNAKE=y
|
||||||
SNAKE_CYCLE_DELAY=100
|
SNAKE_GAME_DELAY=200
|
||||||
|
SNAKE_ANIM_DELAY=100
|
||||||
SNAKE_TERMINATION_DELAY=60
|
SNAKE_TERMINATION_DELAY=60
|
||||||
SNAKE_MAX_LENGTH=64
|
SNAKE_MAX_LENGTH=64
|
||||||
SNAKE_MAX_APPLES=10
|
SNAKE_MAX_APPLES=10
|
||||||
|
|
|
@ -82,7 +82,8 @@ ANIMATION_SPIRAL=y
|
||||||
SPIRAL_DELAY=5
|
SPIRAL_DELAY=5
|
||||||
ANIMATION_JOERN1=y
|
ANIMATION_JOERN1=y
|
||||||
ANIMATION_SNAKE=y
|
ANIMATION_SNAKE=y
|
||||||
SNAKE_CYCLE_DELAY=100
|
SNAKE_GAME_DELAY=200
|
||||||
|
SNAKE_ANIM_DELAY=100
|
||||||
SNAKE_TERMINATION_DELAY=60
|
SNAKE_TERMINATION_DELAY=60
|
||||||
SNAKE_MAX_LENGTH=64
|
SNAKE_MAX_LENGTH=64
|
||||||
SNAKE_MAX_APPLES=10
|
SNAKE_MAX_APPLES=10
|
||||||
|
|
|
@ -74,7 +74,8 @@ ANIMATION_SPIRAL=y
|
||||||
SPIRAL_DELAY=5
|
SPIRAL_DELAY=5
|
||||||
ANIMATION_JOERN1=y
|
ANIMATION_JOERN1=y
|
||||||
ANIMATION_SNAKE=y
|
ANIMATION_SNAKE=y
|
||||||
SNAKE_CYCLE_DELAY=50
|
SNAKE_GAME_DELAY=200
|
||||||
|
SNAKE_ANIM_DELAY=50
|
||||||
SNAKE_TERMINATION_DELAY=60
|
SNAKE_TERMINATION_DELAY=60
|
||||||
SNAKE_MAX_LENGTH=64
|
SNAKE_MAX_LENGTH=64
|
||||||
SNAKE_MAX_APPLES=10
|
SNAKE_MAX_APPLES=10
|
||||||
|
|
|
@ -78,7 +78,8 @@ ANIMATION_SPIRAL=y
|
||||||
SPIRAL_DELAY=5
|
SPIRAL_DELAY=5
|
||||||
ANIMATION_JOERN1=y
|
ANIMATION_JOERN1=y
|
||||||
ANIMATION_SNAKE=y
|
ANIMATION_SNAKE=y
|
||||||
SNAKE_CYCLE_DELAY=100
|
SNAKE_GAME_DELAY=200
|
||||||
|
SNAKE_ANIM_DELAY=100
|
||||||
SNAKE_TERMINATION_DELAY=60
|
SNAKE_TERMINATION_DELAY=60
|
||||||
SNAKE_MAX_LENGTH=64
|
SNAKE_MAX_LENGTH=64
|
||||||
SNAKE_MAX_APPLES=10
|
SNAKE_MAX_APPLES=10
|
||||||
|
|
|
@ -9,7 +9,8 @@ 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 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
|
int "Snake Termination Delay" SNAKE_TERMINATION_DELAY 60
|
||||||
uint "Snake Max Length" SNAKE_MAX_LENGTH 64
|
uint "Snake Max Length" SNAKE_MAX_LENGTH 64
|
||||||
int "Snake Max Apples" SNAKE_MAX_APPLES 10
|
int "Snake Max Apples" SNAKE_MAX_APPLES 10
|
||||||
|
|
|
@ -51,9 +51,14 @@ game_descriptor_t snake_game_descriptor __attribute__((section(".game_descriptor
|
||||||
#define SNAKE_MAX_APPLES 10
|
#define SNAKE_MAX_APPLES 10
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined SNAKE_CYCLE_DELAY || defined DOXYGEN
|
#if !defined SNAKE_GAME_DELAY || defined DOXYGEN
|
||||||
/** Delay (in ms) between every state change. */
|
/** 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
|
#endif
|
||||||
|
|
||||||
#if !defined SNAKE_TERMINATION_DELAY || defined DOXYGEN
|
#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)
|
static void snake_initGameProtagonist(snake_protagonist_t *pprotSnake)
|
||||||
{
|
{
|
||||||
pprotSnake->aSegments[0] = (pixel){NUM_COLS / 2, NUM_ROWS / 2};
|
#if NUM_ROWS > NUM_COLS
|
||||||
pprotSnake->aSegments[1] = (pixel){NUM_COLS / 2, NUM_ROWS / 2 - 1};
|
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->nTailIndex = 0;
|
||||||
pprotSnake->nHeadIndex = 1;
|
pprotSnake->nHeadIndex = 1;
|
||||||
pprotSnake->dir = SNAKE_DIR_UP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GAME_SNAKE
|
#ifdef GAME_SNAKE
|
||||||
|
@ -403,7 +418,7 @@ void snake_engine(uint8_t bDemoMode)
|
||||||
clear_screen(0);
|
clear_screen(0);
|
||||||
snake_drawBorder();
|
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
|
// determine new direction
|
||||||
#if defined ANIMATION_SNAKE && defined GAME_SNAKE
|
#if defined ANIMATION_SNAKE && defined GAME_SNAKE
|
||||||
|
@ -415,48 +430,66 @@ void snake_engine(uint8_t bDemoMode)
|
||||||
{
|
{
|
||||||
snake_userControl(&protSnake, &dirLast);
|
snake_userControl(&protSnake, &dirLast);
|
||||||
}
|
}
|
||||||
|
if (bDemoMode || nTick) {
|
||||||
#elif defined ANIMATION_SNAKE
|
#elif defined ANIMATION_SNAKE
|
||||||
snake_autoRoute(&protSnake, &apples);
|
snake_autoRoute(&protSnake, &apples);
|
||||||
|
{
|
||||||
#else
|
#else
|
||||||
snake_userControl(&protSnake, &dirLast);
|
snake_userControl(&protSnake, &dirLast);
|
||||||
|
if (nTick) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// actually move head
|
// actually move head
|
||||||
pixel pxOldHead = protSnake.aSegments[protSnake.nHeadIndex];
|
pixel pxOldHead = protSnake.aSegments[protSnake.nHeadIndex];
|
||||||
protSnake.nHeadIndex = (protSnake.nHeadIndex + 1u) % USNAKE_MAX_LENGTH;
|
protSnake.nHeadIndex = (protSnake.nHeadIndex + 1u) % USNAKE_MAX_LENGTH;
|
||||||
protSnake.aSegments[protSnake.nHeadIndex] =
|
protSnake.aSegments[protSnake.nHeadIndex] =
|
||||||
snake_nextDirection(pxOldHead, protSnake.dir);
|
snake_nextDirection(pxOldHead, protSnake.dir);
|
||||||
|
|
||||||
// look if we have found an apple
|
// look if we have found an apple
|
||||||
if (!snake_checkForApple(&apples,
|
if (!snake_checkForApple(&apples,
|
||||||
protSnake.aSegments[protSnake.nHeadIndex]))
|
protSnake.aSegments[protSnake.nHeadIndex]))
|
||||||
{
|
|
||||||
// quit game if we hit something which is not an apple
|
|
||||||
if (get_pixel(protSnake.aSegments[protSnake.nHeadIndex]))
|
|
||||||
{
|
{
|
||||||
snake_eliminateProtagonist(&protSnake);
|
// quit game if we hit something which is not an apple
|
||||||
return;
|
if (get_pixel(protSnake.aSegments[protSnake.nHeadIndex]))
|
||||||
|
{
|
||||||
|
snake_eliminateProtagonist(&protSnake);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove last segment
|
||||||
|
clearpixel(protSnake.aSegments[protSnake.nTailIndex])
|
||||||
|
protSnake.nTailIndex =
|
||||||
|
(protSnake.nTailIndex + 1u) % USNAKE_MAX_LENGTH;
|
||||||
|
|
||||||
|
// new apples
|
||||||
|
snake_spawnApples(&apples);
|
||||||
}
|
}
|
||||||
|
// draw new head
|
||||||
// remove last segment
|
setpixel(protSnake.aSegments[protSnake.nHeadIndex],
|
||||||
clearpixel(protSnake.aSegments[protSnake.nTailIndex])
|
SNAKE_COLOR_PROTAGONIST);
|
||||||
protSnake.nTailIndex =
|
|
||||||
(protSnake.nTailIndex + 1u) % USNAKE_MAX_LENGTH;
|
|
||||||
|
|
||||||
// new apples
|
|
||||||
snake_spawnApples(&apples);
|
|
||||||
}
|
}
|
||||||
// draw new head
|
|
||||||
setpixel(protSnake.aSegments[protSnake.nHeadIndex],
|
|
||||||
SNAKE_COLOR_PROTAGONIST);
|
|
||||||
|
|
||||||
// draw apples
|
// draw apples
|
||||||
for (uint8_t i = apples.nAppleCount; i--;)
|
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)
|
void snake_game(void)
|
||||||
{
|
{
|
||||||
snake_engine(0);
|
snake_engine(0);
|
||||||
|
#if defined GAME_SNAKE && defined SCROLLTEXT_SUPPORT
|
||||||
|
scrolltext("</#Game Over!");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
Loading…
Reference in New Issue