the-crypt/magic/Projectiles/Projectile.gd

23 lines
544 B
GDScript3
Raw Normal View History

extends KinematicBody2D
class_name Projectile
2020-07-20 01:18:45 -05:00
export var speed = 400
var velocity = Vector2.ZERO
2020-07-19 19:15:43 -05:00
var energy_cost = 1
2020-07-20 00:06:53 -05:00
var damage = 1
func _physics_process(delta):
var collision = move_and_collide(velocity * delta)
if collision != null:
2020-07-17 19:18:59 -05:00
on_impact(collision)
2020-07-18 17:07:40 -05:00
2020-07-19 18:36:36 -05:00
func launch(wand, effect):
2020-07-17 15:21:22 -05:00
velocity = (Vector2(speed, 0)).rotated(rotation)
2020-07-19 19:15:43 -05:00
return energy_cost
2020-07-17 19:18:59 -05:00
func on_impact(collision):
2020-07-20 00:06:53 -05:00
if collision.collider.has_method("get_type") && collision.collider.get_type() == "enemy":
var c = collision.collider
c.health -= damage
queue_free()