the-crypt/magic/Projectiles/ExplosiveProjectile.gd

35 lines
846 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":
2020-07-21 19:50:43 -05:00
body.health -= damage * damage_mod
if body.has_method("play_hit"):
body.play_hit()
2020-07-21 15:50:32 -05:00
$Explosion.play(0.0)
2020-07-20 01:18:45 -05:00
$Particles2D.emitting = true
$KillTimer.start()
2020-07-23 19:47:27 -05:00
$Light2D.visible = false
2020-07-20 01:18:45 -05:00
set_physics_process(false)
$CollisionShape2D.disabled = true
$Sprite.visible = false
func _on_KillTimer_timeout():
queue_free()