gmtk-2024/scripts/viruling.gd

63 lines
1.7 KiB
GDScript3
Raw Permalink Normal View History

class_name Viruling extends Entity;
@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
@onready var death_timer = $DeathTimer
@onready var explosion_sfx = $ExplosionSFX
2024-08-17 21:39:51 +00:00
var is_dying = false
var attack_speed = 0
var speed_multiplier = 100
const INITIAL_HEALTH = 10
const ATTACK_DAMAGE = 10
const ATTACK_KNOCKBACK = 5000
func _init() -> void:
super._init(INITIAL_HEALTH, speed_multiplier, ATTACK_DAMAGE)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
velocity.x = attack_speed
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)
velocity.x = attack_speed
velocity.y = 0 # jank
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-17 21:39:51 +00:00
animated_sprite.play("death")
explosion_sfx.play()
2024-08-17 21:39:51 +00:00
contact_hitbox.visible = false
speed_multiplier = 0
2024-08-17 21:39:51 +00:00
if death_timer.is_stopped():
queue_free()
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()
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")
func charge() -> void:
attack_speed = -speed_multiplier