55 lines
1.6 KiB
GDScript3
55 lines
1.6 KiB
GDScript3
|
extends CharacterBody2D
|
||
|
|
||
|
@export var speed = 1200
|
||
|
@export var speed_multiplier = 20
|
||
|
@export var friction = 0.9
|
||
|
|
||
|
@export var dash_cooldown_duration = 1.0
|
||
|
@export var dash_cooldown_timer: Timer
|
||
|
|
||
|
@export var weapon_bullet_speed = 3200
|
||
|
@export var weapon_bullet_scene: PackedScene
|
||
|
@export var weapon_bullet_parent: Node2D
|
||
|
|
||
|
@export var fire_cooldown_duration = 0.2
|
||
|
@export var fire_cooldown_timer: Timer
|
||
|
|
||
|
func deal_move(delta):
|
||
|
var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||
|
velocity = velocity.move_toward(input_direction * speed, speed * delta)
|
||
|
velocity = velocity * friction
|
||
|
|
||
|
var is_dash = Input.is_action_pressed("skill_dash")
|
||
|
if is_dash && dash_cooldown_timer.is_stopped():
|
||
|
velocity *= speed_multiplier
|
||
|
dash_cooldown_timer.start(dash_cooldown_duration)
|
||
|
|
||
|
func deal_weapon_shoot():
|
||
|
var is_shooting = Input.is_action_pressed("weapon_fire")
|
||
|
if is_shooting && fire_cooldown_timer.is_stopped():
|
||
|
var mouse_position = get_global_mouse_position()
|
||
|
var direction = (mouse_position - position).normalized()
|
||
|
var bullet = weapon_bullet_scene.instantiate()
|
||
|
bullet.rotation = direction.angle()
|
||
|
weapon_bullet_parent.add_child(bullet)
|
||
|
|
||
|
bullet.global_position = global_position
|
||
|
bullet.velocity = direction * weapon_bullet_speed
|
||
|
|
||
|
fire_cooldown_timer.start(fire_cooldown_duration)
|
||
|
|
||
|
func _on_dash_cooled_down():
|
||
|
dash_cooldown_timer.stop()
|
||
|
|
||
|
func _on_fire_cooled_down():
|
||
|
fire_cooldown_timer.stop()
|
||
|
|
||
|
func _ready():
|
||
|
var screen_size = get_viewport_rect().size
|
||
|
position = Vector2(screen_size.x / 2, screen_size.y / 2)
|
||
|
|
||
|
func _physics_process(delta):
|
||
|
deal_move(delta)
|
||
|
deal_weapon_shoot()
|
||
|
move_and_slide()
|