ape-ame/player-apezoid.gd

65 lines
1.8 KiB
GDScript3
Raw Normal View History

2024-05-06 14:09:14 -04:00
extends "res://player.gd"
var can_damage = false
2024-05-07 09:23:18 -04:00
var shooting = false
2024-05-06 14:09:14 -04:00
var idle_texture = preload("res://dotted line.png")
var aiming_texture = preload("res://laser_idle.png")
2024-05-07 14:29:47 -04:00
var active_texture = preload("res://laser_idle.png")
2024-05-06 14:09:14 -04:00
2024-05-07 09:23:18 -04:00
func _ready():
update_animation()
if config.load("user://settings.cfg") == OK:
absolute_movement = not config.get_value("config", "relative_controls")
speed = 750
2024-05-06 14:09:14 -04:00
func update_animation():
if moving:
$Engine.play("active")
else:
$Engine.play("idle")
func _input(event):
2024-05-07 09:23:18 -04:00
if event.is_action_pressed("shoot") and speed != 0:
2024-05-06 14:09:14 -04:00
fire_laser()
func _process(delta):
if can_damage:
var body = $Laser/RayCast2D.get_collider()
2024-05-07 09:23:18 -04:00
if body != null and (body.is_in_group("destructible") or body.name == "Entagon"):
2024-05-06 14:09:14 -04:00
if body.has_method("destroy"):
body.destroy()
else:
body.queue_free()
func fire_laser():
var tween = get_tree().create_tween()
2024-05-07 09:23:18 -04:00
speed = 0
2024-05-06 14:09:14 -04:00
$Body.play("shoot")
tween.set_parallel(true)
tween.tween_callback(set_laser_texture.bind(aiming_texture))
tween.tween_property($Laser, "modulate", Color.WHITE, 1).set_ease(Tween.EASE_IN)
tween.tween_callback(play_with_delay)
tween.set_parallel(false)
tween.tween_callback(set_laser_texture.bind(active_texture))
2024-05-07 09:23:18 -04:00
tween.tween_property(self, "can_damage", true, 0)
2024-05-06 14:09:14 -04:00
tween.tween_interval(0.2)
2024-05-07 09:23:18 -04:00
tween.tween_property(self, "can_damage", false, 0)
2024-05-06 14:09:14 -04:00
tween.tween_callback(set_laser_texture.bind(aiming_texture))
tween.set_parallel(true)
tween.tween_property($Laser, "modulate", Color(Color.WHITE, 0.2), 0.2).set_ease(Tween.EASE_OUT)
tween.set_parallel(false)
tween.tween_callback(set_laser_texture.bind(idle_texture))
tween.tween_callback($Body.play.bind("idle"))
2024-05-07 09:23:18 -04:00
tween.tween_property(self, "speed", 750, 0)
2024-05-06 14:09:14 -04:00
2024-05-07 09:23:18 -04:00
2024-05-06 14:09:14 -04:00
func play_with_delay():
await get_tree().create_timer(0.9).timeout
$LaserFX.play()
func set_laser_texture(texture):
$Laser.texture = texture