2020-07-17 13:15:52 -05:00
|
|
|
extends KinematicBody2D
|
|
|
|
class_name Projectile
|
|
|
|
|
2020-07-20 01:18:45 -05:00
|
|
|
export var speed = 400
|
2020-07-17 13:15:52 -05:00
|
|
|
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
|
2020-07-17 13:15:52 -05:00
|
|
|
|
2020-07-20 16:36:28 -05:00
|
|
|
var damage_mod = 1
|
|
|
|
var energy_mod = 1
|
|
|
|
var bounces_left = 0
|
|
|
|
|
|
|
|
var is_bounce = false
|
|
|
|
var is_charge = false
|
|
|
|
var is_prism = false
|
|
|
|
var is_triple = false
|
|
|
|
|
2020-07-21 19:50:43 -05:00
|
|
|
onready var Spr: Sprite = $Sprite
|
|
|
|
|
2020-07-20 16:36:28 -05:00
|
|
|
func get_wand_type(wand_id):
|
|
|
|
match wand_id:
|
|
|
|
Globals.Conduit1:
|
|
|
|
is_charge = true
|
|
|
|
print("charge")
|
|
|
|
Globals.Conduit2:
|
|
|
|
is_triple = true
|
|
|
|
print("triple")
|
2020-07-23 14:43:42 -05:00
|
|
|
var damage_mod = 0.5
|
2020-07-20 16:36:28 -05:00
|
|
|
Globals.Conduit3:
|
|
|
|
is_bounce = true
|
|
|
|
print("bounce")
|
|
|
|
bounces_left = 1
|
|
|
|
Globals.Conduit4:
|
|
|
|
print("prism")
|
|
|
|
is_prism = true
|
|
|
|
|
2020-07-17 13:15:52 -05:00
|
|
|
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-21 19:50:43 -05:00
|
|
|
func launch(wand, mod = 1):
|
2020-07-17 15:21:22 -05:00
|
|
|
velocity = (Vector2(speed, 0)).rotated(rotation)
|
2020-07-21 19:50:43 -05:00
|
|
|
damage_mod = mod
|
|
|
|
scale = Vector2(1, 1)
|
|
|
|
Spr.scale = Vector2(mod, mod)
|
2020-07-20 16:36:28 -05:00
|
|
|
get_wand_type(wand)
|
|
|
|
return energy_cost * energy_mod
|
2020-07-17 13:15:52 -05:00
|
|
|
|
2020-07-17 19:18:59 -05:00
|
|
|
func on_impact(collision):
|
2020-07-23 14:43:42 -05:00
|
|
|
print(collision.collider)
|
2020-07-20 00:06:53 -05:00
|
|
|
if collision.collider.has_method("get_type") && collision.collider.get_type() == "enemy":
|
|
|
|
var c = collision.collider
|
2020-07-20 16:36:28 -05:00
|
|
|
c.health -= damage * damage_mod
|
2020-07-21 15:00:32 -05:00
|
|
|
c.play_hit()
|
2020-07-21 15:50:32 -05:00
|
|
|
if $FireSound.playing:
|
|
|
|
set_physics_process(false)
|
|
|
|
$CollisionShape2D.disabled = true
|
|
|
|
$Sprite.visible = false
|
|
|
|
yield($FireSound, "finished")
|
2020-07-20 16:36:28 -05:00
|
|
|
queue_free()
|
|
|
|
elif bounces_left != 0:
|
|
|
|
bounces_left -= 1
|
|
|
|
look_at(position + velocity.bounce(collision.normal))
|
2020-07-21 15:00:32 -05:00
|
|
|
launch(null)
|
2020-07-20 16:36:28 -05:00
|
|
|
else:
|
2020-07-21 15:50:32 -05:00
|
|
|
if $FireSound.playing:
|
|
|
|
set_physics_process(false)
|
|
|
|
$CollisionShape2D.disabled = true
|
|
|
|
$Sprite.visible = false
|
|
|
|
yield($FireSound, "finished")
|
2020-07-20 16:36:28 -05:00
|
|
|
queue_free()
|