Simple plateformer game playing
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
Represents the current state of the game.
|
||||
Contains :
|
||||
- Player score
|
||||
- stopGame flag
|
||||
- Player position
|
||||
"""
|
||||
class GameState:
|
||||
PLAYER_MOVEMENTS = ["left_down", "left", "left_up", "up", "right_up", "right", "right_down"]
|
||||
PLAYER_VELOCITIES = [*PLAYER_MOVEMENTS, "down"]
|
||||
|
||||
def __init__(self):
|
||||
self.score = 0
|
||||
self.playerPosition = (0, 0)
|
||||
self.stopGame = False
|
||||
self.movesCount = 0
|
||||
self.playerVelocity = -1 # -1 means no velocity
|
||||
self.gameWon = False
|
||||
|
||||
def add_score(self, points):
|
||||
self.score += points
|
||||
|
||||
def set_player_position(self, x, y):
|
||||
self.playerPosition = (x, y)
|
||||
|
||||
def set_player_position(self, position: tuple):
|
||||
self.playerPosition = position
|
||||
|
||||
def get_player_position(self):
|
||||
return self.playerPosition
|
||||
|
||||
def set_player_velocity(self, velocity):
|
||||
"""Set the player velocity, meaning where the player is currently going
|
||||
"""
|
||||
if velocity not in self.PLAYER_VELOCITIES and velocity != -1:
|
||||
raise ValueError(f"Invalid player velocity: {velocity}. Must be one of {self.PLAYER_VELOCITIES} or -1.")
|
||||
self.playerVelocity = velocity
|
||||
|
||||
def add_move_count(self, nb=1):
|
||||
self.movesCount += nb
|
||||
|
||||
def set_stop_game(self, stop):
|
||||
self.stopGame = stop
|
||||
|
||||
def set_game_won(self, won):
|
||||
self.gameWon = won
|
||||
Reference in New Issue
Block a user