2018-06-03 11:11:27 -04:00
|
|
|
extends Node2D
|
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
signal upgrade_turret
|
|
|
|
|
2018-06-03 11:11:27 -04:00
|
|
|
var can_shoot = true
|
2018-11-12 23:17:53 -05:00
|
|
|
var damage = 15
|
|
|
|
var reload_time = 1.5
|
|
|
|
|
|
|
|
var current_bad_id
|
|
|
|
var current_bad = null
|
|
|
|
var current_bad_shape
|
|
|
|
|
|
|
|
var tier = 1
|
|
|
|
|
|
|
|
const RANGE_TIER = {1:Vector2(30,30), 2:Vector2(40,40), 3:Vector2(50,50), 4:Vector2(60,60)}
|
|
|
|
const DAMAGE_TIER = {1:15, 2:25, 3:50, 4:100}
|
|
|
|
const RELOAD_TIER = {1:1.5, 2:1, 3:0.75, 4:0.5}
|
2018-11-29 16:04:22 -05:00
|
|
|
const ANIMATION_TIER = {1:"plain", 2:"point", 3:"spike", 4:"spike"}
|
2018-11-12 23:17:53 -05:00
|
|
|
const ANIMATION_SCALE_TIER = {1:Vector2(.12,.12), 2:Vector2(.2,.2), 3:Vector2(.2,.2), 4:Vector2(.2,.2)}
|
|
|
|
|
|
|
|
var enemy_count = 0
|
2018-06-03 11:11:27 -04:00
|
|
|
|
2018-11-29 16:04:22 -05:00
|
|
|
export (PackedScene) var UMenu
|
|
|
|
|
2018-06-03 11:11:27 -04:00
|
|
|
func _ready():
|
2018-11-12 23:17:53 -05:00
|
|
|
$ReloadTimer.wait_time = RELOAD_TIER[tier]
|
|
|
|
damage = DAMAGE_TIER[tier]
|
|
|
|
$Range.scale = RANGE_TIER[tier]
|
|
|
|
$TurretSprite.animation = ANIMATION_TIER[tier]
|
|
|
|
$TurretSprite.scale = ANIMATION_SCALE_TIER[tier]
|
|
|
|
$Damage.text = str(damage)
|
2018-06-03 11:11:27 -04:00
|
|
|
pass
|
|
|
|
|
|
|
|
var zeroPoint = Vector2(-60, -1015)
|
|
|
|
|
|
|
|
func _process(delta):
|
2018-11-12 23:17:53 -05:00
|
|
|
if current_bad:
|
|
|
|
var wr = weakref(current_bad)
|
|
|
|
if wr.get_ref():
|
|
|
|
if current_bad != null:
|
|
|
|
var local_pos = Vector2()
|
|
|
|
local_pos = to_local(current_bad.position)
|
|
|
|
$Beam.set_point_position(1, local_pos)
|
|
|
|
$TurretSprite.rotation = ($Beam.get_point_position(0).angle_to($Beam.get_point_position(1))) + PI/5.3
|
|
|
|
|
|
|
|
if ("Bad" in current_bad.get_name()) && can_shoot:
|
|
|
|
$Beam.default_color.a = 200
|
|
|
|
$TurretSprite.frame = 1
|
|
|
|
if current_bad.health > damage:
|
|
|
|
current_bad.hit(self)
|
|
|
|
else:
|
|
|
|
current_bad.hit(self)
|
|
|
|
current_bad = null
|
|
|
|
$FlashTimer.start()
|
|
|
|
can_shoot = false
|
2018-06-03 11:11:27 -04:00
|
|
|
|
|
|
|
func entityEnteredRange(bad_id, bad, bad_shape, self_shape):
|
2018-11-12 23:17:53 -05:00
|
|
|
#print(bad.get_name())
|
2018-11-13 19:31:59 -05:00
|
|
|
if ("Bad" in bad.get_name() || "Black" in bad.get_name() || "Boss" in bad.get_name()) || "Prison" in bad.get_name():# && current_bad == null:
|
2018-11-12 23:17:53 -05:00
|
|
|
current_bad = bad
|
|
|
|
current_bad_id = bad_id
|
|
|
|
current_bad_shape = bad_shape
|
|
|
|
enemy_count += 1
|
2018-11-13 19:31:59 -05:00
|
|
|
#print(enemy_count)
|
2018-06-03 11:11:27 -04:00
|
|
|
|
|
|
|
func _on_FlashTimer_timeout():
|
|
|
|
$Beam.default_color.a = 0
|
|
|
|
$TurretSprite.frame = 0
|
|
|
|
pass # replace with function body
|
|
|
|
|
|
|
|
func _on_ReloadTimer_timeout():
|
|
|
|
can_shoot = true
|
|
|
|
pass # replace with function body
|
2018-11-12 23:17:53 -05:00
|
|
|
|
|
|
|
func entityExitedRange(bad_id, bad, bad_shape, self_shape):
|
|
|
|
if weakref(bad):
|
|
|
|
if ("Bad" in bad.get_name()):
|
|
|
|
enemy_count -= 1
|
|
|
|
|
|
|
|
if bad_id == current_bad_id:
|
|
|
|
current_bad = null
|
|
|
|
current_bad_id = null
|
|
|
|
current_bad_shape = null
|
|
|
|
|
|
|
|
func _on_OpenMenuButton_pressed():
|
2018-11-29 16:04:22 -05:00
|
|
|
var menu = UMenu.instance()
|
2018-11-12 23:17:53 -05:00
|
|
|
add_child(menu)
|
|
|
|
menu.connect("turret_upgrade", self, "upgradeTurret")
|
2018-11-14 20:36:02 -05:00
|
|
|
pass
|
2018-11-12 23:17:53 -05:00
|
|
|
|
|
|
|
func upgradeTurret():
|
|
|
|
tier += 1
|
|
|
|
$ReloadTimer.wait_time = RELOAD_TIER[tier]
|
|
|
|
damage = DAMAGE_TIER[tier]
|
|
|
|
$Range.scale = RANGE_TIER[tier]
|
|
|
|
$TurretSprite.animation = ANIMATION_TIER[tier]
|
|
|
|
$TurretSprite.scale = ANIMATION_SCALE_TIER[tier]
|
|
|
|
|
|
|
|
func relayUpgrade():
|
|
|
|
print("relayUpgrade()")
|
|
|
|
emit_signal("upgrade_turret", position)
|