2018-05-23 01:40:45 -04:00
|
|
|
extends Area2D
|
|
|
|
|
2018-05-23 11:02:52 -04:00
|
|
|
signal update_display # tells parent to update points display
|
|
|
|
signal refund # will tell parent a refund is occuring, for display
|
|
|
|
signal shooting_speed_upgrade # signals that a shooting speed upgrade has occured
|
|
|
|
signal ship_speed_upgrade
|
|
|
|
signal shooting_speed_fully_upgraded
|
|
|
|
signal ship_speed_fully_upgraded
|
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
export (PackedScene) var Laser
|
|
|
|
|
2018-05-23 03:57:15 -04:00
|
|
|
#Default ship strengths and costs
|
|
|
|
const BULLET_DELAY_TIER1 = 0.8
|
|
|
|
const BULLET_DELAY_TIER2 = 0.5
|
|
|
|
const BULLET_DELAY_TIER3 = 0.2
|
|
|
|
const BULLET_DELAY_TIER4 = 0.1
|
|
|
|
const BULLET_DELAY_TIER5 = 0.05
|
2018-05-23 11:02:52 -04:00
|
|
|
const SHOOTING_SPEED_UPGRADE_DEFAULT = 1500
|
|
|
|
const BULLET_DELAY_MINIMUM = 0.01
|
2018-05-23 03:57:15 -04:00
|
|
|
const BULLET_DELAY_TIER2_COST = 100
|
|
|
|
const BULLET_DELAY_TIER3_COST = 200
|
|
|
|
const BULLET_DELAY_TIER4_COST = 400
|
|
|
|
const BULLET_DELAY_TIER5_COST = 1000
|
|
|
|
|
|
|
|
const SHIP_SPEED_TIER1 = 150
|
|
|
|
const SHIP_SPEED_TIER2 = 200
|
|
|
|
const SHIP_SPEED_TIER3 = 300
|
|
|
|
const SHIP_SPEED_TIER4 = 500
|
|
|
|
const SHIP_SPEED_TIER5 = 800
|
2018-05-23 11:02:52 -04:00
|
|
|
const SHIP_SPEED_UPGRADE_DEFAULT = 1500
|
|
|
|
const SHIP_SPEED_MAXIMUM = 1200
|
|
|
|
const SHIP_SPEED_TIER2_COST = 200
|
|
|
|
const SHIP_SPEED_TIER3_COST = 400
|
|
|
|
const SHIP_SPEED_TIER4_COST = 600
|
|
|
|
const SHIP_SPEED_TIER5_COST = 800
|
2018-05-23 03:57:15 -04:00
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
var screensize
|
2018-05-23 03:57:15 -04:00
|
|
|
|
|
|
|
var ship_speed = SHIP_SPEED_TIER1
|
|
|
|
|
|
|
|
var bullet_delay = BULLET_DELAY_TIER1
|
|
|
|
var bullet_delay_tier = 1
|
|
|
|
var laser_penetration = 0
|
|
|
|
var double_laser = false
|
|
|
|
|
|
|
|
var ship_value = 0
|
2018-05-23 11:13:48 -04:00
|
|
|
var refund_percentage = 1
|
2018-05-23 01:40:45 -04:00
|
|
|
var money = 100
|
|
|
|
|
2018-05-23 04:24:00 -04:00
|
|
|
var shooting_speed_upgrade = SHOOTING_SPEED_UPGRADE_DEFAULT
|
2018-05-23 11:02:52 -04:00
|
|
|
var ship_speed_upgrade = SHIP_SPEED_UPGRADE_DEFAULT
|
|
|
|
|
|
|
|
func upgradeMenu():
|
|
|
|
var upgmenu = preload("res://UpgradeMenu.tscn").instance()
|
|
|
|
add_child(upgmenu)
|
|
|
|
upgmenu.connect("refund", self, "_refund_button")
|
|
|
|
upgmenu.connect("bullet_delay_upgrade", self, "upgradeBulletDelay_button")
|
|
|
|
get_tree().paused = true
|
|
|
|
|
|
|
|
func upgradeBulletDelay_button():
|
|
|
|
upgradeBulletDelay()
|
|
|
|
emit_signal("update_display")
|
|
|
|
get_tree().paused = true
|
2018-05-23 04:24:00 -04:00
|
|
|
|
|
|
|
func upgradeBulletDelay():
|
2018-05-23 11:02:52 -04:00
|
|
|
if (bullet_delay == BULLET_DELAY_TIER1 && money >= BULLET_DELAY_TIER2_COST):
|
|
|
|
bullet_delay = BULLET_DELAY_TIER2
|
|
|
|
money -= BULLET_DELAY_TIER2_COST
|
|
|
|
ship_value += BULLET_DELAY_TIER2_COST
|
|
|
|
elif (bullet_delay == BULLET_DELAY_TIER2 && money >= BULLET_DELAY_TIER3_COST):
|
|
|
|
bullet_delay = BULLET_DELAY_TIER3
|
|
|
|
money -= BULLET_DELAY_TIER3_COST
|
|
|
|
ship_value += BULLET_DELAY_TIER3_COST
|
|
|
|
elif (bullet_delay == BULLET_DELAY_TIER3 && money >= BULLET_DELAY_TIER4_COST):
|
|
|
|
bullet_delay = BULLET_DELAY_TIER4
|
|
|
|
money -= BULLET_DELAY_TIER4_COST
|
|
|
|
ship_value += BULLET_DELAY_TIER4_COST
|
|
|
|
elif (bullet_delay == BULLET_DELAY_TIER4 && money >= BULLET_DELAY_TIER5_COST):
|
|
|
|
bullet_delay = BULLET_DELAY_TIER5
|
|
|
|
money -= BULLET_DELAY_TIER5_COST
|
|
|
|
ship_value += BULLET_DELAY_TIER5_COST
|
|
|
|
elif (bullet_delay <= BULLET_DELAY_MINIMUM):
|
|
|
|
emit_signal("bullet_delay_fully_upgraded")
|
|
|
|
elif (bullet_delay <= BULLET_DELAY_TIER5 && money >= shooting_speed_upgrade):
|
|
|
|
bullet_delay = bullet_delay*0.95
|
|
|
|
money -= shooting_speed_upgrade
|
|
|
|
ship_value += shooting_speed_upgrade
|
|
|
|
shooting_speed_upgrade *= 1.1
|
|
|
|
timer.set_wait_time(bullet_delay)
|
|
|
|
prints(bullet_delay)
|
|
|
|
|
|
|
|
func upgradeShipSpeed():
|
|
|
|
if (ship_speed == SHIP_SPEED_TIER1 && money >= SHIP_SPEED_TIER2_COST):
|
|
|
|
ship_speed = SHIP_SPEED_TIER2
|
|
|
|
money -= SHIP_SPEED_TIER2_COST
|
|
|
|
ship_value += SHIP_SPEED_TIER2_COST
|
|
|
|
elif (ship_speed == SHIP_SPEED_TIER2 && money >= SHIP_SPEED_TIER3_COST):
|
|
|
|
ship_speed = SHIP_SPEED_TIER3
|
|
|
|
money -= SHIP_SPEED_TIER3_COST
|
|
|
|
ship_value += SHIP_SPEED_TIER3_COST
|
|
|
|
elif (ship_speed == SHIP_SPEED_TIER3 && money >= SHIP_SPEED_TIER4_COST):
|
|
|
|
ship_speed = SHIP_SPEED_TIER4
|
|
|
|
money -= SHIP_SPEED_TIER4_COST
|
|
|
|
ship_value += SHIP_SPEED_TIER4_COST
|
|
|
|
elif (ship_speed == SHIP_SPEED_TIER4 && money >= SHIP_SPEED_TIER5_COST):
|
|
|
|
ship_speed = SHIP_SPEED_TIER5
|
|
|
|
money -= SHIP_SPEED_TIER5_COST
|
|
|
|
ship_value += SHIP_SPEED_TIER5_COST
|
|
|
|
elif (ship_speed >= SHIP_SPEED_MAXIMUM):
|
|
|
|
emit_signal("ship_speed_fully_upgraded")
|
|
|
|
elif (ship_speed >= SHIP_SPEED_TIER5 && money >= ship_speed_upgrade):
|
|
|
|
ship_speed = ship_speed*1.05
|
|
|
|
money -= ship_speed_upgrade
|
|
|
|
ship_value += ship_speed_upgrade
|
|
|
|
ship_speed_upgrade *= 1.1
|
|
|
|
prints(ship_speed)
|
2018-05-23 01:40:45 -04:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
timer = Timer.new()
|
|
|
|
timer.set_one_shot(true)
|
|
|
|
timer.set_wait_time(bullet_delay)
|
|
|
|
timer.connect("timeout", self, "on_timeout_complete")
|
|
|
|
add_child(timer)
|
|
|
|
|
|
|
|
position.x = 100
|
|
|
|
position.y = 250
|
|
|
|
|
|
|
|
screensize = get_viewport_rect().size
|
|
|
|
$AnimatedSprite.play()
|
2018-05-23 04:24:00 -04:00
|
|
|
|
2018-05-23 11:02:52 -04:00
|
|
|
func _refund_button():
|
2018-05-23 03:57:15 -04:00
|
|
|
bullet_delay = BULLET_DELAY_TIER1
|
2018-05-23 11:02:52 -04:00
|
|
|
timer.set_wait_time(bullet_delay)
|
2018-05-23 03:57:15 -04:00
|
|
|
ship_speed = SHIP_SPEED_TIER1
|
2018-05-23 04:24:00 -04:00
|
|
|
shooting_speed_upgrade = SHOOTING_SPEED_UPGRADE_DEFAULT
|
2018-05-23 03:57:15 -04:00
|
|
|
money += ship_value*refund_percentage
|
2018-05-23 11:02:52 -04:00
|
|
|
prints("Refunded ", ship_value*refund_percentage)
|
2018-05-23 01:40:45 -04:00
|
|
|
ship_value = 0
|
2018-05-23 11:02:52 -04:00
|
|
|
emit_signal("update_display")
|
|
|
|
get_tree().paused = true
|
2018-05-23 01:40:45 -04:00
|
|
|
|
|
|
|
var timer = null
|
|
|
|
|
|
|
|
var can_shoot = true
|
|
|
|
var going_up = false
|
|
|
|
var going_down = false
|
|
|
|
var shoot_down = false
|
|
|
|
|
2018-05-23 03:57:15 -04:00
|
|
|
func on_timeout_complete():
|
|
|
|
can_shoot = true
|
|
|
|
|
2018-05-23 11:02:52 -04:00
|
|
|
#func _unhandled_input(event):
|
|
|
|
# if (event is InputEventScreenTouch):
|
|
|
|
# gravity_point = true
|
|
|
|
# gravity_vec = Vector2(0.5, 0.5)
|
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
func _process(delta):
|
|
|
|
var velocity = Vector2() # the player's movement vector
|
|
|
|
if (Input.is_action_pressed("ui_right")):
|
|
|
|
velocity.x += 1
|
|
|
|
if (Input.is_action_pressed("ui_left")):
|
|
|
|
velocity.x -= 1
|
|
|
|
if (Input.is_action_pressed("ui_down") || going_down == true):
|
|
|
|
velocity.y += 1
|
|
|
|
if (Input.is_action_pressed("ui_up") || going_up == true):
|
|
|
|
velocity.y -= 1
|
|
|
|
if (velocity.length() > 0):
|
|
|
|
velocity = velocity.normalized() * ship_speed
|
2018-05-23 04:24:00 -04:00
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
position += velocity * delta
|
|
|
|
position.x = clamp(position.x, 0, screensize.x)
|
|
|
|
position.y = clamp(position.y, 0, screensize.y)
|
2018-05-23 04:24:00 -04:00
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
if ((Input.is_action_pressed("ui_accept") || shoot_down == true) && can_shoot == true):
|
2018-05-23 03:57:15 -04:00
|
|
|
shoot()
|
2018-05-23 04:24:00 -04:00
|
|
|
if (Input.is_action_pressed("ui_select") && can_shoot == true):
|
|
|
|
upgradeBulletDelay()
|
2018-05-23 11:02:52 -04:00
|
|
|
if (Input.is_action_pressed("ui_reset") && can_shoot == true):
|
|
|
|
#upgradeShipSpeed()
|
|
|
|
upgradeMenu()
|
2018-05-23 01:40:45 -04:00
|
|
|
|
|
|
|
func _on_Player_body_entered(body):
|
|
|
|
prints("hit")
|
|
|
|
|
|
|
|
func upPressed():
|
|
|
|
going_up = true
|
|
|
|
func upDepressed():
|
|
|
|
going_up = false
|
|
|
|
|
|
|
|
func downPressed():
|
|
|
|
going_down = true
|
|
|
|
func downDepressed():
|
|
|
|
going_down = false
|
|
|
|
|
|
|
|
func shootDown():
|
2018-05-23 03:57:15 -04:00
|
|
|
shoot_down = true
|
2018-05-23 01:40:45 -04:00
|
|
|
func shootUp():
|
2018-05-23 03:57:15 -04:00
|
|
|
shoot_down = false
|
|
|
|
|
|
|
|
func shoot():
|
|
|
|
var laser = Laser.instance()
|
|
|
|
get_node("../").add_child(laser)
|
|
|
|
laser.current_pen = laser_penetration
|
|
|
|
laser.position.y = position.y - 27
|
|
|
|
laser.position.x = position.x + 46
|
2018-05-23 04:24:00 -04:00
|
|
|
|
2018-05-23 03:57:15 -04:00
|
|
|
#MAYBE THE LASERS SHOULD BE THEIR OWN NODES
|
|
|
|
#Would allow for more simple additions in the future
|
|
|
|
if double_laser == true:
|
|
|
|
var laser2 = Laser.instance()
|
|
|
|
get_node("../").add_child(laser2)
|
|
|
|
laser2.position.y = position.y + 28
|
|
|
|
laser2.position.x = position.x + 46
|
|
|
|
laser2.current_pen = laser_penetration
|
|
|
|
|
|
|
|
can_shoot = false
|
|
|
|
timer.start()
|