fix change direction into itself #7
This commit is contained in:
parent
1a9a348793
commit
1f4abeaa00
10
src/snake.c
10
src/snake.c
@ -1,6 +1,7 @@
|
|||||||
#include "snake.h"
|
#include "snake.h"
|
||||||
#include "game.h" //for access to global 'game' struct
|
#include "game.h" //for access to global 'game' struct
|
||||||
|
|
||||||
|
bool snakeSetDirectionIsAllowed = true;
|
||||||
|
|
||||||
void snakeInit()
|
void snakeInit()
|
||||||
{
|
{
|
||||||
@ -44,6 +45,8 @@ void snakeGrow()
|
|||||||
void snakeMove()
|
void snakeMove()
|
||||||
{
|
{
|
||||||
int i = game.snake.length - 1; // counter for snake moving
|
int i = game.snake.length - 1; // counter for snake moving
|
||||||
|
|
||||||
|
snakeSetDirectionIsAllowed = true; // direction can be changed now
|
||||||
|
|
||||||
// update head position automatically
|
// update head position automatically
|
||||||
snakeUpdateHeadPos();
|
snakeUpdateHeadPos();
|
||||||
@ -63,6 +66,12 @@ void snakeMove()
|
|||||||
|
|
||||||
void snakeSetDir(snakeDirection_t dir)
|
void snakeSetDir(snakeDirection_t dir)
|
||||||
{
|
{
|
||||||
|
// if direction mustn changed
|
||||||
|
if(!snakeSetDirectionIsAllowed)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// check, if snake should be move in opposite direction -> new direction stays old direction
|
// check, if snake should be move in opposite direction -> new direction stays old direction
|
||||||
switch(dir)
|
switch(dir)
|
||||||
{
|
{
|
||||||
@ -92,6 +101,7 @@ void snakeSetDir(snakeDirection_t dir)
|
|||||||
|
|
||||||
}
|
}
|
||||||
game.snake.direction = dir;
|
game.snake.direction = dir;
|
||||||
|
snakeSetDirectionIsAllowed = false; // direction cannot updated until next snakeMove
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user