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 Node
|
2018-05-23 03:57:15 -04:00
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
export (PackedScene) var FirstBad
|
2018-05-23 03:57:15 -04:00
|
|
|
export (PackedScene) var BlobBad
|
2018-05-26 02:55:17 -04:00
|
|
|
export (PackedScene) var LaserBad
|
2018-05-27 19:22:11 -04:00
|
|
|
export (PackedScene) var RectangleBoss
|
2018-05-23 03:57:15 -04:00
|
|
|
|
2018-05-29 00:08:30 -04:00
|
|
|
var players = {}
|
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
var position = Vector2(200, 200)
|
2018-05-27 19:22:11 -04:00
|
|
|
var bads_this_round = 0
|
2018-05-23 01:40:45 -04:00
|
|
|
var upgrade_cost = 50
|
2018-05-26 02:55:17 -04:00
|
|
|
var booting = true
|
2018-05-29 00:08:30 -04:00
|
|
|
var screen_flashing = false
|
2018-05-26 02:55:17 -04:00
|
|
|
var rectangle_opacity = 1
|
2018-05-27 19:22:11 -04:00
|
|
|
var bad_spawning_enabled = true
|
2018-05-29 00:08:30 -04:00
|
|
|
var player_info
|
|
|
|
var touchy_shooty = false
|
2018-05-29 02:39:43 -04:00
|
|
|
var my_info = { name = "sagethesagesage", color = "FFFFFF" }
|
2018-05-29 00:08:30 -04:00
|
|
|
var mainmenu
|
2018-05-23 01:40:45 -04:00
|
|
|
|
2018-05-23 21:35:16 -04:00
|
|
|
const BADDIE_WAIT_TIME_DEFAULT = 5
|
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
func _ready():
|
2018-05-29 00:08:30 -04:00
|
|
|
# Prepare black rectangle for fading in
|
2018-05-27 02:20:51 -04:00
|
|
|
$ColorRect.visible = true
|
2018-05-29 00:08:30 -04:00
|
|
|
|
|
|
|
# Launch the main menu on boot and pause the game
|
|
|
|
mainmenu = preload("res://MainMenu.tscn").instance()
|
2018-05-24 04:19:59 -04:00
|
|
|
add_child(mainmenu)
|
2018-05-26 02:55:17 -04:00
|
|
|
mainmenu.connect("multiplayer_menu", self, "_open_multiplayer_menu")
|
2018-05-24 04:19:59 -04:00
|
|
|
get_tree().paused = true
|
2018-05-29 00:08:30 -04:00
|
|
|
|
|
|
|
# Prepare timer for spawning enemies
|
2018-05-23 21:35:16 -04:00
|
|
|
$BaddieTimer.wait_time = BADDIE_WAIT_TIME_DEFAULT
|
2018-05-23 01:40:45 -04:00
|
|
|
$BaddieTimer.start()
|
2018-05-29 00:08:30 -04:00
|
|
|
|
|
|
|
# Seed randi for randomizing enemy spawn locations
|
2018-05-23 01:40:45 -04:00
|
|
|
randomize()
|
2018-05-26 02:55:17 -04:00
|
|
|
|
2018-05-29 00:08:30 -04:00
|
|
|
# Open the multiplayer section of the menu and pause the game
|
2018-05-26 02:55:17 -04:00
|
|
|
func _open_multiplayer_menu():
|
|
|
|
var multiplayer = preload("res://Networking.tscn").instance()
|
2018-05-29 00:08:30 -04:00
|
|
|
multiplayer.connect("player_info", self, "_load_players")
|
|
|
|
multiplayer.connect("start_multiplayer_game", self, "_start_multiplayer_game")
|
2018-05-26 02:55:17 -04:00
|
|
|
add_child(multiplayer)
|
2018-05-29 00:08:30 -04:00
|
|
|
multiplayer.setName(my_info.name)
|
2018-05-26 02:55:17 -04:00
|
|
|
get_tree().paused = true
|
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
func _process(delta):
|
2018-05-29 00:08:30 -04:00
|
|
|
# If L+R+A+Start is pressed on a controller, quit
|
2018-05-23 01:40:45 -04:00
|
|
|
if (Input.is_action_pressed("ctlr_l")):
|
|
|
|
if (Input.is_action_pressed("ctlr_r")):
|
|
|
|
if (Input.is_action_pressed("ctlr_a")):
|
|
|
|
if (Input.is_action_pressed("ctlr_start")):
|
|
|
|
get_tree().quit()
|
2018-05-29 00:08:30 -04:00
|
|
|
# If the quit button is pressed, do it
|
2018-05-23 01:40:45 -04:00
|
|
|
if (Input.is_action_pressed("ui_quit")):
|
|
|
|
get_tree().quit()
|
2018-05-29 00:08:30 -04:00
|
|
|
|
|
|
|
# Constantly update point display
|
2018-05-23 03:57:15 -04:00
|
|
|
updatePoints()
|
2018-05-26 02:55:17 -04:00
|
|
|
|
2018-05-29 00:08:30 -04:00
|
|
|
# If you're in multiplayer,
|
2018-05-26 04:15:20 -04:00
|
|
|
if get_tree().has_network_peer():
|
2018-05-29 00:08:30 -04:00
|
|
|
# and not the host
|
2018-05-26 04:15:20 -04:00
|
|
|
if !get_tree().is_network_server():
|
2018-05-29 00:08:30 -04:00
|
|
|
# Stop spawning bads
|
2018-05-26 04:15:20 -04:00
|
|
|
$BaddieTimer.stop()
|
|
|
|
|
2018-05-26 02:55:17 -04:00
|
|
|
if (touchy_feely && (abs(touchy_feely.position.x - $Player.position.x) > 1)):
|
|
|
|
if (touchy_feely.position.x < 800):
|
|
|
|
$Player.moveto(touchy_feely.position)
|
|
|
|
|
|
|
|
if (touchy_shooty && $Player.can_shoot):
|
|
|
|
$Player.shoot()
|
2018-05-29 00:08:30 -04:00
|
|
|
|
|
|
|
# If we're in the booting process, fade out the rectangle
|
2018-05-26 02:55:17 -04:00
|
|
|
if booting == true:
|
|
|
|
$ColorRect.color = Color(0, 0, 0, rectangle_opacity)
|
|
|
|
rectangle_opacity -= delta/1.25
|
|
|
|
if rectangle_opacity <= 0:
|
|
|
|
booting = false
|
|
|
|
$ColorRect.visible = false
|
2018-05-27 19:22:11 -04:00
|
|
|
|
2018-05-29 00:08:30 -04:00
|
|
|
# Flash the screen white
|
2018-05-27 19:22:11 -04:00
|
|
|
if screen_flashing == true:
|
|
|
|
$ColorRect.color = Color(1, 1, 1, rectangle_opacity)
|
|
|
|
rectangle_opacity -= delta/4
|
|
|
|
if rectangle_opacity <= 0:
|
|
|
|
screen_flashing = false
|
|
|
|
$ColorRect.visible = false
|
|
|
|
|
2018-05-29 00:08:30 -04:00
|
|
|
# After 100 enemies, enter bossMode
|
2018-05-27 19:22:11 -04:00
|
|
|
if total_bads_spawned == 100:
|
|
|
|
bossMode()
|
2018-05-23 01:40:45 -04:00
|
|
|
|
2018-05-29 00:08:30 -04:00
|
|
|
# When an enemy dies
|
2018-05-23 03:57:15 -04:00
|
|
|
func _on_bad_death(kill_money):
|
2018-05-29 00:08:30 -04:00
|
|
|
# Give players appropriate money
|
2018-05-23 01:40:45 -04:00
|
|
|
$Player.money += kill_money
|
|
|
|
|
2018-05-29 00:08:30 -04:00
|
|
|
var a_round_of_bads = 30
|
2018-05-26 02:55:17 -04:00
|
|
|
var sendblob = 1
|
|
|
|
var bad_health_multi = 1
|
2018-05-27 19:22:11 -04:00
|
|
|
var total_bads_spawned = 0
|
2018-05-23 01:40:45 -04:00
|
|
|
func BaddieTimer():
|
2018-05-29 02:52:23 -04:00
|
|
|
if total_bads_spawned == 15: # 75 default
|
2018-05-27 19:22:11 -04:00
|
|
|
if get_tree().is_network_server():
|
|
|
|
rpc("bossMode")
|
|
|
|
else:
|
|
|
|
bossMode()
|
|
|
|
total_bads_spawned += 1
|
|
|
|
|
|
|
|
if bads_this_round <= a_round_of_bads && bad_spawning_enabled:
|
2018-05-26 15:34:41 -04:00
|
|
|
var bad_type
|
|
|
|
var badposition = Vector2()
|
2018-05-26 02:55:17 -04:00
|
|
|
if sendblob%20 == 0:
|
2018-05-26 15:34:41 -04:00
|
|
|
bad_type = 2
|
2018-05-26 02:55:17 -04:00
|
|
|
sendblob += 1
|
|
|
|
elif sendblob%5 == 0:
|
2018-05-26 15:34:41 -04:00
|
|
|
bad_type = 1
|
2018-05-26 02:55:17 -04:00
|
|
|
sendblob += 1
|
2018-05-23 01:40:45 -04:00
|
|
|
else:
|
2018-05-26 15:34:41 -04:00
|
|
|
bad_type = 0
|
2018-05-23 01:40:45 -04:00
|
|
|
sendblob += 1
|
2018-05-23 03:57:15 -04:00
|
|
|
|
2018-05-27 19:22:11 -04:00
|
|
|
bads_this_round += 1
|
2018-05-26 02:55:17 -04:00
|
|
|
if $BaddieTimer.wait_time > 0.5:
|
2018-05-27 02:20:51 -04:00
|
|
|
$BaddieTimer.wait_time = $BaddieTimer.wait_time * 0.975
|
2018-05-27 19:22:11 -04:00
|
|
|
if bads_this_round == a_round_of_bads:
|
2018-05-26 02:55:17 -04:00
|
|
|
bad_health_multi *= 1.5
|
2018-05-23 01:40:45 -04:00
|
|
|
|
2018-05-26 15:34:41 -04:00
|
|
|
badposition.x = 1200
|
|
|
|
badposition.y = (randi()%410) + 50
|
|
|
|
if get_tree().is_network_server():
|
2018-05-27 02:20:51 -04:00
|
|
|
rpc("spawnBad", bad_type, badposition, bad_health_multi)
|
2018-05-26 15:34:41 -04:00
|
|
|
else:
|
2018-05-27 02:20:51 -04:00
|
|
|
spawnBad(bad_type, badposition, bad_health_multi)
|
2018-05-23 01:40:45 -04:00
|
|
|
else:
|
2018-05-27 19:22:11 -04:00
|
|
|
bads_this_round = 0
|
2018-05-23 01:40:45 -04:00
|
|
|
|
2018-05-27 19:22:11 -04:00
|
|
|
sync func spawnBad(bad_type, position, health_multi):
|
2018-05-26 15:34:41 -04:00
|
|
|
var bad
|
|
|
|
if bad_type == 0:
|
|
|
|
bad = FirstBad.instance()
|
|
|
|
if bad_type == 1:
|
|
|
|
bad = BlobBad.instance()
|
|
|
|
if bad_type == 2:
|
|
|
|
bad = LaserBad.instance()
|
2018-05-27 19:22:11 -04:00
|
|
|
|
|
|
|
total_bads_spawned += 1
|
|
|
|
|
2018-05-26 15:34:41 -04:00
|
|
|
add_child(bad)
|
|
|
|
bad.connect("dead", self, "_on_bad_death")
|
2018-05-27 02:20:51 -04:00
|
|
|
bad.health_multi = health_multi
|
2018-05-26 15:34:41 -04:00
|
|
|
bad.position = position
|
|
|
|
|
2018-05-23 01:40:45 -04:00
|
|
|
func _on_PauseButton_pressed():
|
2018-05-23 11:02:52 -04:00
|
|
|
$Player.upgradeMenu()
|
2018-05-23 03:57:15 -04:00
|
|
|
|
|
|
|
func updatePoints():
|
|
|
|
$MoneyDisplay.text = str($Player.money, " points")
|
|
|
|
|
2018-05-23 11:02:52 -04:00
|
|
|
func _on_Player_update_display():
|
2018-05-23 21:35:16 -04:00
|
|
|
updatePoints()
|
|
|
|
|
|
|
|
func _on_Mothership_game_over():
|
2018-05-26 02:55:17 -04:00
|
|
|
$ShootButton.visible = false
|
2018-05-23 21:35:16 -04:00
|
|
|
$Player.gameOver()
|
|
|
|
|
|
|
|
func _on_Player_restart_game():
|
|
|
|
for child in self.get_children():
|
|
|
|
if (child.has_method("_on_Visibility_screen_exited")):
|
|
|
|
child.queue_free()
|
2018-05-27 19:22:11 -04:00
|
|
|
bads_this_round = 0
|
2018-05-23 21:35:16 -04:00
|
|
|
$BaddieTimer.wait_time = BADDIE_WAIT_TIME_DEFAULT
|
2018-05-26 02:55:17 -04:00
|
|
|
$ShootButton.visible = true
|
|
|
|
|
|
|
|
var touchy_feely
|
|
|
|
|
|
|
|
var touchscreen_on = false
|
|
|
|
func _input(event):
|
|
|
|
if (event is InputEventScreenTouch || event is InputEventScreenDrag):
|
|
|
|
touchscreen_on = true
|
|
|
|
if event.position.x < 800: #&& (abs (event.position.y - $Player.position.y) < 100) :
|
|
|
|
$Player.position.x = event.position.x + 100*(event.position.x/800)
|
|
|
|
$Player.position.y = event.position.y - 100
|
|
|
|
prints(event.index)
|
|
|
|
else:
|
2018-05-26 04:15:20 -04:00
|
|
|
touchy_shooty = true
|
|
|
|
|
2018-05-27 02:20:51 -04:00
|
|
|
func other_shooting_upgrade(id, other_bullet_delay):
|
|
|
|
prints("Other player shooting speed upgrade")
|
2018-05-29 00:08:30 -04:00
|
|
|
get_node(str(id)).timer.set_wait_time(other_bullet_delay)
|
|
|
|
|
|
|
|
func other_ship_color_change(id, other_color):
|
|
|
|
prints("Other player color change")
|
|
|
|
get_node(str(id)).modulate(other_color)
|
2018-05-27 02:20:51 -04:00
|
|
|
|
2018-05-29 02:39:43 -04:00
|
|
|
func double_laser_upgrade(id):
|
|
|
|
prints("Double laser upgrade for", id)
|
|
|
|
get_node(str(id)).double_laser = true
|
|
|
|
|
2018-05-29 00:08:30 -04:00
|
|
|
# Show other player's movement
|
2018-05-26 04:15:20 -04:00
|
|
|
func _on_Player_multiplayer_movement(id, position, is_shooting):
|
2018-05-29 00:08:30 -04:00
|
|
|
get_node(str(id)).position = position
|
|
|
|
#prints("Set position of", id, "( currently", get_node(str(id)).position, ") to", position)
|
|
|
|
|
2018-05-26 04:15:20 -04:00
|
|
|
if is_shooting:
|
2018-05-29 00:08:30 -04:00
|
|
|
get_node(str(id)).shoot()
|
2018-05-27 19:22:11 -04:00
|
|
|
|
2018-05-29 00:08:30 -04:00
|
|
|
# BOSS MODE #
|
|
|
|
# Disable enemy spawning
|
|
|
|
# Wait a few seconds for enemies to clear
|
|
|
|
# Call for boss launch
|
2018-05-27 19:22:11 -04:00
|
|
|
sync func bossMode():
|
|
|
|
bad_spawning_enabled = false
|
|
|
|
var bosstimer = Timer.new()
|
|
|
|
bosstimer.connect("timeout",self,"_launch_boss")
|
|
|
|
add_child(bosstimer) #to process
|
|
|
|
bosstimer.wait_time = 3 # 15 default
|
|
|
|
bosstimer.one_shot = true
|
|
|
|
bosstimer.start() #to start
|
|
|
|
|
2018-05-29 00:08:30 -04:00
|
|
|
# Spawn the first boss
|
2018-05-27 19:22:11 -04:00
|
|
|
func _launch_boss():
|
|
|
|
var bad
|
|
|
|
bad = RectangleBoss.instance()
|
|
|
|
add_child(bad)
|
2018-05-29 00:08:30 -04:00
|
|
|
|
|
|
|
# Flash screen when signalled
|
2018-05-27 19:22:11 -04:00
|
|
|
bad.connect("flash", self, "_flash_screen")
|
|
|
|
bad.show_behind_parent = true
|
|
|
|
|
2018-05-29 00:08:30 -04:00
|
|
|
# Boss death functions the same as regular death
|
|
|
|
bad.connect("dead", self, "_on_boss_death")
|
|
|
|
|
|
|
|
# Currently same as regular enemy death
|
|
|
|
func _on_boss_death(kill_money):
|
2018-05-29 02:39:43 -04:00
|
|
|
# Give players appropriate money, and restart spawns
|
2018-05-29 00:08:30 -04:00
|
|
|
$Player.money += kill_money
|
2018-05-29 02:39:43 -04:00
|
|
|
bad_spawning_enabled = true
|
2018-05-29 00:08:30 -04:00
|
|
|
|
|
|
|
# Begins screen-flashing process
|
2018-05-27 19:22:11 -04:00
|
|
|
func _flash_screen():
|
|
|
|
prints("_flash_screen")
|
|
|
|
screen_flashing = true
|
|
|
|
rectangle_opacity = 1
|
2018-05-29 00:08:30 -04:00
|
|
|
$ColorRect.visible = true
|
|
|
|
|
|
|
|
func _load_players(id, info):
|
|
|
|
player_info = info
|
|
|
|
#prints(player_info)
|
|
|
|
#prints(player_info[id].name, "YEET", player_info[id].color)
|
|
|
|
|
|
|
|
func _start_multiplayer_game():
|
|
|
|
mainmenu.now_quitting = true
|
|
|
|
for peer_id in player_info:
|
|
|
|
if peer_id != get_tree().get_network_unique_id():
|
|
|
|
var player = preload("res://OtherPlayer.tscn").instance()
|
|
|
|
player.set_name(str(peer_id))
|
|
|
|
prints(str(peer_id), "yeetert")
|
|
|
|
add_child(player)
|
|
|
|
#get_node("/").add_child(player)
|
|
|
|
player.setUsername(player_info[peer_id].name)
|