the-crypt/magic/Wands/ChargedWand.gd

38 lines
915 B
GDScript3
Raw Normal View History

2020-07-20 23:24:09 -05:00
extends Wand
2020-07-21 19:50:43 -05:00
var charge_level = 0
var max_charge = 3
var projectile = null
onready var ChargeTimer: Timer = $ChargeTimer
func fire(p):
2020-07-23 01:27:37 -05:00
print(p)
2020-07-21 19:50:43 -05:00
projectile = p
if ChargeTimer.is_stopped():
ChargeTimer.start()
2020-07-21 20:06:39 -05:00
if charge_level == 0:
var temp = p.instance()
get_tree().current_scene.add_child(temp)
var energy = temp.energy_cost
temp.queue_free()
return energy * 2
2020-07-21 19:50:43 -05:00
func _process(delta):
2020-07-22 00:41:29 -05:00
scale = Vector2(charge_level / 2.0 + 1.0, charge_level / 2.0 + 1.0)
2020-07-21 19:50:43 -05:00
func _on_ChargeTimer_timeout():
2020-07-22 00:41:29 -05:00
charge_level = clamp(charge_level + 1, 0, max_charge)
2020-07-21 19:50:43 -05:00
func _input(event):
if event.is_action_released("shoot"):
ChargeTimer.stop()
if charge_level <= 0:
charge_level = 0
return
var temp = projectile.instance()
get_tree().current_scene.add_child(temp)
temp.global_transform = $ProjectileSpawn.global_transform
var energy_cost = temp.launch(wand_type, charge_level)
charge_level = 0