Prevent snake from turning around directly.
This commit is contained in:
parent
129c6d5f3b
commit
5090c09123
@ -9,3 +9,7 @@ class SnakeState:
|
|||||||
return SnakeSegment(center=self._get_next_pos(old_head.get_position(), old_head.get_radius()),
|
return SnakeSegment(center=self._get_next_pos(old_head.get_position(), old_head.get_radius()),
|
||||||
radius=old_head.get_radius(),
|
radius=old_head.get_radius(),
|
||||||
color=old_head.get_color())
|
color=old_head.get_color())
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type(self):
|
||||||
|
return self.__class__
|
||||||
@ -16,8 +16,16 @@ class SnakeStateMachine:
|
|||||||
InputManager.RIGHT: SnakeRightMovementState()
|
InputManager.RIGHT: SnakeRightMovementState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.__input_ignore_dict = {
|
||||||
|
SnakeDownMovementState: InputManager.UP,
|
||||||
|
SnakeUpMovementState: InputManager.DOWN,
|
||||||
|
SnakeLeftMovementState: InputManager.RIGHT,
|
||||||
|
SnakeRightMovementState: InputManager.LEFT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def update(self, user_input):
|
def update(self, user_input):
|
||||||
|
if user_input != self.__input_ignore_dict.get(self.__state.type, None):
|
||||||
self.__state = self.__next_state_dict.get(user_input, self.__state)
|
self.__state = self.__next_state_dict.get(user_input, self.__state)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user