X-Git-Url: http://git.purplebirdman.com/lightcycles.git/blobdiff_plain/324144cac84227aecd582e51288173e7fa0b9bda..caf59faf462f0ef16a3a2474040f4c577b941222:/player/player.gd diff --git a/player/player.gd b/player/player.gd index 27754a4..c71d952 100644 --- a/player/player.gd +++ b/player/player.gd @@ -1,22 +1,53 @@ +class_name Player extends CharacterBody3D -@export_category("Movement") + +signal playerTurn +signal playerDestroyed +signal playerRestart + + +@onready var _skin = $skin + + +@export_category("Movement") @export var speed = 5.0 @export_category("Camera") @export var distance = 3.0 + @onready var _springArm = $SpringArm3D -@onready var _skin = %skin +enum state {ALIVE, DEAD} +var _state = state.ALIVE + +func _ready() -> void: + _springArm.spring_length = distance func _input(event: InputEvent) -> void: - if event.is_action_pressed("player_left"): - global_rotate(Vector3.UP, PI/2) - elif event.is_action_pressed("player_right"): - global_rotate(Vector3.UP, -PI/2) - -func _physics_process(delta: float) -> void: - velocity = global_transform.basis.z * speed - move_and_slide() + if _state == state.ALIVE: + if event.is_action_pressed("player_left"): + global_rotate(Vector3.UP, PI/2) + playerTurn.emit(self) + elif event.is_action_pressed("player_right"): + global_rotate(Vector3.UP, -PI/2) + playerTurn.emit(self) + else: + if event.is_action_pressed("player_restart"): + playerRestart.emit(self) + + +func _physics_process(_delta: float) -> void: + if _state == state.ALIVE: + velocity = global_transform.basis.z * speed + move_and_slide() + if velocity.length() == 0: + _explode() + + +func _explode() -> void: + _skin.visible = false + _state = state.DEAD + playerDestroyed.emit(self)