2024-02-07 22:04:19 +00:00
|
|
|
class_name PlayerController
|
|
|
|
extends Controller
|
|
|
|
|
|
|
|
var player: Player
|
|
|
|
var movement: MovementComponent
|
2024-02-15 15:28:27 +00:00
|
|
|
var skills: SkillsComponent
|
2024-02-07 22:04:19 +00:00
|
|
|
|
|
|
|
func _init(new_player: Player):
|
|
|
|
player = new_player
|
2024-02-15 15:28:27 +00:00
|
|
|
movement = player.get_node("Movement")
|
|
|
|
skills = player.get_node("Skills")
|
|
|
|
name = "Controller"
|
2024-02-07 22:04:19 +00:00
|
|
|
|
2024-02-15 15:28:27 +00:00
|
|
|
func _unhandled_input(event: InputEvent):
|
2024-02-25 18:47:13 +00:00
|
|
|
if UI.focus:
|
|
|
|
direction_changed.emit(Vector3.ZERO)
|
2024-02-07 22:04:19 +00:00
|
|
|
return
|
|
|
|
|
2024-02-15 15:28:27 +00:00
|
|
|
update_direction()
|
|
|
|
update_actions(event)
|
|
|
|
|
2024-02-26 22:50:56 +00:00
|
|
|
if Input.is_key_pressed(KEY_P):
|
|
|
|
get_tree().paused = !get_tree().paused
|
|
|
|
|
2024-02-15 15:28:27 +00:00
|
|
|
func update_direction():
|
2024-02-07 22:04:19 +00:00
|
|
|
var move := Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
|
2024-02-09 23:10:51 +00:00
|
|
|
var direction := (Global.camera.global_basis * Vector3(move.x, 0, move.y))
|
2024-02-07 22:04:19 +00:00
|
|
|
direction.y = 0
|
|
|
|
direction = direction.normalized()
|
2024-02-15 15:28:27 +00:00
|
|
|
direction_changed.emit(direction)
|
2024-02-07 22:04:19 +00:00
|
|
|
|
2024-02-15 15:28:27 +00:00
|
|
|
func update_actions(event: InputEvent):
|
2024-02-07 22:04:19 +00:00
|
|
|
if event.is_action_pressed("jump") && movement && movement.can_jump():
|
2024-02-15 15:28:27 +00:00
|
|
|
jumped.emit()
|
2024-02-13 20:04:35 +00:00
|
|
|
|
|
|
|
for i in range(4):
|
|
|
|
if event.is_action_pressed("skill_%d" % (i + 1)):
|
2024-02-15 15:28:27 +00:00
|
|
|
used_skill.emit(i)
|