This repository has been archived on 2024-08-28. You can view files and clone it, but cannot push or open issues or pull requests.
gmtk-2024/scripts/viruling.gd

53 lines
1.4 KiB
GDScript3
Raw Normal View History

extends Entity;
@onready var animated_sprite = $AnimatedSprite2D
@onready var collider = $CollisionShape2D
@onready var contact_hitbox = $ContactHitbox
@onready var collision_shape = collider.shape
@onready var attack_timer = $Timer
@onready var is_dying = false
@onready var death_timer = $DeathTimer
const 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 = -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 = -speed
move_and_slide()
func _process(delta: float) -> void:
if health <= 0:
is_dying = true
death_timer.start()
health = 99999
if is_dying:
animated_sprite.play("death")
contact_hitbox.visible = false
speed = 0
if death_timer.is_stopped():
queue_free()
func body_connect(node: Node):
if node is Entity and node != self and attack_timer.is_stopped():
attack_timer.start(0.25)
node.health -= damage
take_knockback(ATTACK_KNOCKBACK)