Added player character and initial interaction functionality
This commit is contained in:
27
scripts/player.gd
Normal file
27
scripts/player.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
extends CharacterBody2D
|
||||
class_name Player
|
||||
|
||||
@export var SPEED := 4
|
||||
|
||||
var last_direction = 0
|
||||
var interaction_location: Vector2i
|
||||
|
||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var input_direction := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
||||
velocity = input_direction * SPEED / delta
|
||||
move_and_slide()
|
||||
|
||||
if input_direction:
|
||||
animation_player.play()
|
||||
last_direction = input_direction.angle() + 3 * PI / 2
|
||||
rotation = last_direction
|
||||
interaction_location = Grid.world_to_grid(position) + Vector2i(input_direction.round())
|
||||
Grid.set_selected_tile(interaction_location)
|
||||
else:
|
||||
animation_player.stop()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_accept"):
|
||||
print("Interacted with: %s" % Grid.get_location_data(interaction_location))
|
||||
Reference in New Issue
Block a user