2018-05-29 00:08:30 -04:00
|
|
|
#
|
|
|
|
# Copyright (C) 2018 Sage Vaillancourt, sagev9000@gmail.com
|
|
|
|
#
|
|
|
|
# This file is part of Fronter.
|
|
|
|
#
|
|
|
|
# Fronter is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Fronter is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Fronter. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
extends Area2D
|
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# signals
|
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
|
2018-05-27 02:20:51 -04:00
|
|
|
signal other_shooting_upgrade
|
2018-11-12 23:17:53 -05:00
|
|
|
signal other_damage_upgrade
|
2018-05-29 02:39:43 -04:00
|
|
|
signal double_laser_upgrade
|
2018-11-12 23:17:53 -05:00
|
|
|
signal other_laser_penetration_upgrade
|
2018-05-29 00:08:30 -04:00
|
|
|
signal other_ship_color_change
|
2018-06-03 11:11:27 -04:00
|
|
|
signal other_ship_enable_rainbow
|
2018-05-23 11:02:52 -04:00
|
|
|
signal shooting_speed_fully_upgraded
|
2018-05-23 21:35:16 -04:00
|
|
|
signal restart_game
|
2018-05-26 04:15:20 -04:00
|
|
|
signal multiplayer_movement
|
2018-11-12 23:17:53 -05:00
|
|
|
signal start_next_round
|
|
|
|
signal buy_turret
|
|
|
|
signal upgrade_turret_range
|
2018-05-23 11:02:52 -04:00
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
export (PackedScene) var Laser
|
|
|
|
|
2018-05-26 02:55:17 -04:00
|
|
|
################################
|
2018-05-27 03:46:10 -04:00
|
|
|
# THINGS THAT MAY NEED ADJUSTING
|
2018-05-26 02:55:17 -04:00
|
|
|
#################################
|
2018-05-27 03:46:10 -04:00
|
|
|
|
2018-06-03 11:11:27 -04:00
|
|
|
var ship_speed = 500
|
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# first 5 tiers of shooting speed
|
2018-11-12 23:17:53 -05:00
|
|
|
#const BULLET_DELAY_DICT = {1:0.8, 2:0.5, 3:0.4, 4:0.2, 5:0.05} #original
|
|
|
|
const BULLET_DELAY_DICT = {1:0.8, 2:0.6, 3:0.4, 4:0.2, 5:0.1}
|
2018-05-27 03:46:10 -04:00
|
|
|
# starting cost of shooting speed upgrades after tier 5
|
2018-05-23 11:02:52 -04:00
|
|
|
const SHOOTING_SPEED_UPGRADE_DEFAULT = 1500
|
2018-05-27 03:46:10 -04:00
|
|
|
|
|
|
|
# can't shoot faster than this
|
2018-05-23 11:02:52 -04:00
|
|
|
const BULLET_DELAY_MINIMUM = 0.01
|
2018-05-27 03:46:10 -04:00
|
|
|
|
|
|
|
# costs of shooting speed upgrades
|
2018-11-12 23:17:53 -05:00
|
|
|
const BULLET_DELAY_COST = {2:100, 3:400, 4:1000, 5:4000, 6:0}
|
2018-05-23 03:57:15 -04:00
|
|
|
|
2018-05-29 02:39:43 -04:00
|
|
|
# double laser cost
|
2018-11-12 23:17:53 -05:00
|
|
|
const DOUBLE_LASER_COST = 6000
|
2018-05-29 02:39:43 -04:00
|
|
|
|
2018-06-03 11:11:27 -04:00
|
|
|
# 5 tiers of laser damage
|
2018-11-12 23:17:53 -05:00
|
|
|
const LASER_DAMAGE_DICT = {1:10, 2:15, 3:20, 4:40, 5:50}
|
2018-05-27 03:46:10 -04:00
|
|
|
|
2018-06-03 11:11:27 -04:00
|
|
|
# costs of laser damage upgrades
|
2018-11-12 23:17:53 -05:00
|
|
|
const LASER_DAMAGE_COST = {2:400, 3:1000, 4:2000, 5:6000, 6:0}
|
|
|
|
|
|
|
|
# costs of laser penetration upgrades
|
|
|
|
const LASER_PENETRATION_COST = {2:400, 3:1000, 4:2000, 5:6000, 6:0}
|
2018-05-23 03:57:15 -04:00
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
# 5 tiers of laser penetration
|
|
|
|
const LASER_PENETRATION_DICT = {1:0,2:1,3:2,4:3,5:5}
|
2018-05-27 03:46:10 -04:00
|
|
|
# the ship's starting position
|
2018-06-03 11:11:27 -04:00
|
|
|
const STARTING_POSITION = Vector2(130, 250)
|
2018-05-27 03:46:10 -04:00
|
|
|
|
|
|
|
# the amount of money the player starts with
|
2018-11-14 20:36:02 -05:00
|
|
|
const STARTING_MONEY = 0100000
|
2018-11-12 23:17:53 -05:00
|
|
|
|
|
|
|
# cost to unlock turrets
|
|
|
|
const UNLOCK_TURRETS_COST = 1000
|
2018-05-23 21:35:16 -04:00
|
|
|
|
2018-05-26 02:55:17 -04:00
|
|
|
#################################
|
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# set sliding shooting speed upgrade costs
|
|
|
|
var shooting_speed_upgrade = SHOOTING_SPEED_UPGRADE_DEFAULT
|
|
|
|
|
|
|
|
# used to limit player movement
|
2018-05-23 01:40:45 -04:00
|
|
|
var screensize
|
2018-05-23 03:57:15 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# can the player shoot at this instant
|
|
|
|
var can_shoot = false
|
|
|
|
|
|
|
|
# timer for shooting speed
|
|
|
|
var timer = null
|
|
|
|
|
|
|
|
# sets the delay between shots to the default
|
2018-11-12 23:17:53 -05:00
|
|
|
var bullet_delay = BULLET_DELAY_DICT[1]
|
|
|
|
var bullet_delay_tier = 1
|
2018-05-27 03:46:10 -04:00
|
|
|
|
|
|
|
# sets other shooting settings to their defaults
|
2018-11-12 23:17:53 -05:00
|
|
|
var laser_penetration = LASER_PENETRATION_DICT[1]
|
|
|
|
var laser_penetration_tier = 1
|
2018-05-23 03:57:15 -04:00
|
|
|
var double_laser = false
|
2018-11-12 23:17:53 -05:00
|
|
|
var laser_damage = LASER_DAMAGE_DICT[1]
|
|
|
|
var laser_damage_tier = 1
|
|
|
|
|
|
|
|
# turret settings
|
|
|
|
var turrets_unlocked = false
|
|
|
|
var has_turret = false
|
2018-05-23 03:57:15 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# gives the player their starting points
|
|
|
|
var money = STARTING_MONEY
|
|
|
|
|
|
|
|
# sets initial value of ship, to be added to with upgrades for refunds
|
2018-05-23 03:57:15 -04:00
|
|
|
var ship_value = 0
|
2018-05-27 03:46:10 -04:00
|
|
|
|
|
|
|
# what percentage of points should be returned on refunding
|
2018-05-23 11:13:48 -04:00
|
|
|
var refund_percentage = 1
|
2018-05-23 01:40:45 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# is a menu open? try to ignore input in-game
|
|
|
|
# only really relevant to touchscreens
|
|
|
|
var menu_open = false
|
2018-05-23 11:02:52 -04:00
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
var boss = false
|
|
|
|
var damage = 0
|
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# opens the upgrade menu
|
2018-05-23 11:02:52 -04:00
|
|
|
func upgradeMenu():
|
|
|
|
var upgmenu = preload("res://UpgradeMenu.tscn").instance()
|
2018-11-12 23:17:53 -05:00
|
|
|
menu_open = true
|
2018-05-23 11:02:52 -04:00
|
|
|
add_child(upgmenu)
|
|
|
|
upgmenu.connect("refund", self, "_refund_button")
|
2018-11-12 23:17:53 -05:00
|
|
|
upgmenu.connect("bullet_delay_upgrade", self, "upgradeBulletDelay")
|
|
|
|
upgmenu.connect("double_laser_upgrade", self, "doubleLaserUpgrade")
|
|
|
|
upgmenu.connect("laser_penetration_upgrade", self, "laserPenetrationUpgrade")
|
2018-05-29 00:08:30 -04:00
|
|
|
upgmenu.connect("change_color", self, "changeColor")
|
2018-06-03 11:11:27 -04:00
|
|
|
upgmenu.connect("taste_the_rainbow", self, "enable_the_rainbow")
|
2018-11-12 23:17:53 -05:00
|
|
|
upgmenu.connect("laser_damage_upgrade", self, "upgradeLaserDamage")
|
|
|
|
upgmenu.connect("menu_closed", self, "upgradeMenuClosed")
|
|
|
|
upgmenu.connect("unlock_turrets", self, "unlockTurrets")
|
|
|
|
upgmenu.connect("buy_turret", self, "buyTurret")
|
|
|
|
upgmenu.connect("turret_menu", self, "openTurretMenu")
|
|
|
|
upgmenu.laser_damage_tier = laser_damage_tier
|
2018-05-23 21:35:16 -04:00
|
|
|
upgmenu.bullet_delay_tier = bullet_delay_tier
|
2018-11-12 23:17:53 -05:00
|
|
|
upgmenu.laser_penetration_tier = laser_penetration_tier
|
|
|
|
upgmenu.turrets_unlocked = turrets_unlocked
|
|
|
|
upgmenu.has_turret = has_turret
|
2018-05-27 02:20:51 -04:00
|
|
|
if !get_tree().has_network_peer():
|
|
|
|
get_tree().paused = true
|
2018-11-12 23:17:53 -05:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# signalled on close of UpgradeMenu
|
2018-11-12 23:17:53 -05:00
|
|
|
func upgradeMenuClosed():
|
|
|
|
menu_open = false
|
|
|
|
emit_signal("start_next_round")
|
|
|
|
|
|
|
|
func pauseMenu():
|
|
|
|
menu_open = true
|
|
|
|
var pausemenu = preload("res://PauseMenu.tscn").instance()
|
|
|
|
add_child(pausemenu)
|
|
|
|
pausemenu.connect("change_color", self, "changeColor")
|
|
|
|
pausemenu.connect("menu_closed", self, "pauseMenuClosed")
|
|
|
|
pausemenu.connect("taste_the_rainbow", self, "enable_the_rainbow")
|
|
|
|
if !get_tree().has_network_peer():
|
|
|
|
get_tree().paused = true
|
|
|
|
|
|
|
|
func pauseMenuClosed():
|
2018-05-27 02:20:51 -04:00
|
|
|
menu_open = false
|
2018-05-26 02:55:17 -04:00
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
func openTurretMenu():
|
|
|
|
var turretmenu = preload("res://TurretMenu.tscn").instance()
|
|
|
|
add_child(turretmenu)
|
|
|
|
turretmenu.connect("buy_turret", self, "buyTurret")
|
|
|
|
turretmenu.connect("turret_range_upgrade", self, "turretRangeUpgrade")
|
|
|
|
turretmenu.screensize = screensize
|
|
|
|
if !get_tree().has_network_peer():
|
|
|
|
get_tree().paused = true
|
|
|
|
|
|
|
|
func makePurchaseFor(cost):
|
|
|
|
if money >= cost:
|
|
|
|
money -= cost
|
|
|
|
emit_signal("update_display")
|
|
|
|
return true
|
|
|
|
else:
|
|
|
|
return false
|
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
#######################
|
|
|
|
# REQUESTING UPGRADES #
|
|
|
|
#######################
|
|
|
|
# all will request their upgrade
|
|
|
|
# all will pause the game if not in multiplayer
|
2018-11-12 23:17:53 -05:00
|
|
|
# checks which tier the player is already on, and if they have enough points
|
|
|
|
# upgrades and charges the player, if possible
|
|
|
|
# increases the ship value by the amount spent, for refunds
|
|
|
|
# sends an rpc message about current state for a given upgrade
|
2018-05-27 03:46:10 -04:00
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
func unlockTurrets():
|
|
|
|
if money >= UNLOCK_TURRETS_COST:# && turrets_unlocked == false:
|
|
|
|
money -= UNLOCK_TURRETS_COST
|
|
|
|
turrets_unlocked = true
|
|
|
|
emit_signal("update_display")
|
|
|
|
openTurretMenu()
|
|
|
|
# pause if not multiplayer
|
|
|
|
if !get_tree().has_network_peer():
|
|
|
|
get_tree().paused = true
|
|
|
|
|
|
|
|
func buyTurret(turret_position, cost):
|
|
|
|
#money -= cost
|
2018-05-27 03:46:10 -04:00
|
|
|
emit_signal("update_display")
|
|
|
|
if !get_tree().has_network_peer():
|
2018-11-12 23:17:53 -05:00
|
|
|
emit_signal("buy_turret", get_tree().get_network_unique_id(), turret_position)
|
|
|
|
has_turret = true
|
2018-05-27 03:46:10 -04:00
|
|
|
get_tree().paused = true
|
2018-11-12 23:17:53 -05:00
|
|
|
else:
|
|
|
|
rpc("net_buying_turret", get_tree().get_network_unique_id(), turret_position)
|
2018-05-27 03:46:10 -04:00
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
sync func net_buying_turret(id, turret_position):
|
|
|
|
emit_signal("buy_turret", id, turret_position)
|
2018-05-27 03:46:10 -04:00
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
func turretRangeUpgrade(cost, new_scale):
|
|
|
|
if makePurchaseFor(cost):
|
|
|
|
emit_signal("upgrade_turret_range", get_tree().get_network_unique_id(), new_scale)
|
|
|
|
if !get_tree().has_network_peer():
|
|
|
|
get_tree().paused = true
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
# ALLOWS THE PLAYER TO SHOOT TWO LASERS AT ONCE #
|
|
|
|
func doubleLaserUpgrade():
|
|
|
|
# if the user has enough money, take that money, and enable doubles
|
|
|
|
if money >= DOUBLE_LASER_COST && double_laser == false:
|
|
|
|
money -= DOUBLE_LASER_COST
|
|
|
|
double_laser = true
|
|
|
|
|
|
|
|
# tell other players to enable doubles for you
|
|
|
|
rpc("double_laser_upgrade", get_tree().get_network_unique_id())
|
|
|
|
|
|
|
|
# tell main to update the points display
|
2018-05-26 02:55:17 -04:00
|
|
|
emit_signal("update_display")
|
2018-11-12 23:17:53 -05:00
|
|
|
|
|
|
|
# pause if not multiplayer
|
2018-05-27 02:20:51 -04:00
|
|
|
if !get_tree().has_network_peer():
|
|
|
|
get_tree().paused = true
|
2018-05-23 11:02:52 -04:00
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
# tell main about other ship's double_laser
|
|
|
|
remote func double_laser_upgrade(id):
|
|
|
|
emit_signal("double_laser_upgrade", id)
|
|
|
|
# ALLOWS THE PLAYER TO SHOOT TWO LASERS AT ONCE #
|
|
|
|
#################################################
|
|
|
|
|
|
|
|
|
|
|
|
######################################################
|
|
|
|
# ALLOWS LASERS TO PENETRATE ENEMIES BEFORE EXPIRING #
|
|
|
|
var next_penetration_upgrade_cost = LASER_PENETRATION_COST[laser_penetration_tier + 1]
|
|
|
|
func laserPenetrationUpgrade():
|
|
|
|
if laser_penetration_tier < 5:
|
|
|
|
if money >= LASER_PENETRATION_COST[laser_penetration_tier + 1]:
|
|
|
|
laser_penetration_tier += 1
|
|
|
|
laser_penetration = LASER_PENETRATION_DICT[laser_penetration_tier]
|
|
|
|
money -= LASER_PENETRATION_COST[laser_penetration_tier]
|
|
|
|
ship_value += LASER_PENETRATION_COST[laser_penetration_tier]
|
|
|
|
next_penetration_upgrade_cost = LASER_PENETRATION_COST[laser_penetration_tier + 1]
|
|
|
|
print(laser_penetration)
|
2018-05-23 11:02:52 -04:00
|
|
|
emit_signal("update_display")
|
2018-11-12 23:17:53 -05:00
|
|
|
|
|
|
|
rpc("other_laser_penetration_upgrade", get_tree().get_network_unique_id(), laser_penetration)
|
|
|
|
# pause if not multiplayer
|
2018-05-27 02:20:51 -04:00
|
|
|
if !get_tree().has_network_peer():
|
|
|
|
get_tree().paused = true
|
2018-05-23 04:24:00 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
remote func other_laser_penetration_upgrade(id):
|
|
|
|
emit_signal("other_laser_penetration_upgrade", id)
|
|
|
|
|
|
|
|
# tell main about other ship's
|
|
|
|
# ALLOWS LASERS TO PENETRATE ENEMIES BEFORE EXPIRING #
|
|
|
|
######################################################
|
2018-05-27 03:46:10 -04:00
|
|
|
|
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
###############################################
|
|
|
|
# INCREASES THE FIRE RATE FOR PLAYERS' LASERS #
|
|
|
|
var next_bullet_delay_upgrade_cost = BULLET_DELAY_COST[bullet_delay_tier + 1]
|
2018-05-23 04:24:00 -04:00
|
|
|
func upgradeBulletDelay():
|
2018-11-12 23:17:53 -05:00
|
|
|
if bullet_delay_tier < 5:
|
|
|
|
if money >= BULLET_DELAY_COST[bullet_delay_tier + 1]:
|
|
|
|
bullet_delay_tier += 1
|
|
|
|
bullet_delay = BULLET_DELAY_DICT[bullet_delay_tier]
|
|
|
|
money -= BULLET_DELAY_COST[bullet_delay_tier]
|
|
|
|
ship_value += BULLET_DELAY_COST[bullet_delay_tier]
|
|
|
|
next_bullet_delay_upgrade_cost = BULLET_DELAY_COST[bullet_delay_tier + 1]
|
|
|
|
print(bullet_delay)
|
2018-05-27 02:20:51 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
timer.set_wait_time(bullet_delay)
|
2018-05-27 02:20:51 -04:00
|
|
|
rpc("other_shooting_speed_upgrade", get_tree().get_network_unique_id(), bullet_delay)
|
2018-11-12 23:17:53 -05:00
|
|
|
emit_signal("update_display")
|
|
|
|
if !get_tree().has_network_peer():
|
|
|
|
get_tree().paused = true
|
2018-05-23 11:02:52 -04:00
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
# tell main about other ship's bullet_delay upgrade
|
|
|
|
remote func other_shooting_speed_upgrade(id, bullet_delay):
|
|
|
|
emit_signal("other_shooting_upgrade", id, bullet_delay)
|
|
|
|
# INCREASES THE FIRE RATE FOR PLAYERS' LASERS #
|
|
|
|
###############################################
|
|
|
|
|
|
|
|
|
|
|
|
############################################
|
|
|
|
# INCREASES DAMAGE DONE BY EACH LASER SHOT #
|
|
|
|
var next_laser_damage_upgrade_cost = LASER_DAMAGE_COST[laser_damage_tier + 1]
|
|
|
|
func upgradeLaserDamage():
|
|
|
|
if laser_damage_tier < 5:
|
|
|
|
if money >= LASER_DAMAGE_COST[laser_damage_tier + 1]:
|
|
|
|
laser_damage_tier += 1
|
|
|
|
laser_damage = LASER_DAMAGE_DICT[laser_damage_tier]
|
|
|
|
money -= LASER_DAMAGE_COST[laser_damage_tier]
|
|
|
|
ship_value += LASER_DAMAGE_COST[laser_damage_tier]
|
|
|
|
next_laser_damage_upgrade_cost = LASER_DAMAGE_COST[laser_damage_tier + 1]
|
|
|
|
print(laser_damage)
|
|
|
|
|
|
|
|
rpc("other_laser_damage_upgrade", get_tree().get_network_unique_id(), laser_damage)
|
|
|
|
emit_signal("update_display")
|
|
|
|
if !get_tree().has_network_peer():
|
|
|
|
get_tree().paused = true
|
2018-05-29 02:39:43 -04:00
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
# tell main about other ship's laser_damage upgrade
|
|
|
|
remote func other_laser_damage_upgrade(id, laser_damage):
|
|
|
|
emit_signal("other_damage_upgrade", id, laser_damage)
|
|
|
|
# INCREASES DAMAGE DONE BY EACH LASER SHOT #
|
|
|
|
############################################
|
2018-05-27 03:46:10 -04:00
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
func _ready():
|
2018-05-27 03:46:10 -04:00
|
|
|
# for measuring time between lasers
|
2018-05-23 01:40:45 -04:00
|
|
|
timer = Timer.new()
|
|
|
|
timer.set_one_shot(true)
|
|
|
|
timer.set_wait_time(bullet_delay)
|
|
|
|
timer.connect("timeout", self, "on_timeout_complete")
|
|
|
|
add_child(timer)
|
2018-05-26 02:55:17 -04:00
|
|
|
timer.start()
|
2018-05-23 01:40:45 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# set player's position to the default
|
|
|
|
position = STARTING_POSITION
|
2018-05-23 01:40:45 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# sets screensize to prevent player leaving screen
|
2018-05-23 01:40:45 -04:00
|
|
|
screensize = get_viewport_rect().size
|
2018-05-27 03:46:10 -04:00
|
|
|
|
|
|
|
# starts the ship's rocketing animation
|
2018-05-23 01:40:45 -04:00
|
|
|
$AnimatedSprite.play()
|
2018-05-23 04:24:00 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# resets all upgrades to the default
|
|
|
|
# refunds them with adjustable percentage returned
|
2018-11-12 23:17:53 -05:00
|
|
|
# not currently 100%, so disabled
|
2018-05-23 11:02:52 -04:00
|
|
|
func _refund_button():
|
2018-11-12 23:17:53 -05:00
|
|
|
bullet_delay = BULLET_DELAY_DICT[1]
|
|
|
|
bullet_delay_tier = 1
|
2018-05-23 11:02:52 -04:00
|
|
|
timer.set_wait_time(bullet_delay)
|
2018-05-27 03:46:10 -04:00
|
|
|
laser_penetration = 0
|
|
|
|
double_laser = false
|
2018-11-12 23:17:53 -05:00
|
|
|
rainbow_is_on = false
|
|
|
|
changeColor(Color(1,1,1,1))
|
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")
|
2018-11-12 23:17:53 -05:00
|
|
|
#get_tree().paused = true
|
2018-05-23 01:40:45 -04:00
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
############################
|
|
|
|
# Changes the ship's color #
|
2018-05-29 00:08:30 -04:00
|
|
|
func changeColor(color):
|
|
|
|
$AnimatedSprite.modulate = color
|
|
|
|
if get_tree().has_network_peer():
|
|
|
|
rpc("_change_color", get_tree().get_network_unique_id(), color)
|
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
# tell main about other ship's color change
|
|
|
|
remote func _change_color(id, color):
|
|
|
|
emit_signal("other_ship_color_change", id, color)
|
|
|
|
|
|
|
|
# Changes the ship's color #
|
|
|
|
############################
|
|
|
|
|
2018-05-23 03:57:15 -04:00
|
|
|
func on_timeout_complete():
|
|
|
|
can_shoot = true
|
|
|
|
|
2018-05-26 04:15:20 -04:00
|
|
|
var is_shooting
|
|
|
|
|
2018-05-26 02:55:17 -04:00
|
|
|
func moveto(finger_position):
|
2018-05-27 02:20:51 -04:00
|
|
|
if !menu_open:
|
|
|
|
if (finger_position.x > position.x && finger_position.x < 800):
|
|
|
|
velocity.x += 1
|
|
|
|
if position.x > finger_position.x:
|
|
|
|
velocity.x -= 1
|
|
|
|
if (finger_position.y - 100 > position.y && finger_position.x < 800):
|
|
|
|
velocity.y += 1
|
|
|
|
if (position.y > finger_position.y - 100 && finger_position.x < 800):
|
|
|
|
velocity.y -= 1
|
2018-05-26 02:55:17 -04:00
|
|
|
|
2018-05-26 04:15:20 -04:00
|
|
|
remote func move_player(id, position, is_shooting):
|
|
|
|
emit_signal("multiplayer_movement", id, position, is_shooting)
|
2018-05-26 02:55:17 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# the player's movement vector
|
|
|
|
var velocity = Vector2()
|
2018-05-26 02:55:17 -04:00
|
|
|
|
2018-06-03 11:11:27 -04:00
|
|
|
var rainbow = Color(0,0,0,1)
|
|
|
|
var r_up = true
|
|
|
|
var g_up = true
|
|
|
|
var b_up = true
|
|
|
|
var rainbow_speed = 30
|
|
|
|
var rainbow_is_on = false
|
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
func _process(delta):
|
2018-05-27 03:46:10 -04:00
|
|
|
# move player with keyboard
|
2018-05-26 02:55:17 -04:00
|
|
|
velocity = Vector2()
|
2018-05-27 03:46:10 -04:00
|
|
|
if Input.is_action_pressed("ui_right"):
|
2018-05-23 01:40:45 -04:00
|
|
|
velocity.x += 1
|
2018-05-27 03:46:10 -04:00
|
|
|
if Input.is_action_pressed("ui_left"):
|
2018-05-23 01:40:45 -04:00
|
|
|
velocity.x -= 1
|
2018-05-27 03:46:10 -04:00
|
|
|
if Input.is_action_pressed("ui_down"):
|
2018-05-23 01:40:45 -04:00
|
|
|
velocity.y += 1
|
2018-05-27 03:46:10 -04:00
|
|
|
if Input.is_action_pressed("ui_up"):
|
2018-05-23 01:40:45 -04:00
|
|
|
velocity.y -= 1
|
|
|
|
if (velocity.length() > 0):
|
|
|
|
velocity = velocity.normalized() * ship_speed
|
|
|
|
position += velocity * delta
|
2018-05-27 03:46:10 -04:00
|
|
|
|
2018-06-03 11:11:27 -04:00
|
|
|
if rainbow_is_on:
|
|
|
|
rainbow(delta)
|
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# prevents player leaving the screen
|
2018-06-03 11:11:27 -04:00
|
|
|
position.x = clamp(position.x-100, 0, screensize.x-164) + 100
|
2018-05-23 01:40:45 -04:00
|
|
|
position.y = clamp(position.y, 0, screensize.y)
|
2018-05-26 04:15:20 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# basically exists just for rpc messages about whether or not the player is currently firing
|
2018-05-26 04:15:20 -04:00
|
|
|
if can_shoot:
|
|
|
|
is_shooting = false
|
|
|
|
else:
|
|
|
|
is_shooting = true
|
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# if in multiplayer mode, push position and shooting status as often as possible
|
2018-11-12 23:17:53 -05:00
|
|
|
#if get_tree().has_network_peer():
|
|
|
|
# rpc_unreliable("move_player", get_tree().get_network_unique_id(), position, is_shooting)
|
2018-05-23 04:24:00 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# if shoot button is pressed, try shooting
|
|
|
|
if Input.is_action_pressed("ui_accept"):
|
2018-05-23 03:57:15 -04:00
|
|
|
shoot()
|
2018-05-26 02:55:17 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# ui_reset button opens the upgrade menu
|
|
|
|
if Input.is_action_pressed("ui_reset"):
|
|
|
|
upgradeMenu()
|
2018-05-23 03:57:15 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# spawn lasers to shoot
|
|
|
|
# lasers can be set to penetrate or not
|
|
|
|
# can fire two lasers at once if double_laser is on
|
2018-05-23 03:57:15 -04:00
|
|
|
func shoot():
|
2018-05-26 04:15:20 -04:00
|
|
|
if can_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-06-03 11:11:27 -04:00
|
|
|
laser.damage = laser_damage
|
2018-05-26 02:55:17 -04:00
|
|
|
|
2018-05-26 04:15:20 -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
|
2018-11-12 23:17:53 -05:00
|
|
|
laser2.damage = laser_damage
|
2018-05-26 04:15:20 -04:00
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# don't shoot again until the timer resets
|
2018-05-26 04:15:20 -04:00
|
|
|
can_shoot = false
|
|
|
|
timer.start()
|
|
|
|
|
2018-06-03 11:11:27 -04:00
|
|
|
# Funky colors #
|
|
|
|
# NOT CURRENTLY REFUNDABLE #
|
|
|
|
func enable_the_rainbow():
|
|
|
|
if money >= 2000 && not rainbow_is_on:
|
|
|
|
money -= 2000
|
2018-11-12 23:17:53 -05:00
|
|
|
emit_signal("update_display")
|
2018-06-03 11:11:27 -04:00
|
|
|
rainbow_is_on = true
|
|
|
|
rpc("_enable_rainbow", get_tree().get_network_unique_id())
|
2018-11-12 23:17:53 -05:00
|
|
|
|
|
|
|
if !get_tree().has_network_peer():
|
|
|
|
get_tree().paused = true
|
|
|
|
|
|
|
|
remote func _enable_rainbow(id):
|
|
|
|
emit_signal("other_ship_enable_rainbow", id)
|
2018-06-03 11:11:27 -04:00
|
|
|
|
|
|
|
func rainbow(delta):
|
|
|
|
if rainbow.r < 1 && r_up:
|
|
|
|
rainbow.r += rainbow_speed*delta/10
|
|
|
|
if rainbow.r >= 1: r_up = false
|
|
|
|
else:
|
|
|
|
rainbow.r -= rainbow_speed*delta/10
|
|
|
|
if rainbow.r <= 0.2: r_up = true
|
|
|
|
|
|
|
|
if rainbow.g < 1 && g_up:
|
|
|
|
rainbow.g += rainbow_speed*delta/9
|
|
|
|
if rainbow.g >= 1: g_up = false
|
|
|
|
else:
|
|
|
|
rainbow.g -= rainbow_speed*delta/9
|
|
|
|
if rainbow.g <= 0.2: g_up = true
|
|
|
|
|
|
|
|
if rainbow.b < 1 && b_up:
|
|
|
|
rainbow.b += rainbow_speed*delta/8
|
|
|
|
if rainbow.b >= 1: b_up = false
|
|
|
|
else:
|
|
|
|
rainbow.b -= rainbow_speed*delta/8
|
|
|
|
if rainbow.b <= 0.2: b_up = true
|
|
|
|
|
|
|
|
$AnimatedSprite.modulate = rainbow
|
|
|
|
|
2018-11-12 23:17:53 -05:00
|
|
|
var gameover
|
2018-05-27 03:46:10 -04:00
|
|
|
# displays endgame screen and pauses
|
2018-05-23 21:35:16 -04:00
|
|
|
func gameOver():
|
2018-11-12 23:17:53 -05:00
|
|
|
gameover = preload("res://GameOver.tscn").instance()
|
2018-05-23 21:35:16 -04:00
|
|
|
add_child(gameover)
|
|
|
|
gameover.connect("restart", self, "restart_game")
|
|
|
|
# gameover.connect("bullet_delay_upgrade", self, "upgradeBulletDelay_button")
|
|
|
|
get_tree().paused = true
|
|
|
|
|
2018-05-27 03:46:10 -04:00
|
|
|
# uses refund function to remove upgrades
|
|
|
|
# sets points back to default
|
2018-05-23 21:35:16 -04:00
|
|
|
func restart_game():
|
|
|
|
_refund_button()
|
|
|
|
get_tree().paused = false
|
|
|
|
money = STARTING_MONEY
|
2018-11-12 23:17:53 -05:00
|
|
|
emit_signal("restart_game")
|
|
|
|
gameover.queue_free()
|
|
|
|
|
|
|
|
func _on_Timer_timeout():
|
|
|
|
if get_tree().has_network_peer():
|
|
|
|
rpc_unreliable("move_player", get_tree().get_network_unique_id(), position, is_shooting)
|