X-Git-Url: http://git.purplebirdman.com/lightcycles.git/blobdiff_plain/010b3d611cf1bfc9b1b0e715206b484844d5ad65..caf59faf462f0ef16a3a2474040f4c577b941222:/player/player.gd diff --git a/player/player.gd b/player/player.gd index 4378676..c71d952 100644 --- a/player/player.gd +++ b/player/player.gd @@ -3,30 +3,51 @@ extends CharacterBody3D signal playerTurn +signal playerDestroyed +signal playerRestart -@export_category("Movement") +@onready var _skin = $skin + + +@export_category("Movement") @export var speed = 5.0 @export_category("Camera") @export var distance = 3.0 + @onready var _springArm = $SpringArm3D +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) - playerTurn.emit(self) - elif event.is_action_pressed("player_right"): - global_rotate(Vector3.UP, -PI/2) - playerTurn.emit(self) + 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: - velocity = global_transform.basis.z * speed - move_and_slide() + 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)