]> Untitled Git - lightcycles.git/blob - player/player.gd
Added triplanar player wall textures and added arena walls
[lightcycles.git] / player / player.gd
1 class_name Player
2 extends CharacterBody3D
3
4
5 signal playerTurn
6 signal playerDestroyed
7 signal playerRestart
8
9
10 @onready var _skin = $skin
11
12
13 @export_category("Movement") 
14 @export var speed = 5.0
15
16 @export_category("Camera")
17 @export var distance = 3.0
18
19
20 @onready var _springArm = $SpringArm3D
21
22 enum state {ALIVE, DEAD}
23 var _state = state.ALIVE
24
25 func _ready() -> void:
26         _springArm.spring_length = distance
27
28
29 func _input(event: InputEvent) -> void:
30         if _state == state.ALIVE:
31                 if event.is_action_pressed("player_left"):
32                         global_rotate(Vector3.UP, PI/2)
33                         playerTurn.emit(self)
34                 elif event.is_action_pressed("player_right"):
35                         global_rotate(Vector3.UP, -PI/2)
36                         playerTurn.emit(self)
37         else:
38                 if event.is_action_pressed("player_restart"):
39                         playerRestart.emit(self)
40
41
42 func _physics_process(_delta: float) -> void:
43         if _state == state.ALIVE:
44                 velocity = global_transform.basis.z * speed
45                 move_and_slide()
46                 if velocity.length() == 0:
47                         _explode()
48
49
50 func _explode() -> void:
51         _skin.visible = false
52         _state = state.DEAD
53         playerDestroyed.emit(self)