41 lines
1004 B
GDScript
41 lines
1004 B
GDScript
class_name MazePlayer
|
|
extends Reference
|
|
|
|
# Player in maze coordinates
|
|
var position = Vector2.ZERO
|
|
var forward_dir = Direction.NORTH
|
|
var nb_steps = 0
|
|
var nb_chests_found = 0
|
|
|
|
func teleport_at(pos: Vector2):
|
|
position = pos
|
|
|
|
func turn_at(dir):
|
|
forward_dir = dir
|
|
|
|
func move_forward():
|
|
position += Direction.offset(forward_dir)
|
|
nb_steps += 1
|
|
|
|
func move_backward():
|
|
position += Direction.offset(Direction.opposite(forward_dir))
|
|
nb_steps += 1
|
|
|
|
func turn_left():
|
|
forward_dir = Direction.rotate_left(forward_dir)
|
|
|
|
func turn_right():
|
|
forward_dir = Direction.rotate_right(forward_dir)
|
|
|
|
# Check if a player can move forward
|
|
func can_move_forward(level: Maze):
|
|
return level.at(position.x, position.y).get_edge(forward_dir) != Cell.Edge.WALL
|
|
|
|
# Check if a player can move backward
|
|
func can_move_backward(level: Maze):
|
|
return level.at(position.x, position.y).get_edge(Direction.opposite(forward_dir)) != Cell.Edge.WALL
|
|
|
|
# Find a chest
|
|
func open_chest():
|
|
nb_chests_found += 1
|