-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.gd
37 lines (26 loc) · 834 Bytes
/
player.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
extends CharacterBody2D
class_name Player
@export var move_speed = 6000
@onready var sprite := $AnimatedSprite2D
@onready var dash := $Dash as Dash
func _ready():
Globals.player = self
func _physics_process(delta: float) -> void:
var x_input = Input.get_axis("left", "right")
var y_input = Input.get_axis("up", "down")
sprite.flip_h = get_global_mouse_position().x < position.x
if x_input != 0:
if sprite.flip_h:
sprite.speed_scale = -x_input
else:
sprite.speed_scale = x_input
if x_input or y_input:
sprite.animation = "Run"
else:
sprite.animation = "Idle"
if Input.is_action_just_pressed("dash"):
dash.start_dash()
var speed = dash.speed if dash.is_dashing() else move_speed
velocity = Vector2(x_input, y_input) * speed * delta
if dash.is_dashing(): sprite.animation = "Dash"
move_and_slide()