the-crypt/magic/Projectiles/ExplosiveProjectile.gd

33 lines
785 B
GDScript3
Raw Normal View History

2020-07-20 01:18:45 -05:00
extends Projectile
func _ready():
damage = 3
2020-07-20 16:36:28 -05:00
energy_cost = 5
2020-07-20 01:18:45 -05:00
func on_impact(collision):
2020-07-20 16:36:28 -05:00
if collision.collider.has_method("get_type") && collision.collider.get_type() == "enemy":
var c = collision.collider
c.health -= damage * damage_mod
explode()
elif bounces_left != 0:
bounces_left -= 1
look_at(position + velocity.bounce(collision.normal))
launch(null)
2020-07-20 16:36:28 -05:00
else:
explode()
func explode():
2020-07-20 01:18:45 -05:00
for body in $Area2D.get_overlapping_bodies():
if body.get("health") != null and body.get_type() != "player":
body.health -= damage
if body.has_method("play_hit"):
body.play_hit()
2020-07-20 01:18:45 -05:00
$Particles2D.emitting = true
$KillTimer.start()
set_physics_process(false)
$CollisionShape2D.disabled = true
$Sprite.visible = false
func _on_KillTimer_timeout():
queue_free()