2024-08-18 15:29:35 +00:00
|
|
|
class_name Viruling extends Entity;
|
2024-08-17 19:54:37 +00:00
|
|
|
|
|
|
|
@onready var animated_sprite = $AnimatedSprite2D
|
|
|
|
@onready var collider = $CollisionShape2D
|
|
|
|
@onready var contact_hitbox = $ContactHitbox
|
|
|
|
@onready var collision_shape = collider.shape
|
2024-08-17 21:39:51 +00:00
|
|
|
@onready var attack_timer = $AttackTimer
|
2024-08-17 19:54:37 +00:00
|
|
|
@onready var death_timer = $DeathTimer
|
2024-08-18 02:04:28 +00:00
|
|
|
@onready var explosion_sfx = $ExplosionSFX
|
2024-08-17 21:39:51 +00:00
|
|
|
var is_dying = false
|
2024-08-18 15:29:35 +00:00
|
|
|
var attack_speed = 0
|
2024-08-17 19:54:37 +00:00
|
|
|
|
2024-08-18 15:29:35 +00:00
|
|
|
var speed_multiplier = 100
|
2024-08-17 19:54:37 +00:00
|
|
|
const INITIAL_HEALTH = 10
|
|
|
|
const ATTACK_DAMAGE = 10
|
|
|
|
const ATTACK_KNOCKBACK = 5000
|
|
|
|
|
|
|
|
func _init() -> void:
|
2024-08-18 15:29:35 +00:00
|
|
|
super._init(INITIAL_HEALTH, speed_multiplier, ATTACK_DAMAGE)
|
2024-08-17 19:54:37 +00:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready() -> void:
|
2024-08-18 15:29:35 +00:00
|
|
|
velocity.x = attack_speed
|
2024-08-17 19:54:37 +00:00
|
|
|
contact_hitbox.body_entered.connect(body_connect)
|
|
|
|
contact_hitbox.visible = false
|
|
|
|
animated_sprite.play("spin")
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
if !is_dying:
|
|
|
|
contact_hitbox.visible = false if contact_hitbox.visible else true
|
|
|
|
super._physics_process(delta)
|
2024-08-18 15:29:35 +00:00
|
|
|
velocity.x = attack_speed
|
|
|
|
velocity.y = 0 # jank
|
2024-08-17 19:54:37 +00:00
|
|
|
move_and_slide()
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
2024-08-17 21:39:51 +00:00
|
|
|
if health <= 0:
|
|
|
|
is_dying = true
|
|
|
|
death_timer.start()
|
|
|
|
health = 99999
|
|
|
|
|
|
|
|
if is_dying:
|
2024-08-18 02:04:28 +00:00
|
|
|
|
2024-08-17 21:39:51 +00:00
|
|
|
animated_sprite.play("death")
|
2024-08-18 02:04:28 +00:00
|
|
|
explosion_sfx.play()
|
2024-08-17 21:39:51 +00:00
|
|
|
contact_hitbox.visible = false
|
2024-08-18 15:29:35 +00:00
|
|
|
speed_multiplier = 0
|
2024-08-17 19:54:37 +00:00
|
|
|
|
2024-08-17 21:39:51 +00:00
|
|
|
if death_timer.is_stopped():
|
|
|
|
queue_free()
|
2024-08-17 19:54:37 +00:00
|
|
|
|
|
|
|
func body_connect(node: Node):
|
|
|
|
if node is Entity and node != self and attack_timer.is_stopped():
|
2024-08-17 21:39:51 +00:00
|
|
|
attack_timer.start()
|
2024-08-17 19:54:37 +00:00
|
|
|
node.health -= damage
|
2024-08-17 21:39:51 +00:00
|
|
|
node.take_knockback(ATTACK_KNOCKBACK)
|
|
|
|
if node.has_method("hurt_anim"):
|
|
|
|
node.call("hurt_anim")
|
2024-08-18 15:29:35 +00:00
|
|
|
|
|
|
|
func charge() -> void:
|
|
|
|
attack_speed = -speed_multiplier
|