210 lines
5.3 KiB
GDScript
210 lines
5.3 KiB
GDScript
extends Node
|
|
|
|
export (PackedScene) var FirstBad
|
|
export (PackedScene) var BlobBad
|
|
export (PackedScene) var LaserBad
|
|
export (PackedScene) var RectangleBoss
|
|
|
|
var position = Vector2(200, 200)
|
|
var bads_this_round = 0
|
|
var upgrade_cost = 50
|
|
var booting = true
|
|
var rectangle_opacity = 1
|
|
var bad_spawning_enabled = true
|
|
var screen_flashing = false
|
|
|
|
const BADDIE_WAIT_TIME_DEFAULT = 5
|
|
|
|
func _ready():
|
|
$ColorRect.visible = true
|
|
var mainmenu = preload("res://MainMenu.tscn").instance()
|
|
add_child(mainmenu)
|
|
mainmenu.connect("multiplayer_menu", self, "_open_multiplayer_menu")
|
|
get_tree().paused = true
|
|
$BaddieTimer.wait_time = BADDIE_WAIT_TIME_DEFAULT
|
|
$BaddieTimer.start()
|
|
randomize()
|
|
updatePoints()
|
|
|
|
var touchy_shooty = false
|
|
|
|
func _open_multiplayer_menu():
|
|
var multiplayer = preload("res://Networking.tscn").instance()
|
|
add_child(multiplayer)
|
|
get_tree().paused = true
|
|
|
|
func _process(delta):
|
|
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()
|
|
if (Input.is_action_pressed("ui_quit")):
|
|
get_tree().quit()
|
|
updatePoints()
|
|
|
|
if get_tree().has_network_peer():
|
|
if !get_tree().is_network_server():
|
|
$BaddieTimer.stop()
|
|
|
|
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()
|
|
|
|
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
|
|
|
|
if screen_flashing == true:
|
|
prints("screen_flashing == true", rectangle_opacity)
|
|
$ColorRect.color = Color(1, 1, 1, rectangle_opacity)
|
|
rectangle_opacity -= delta/4
|
|
if rectangle_opacity <= 0:
|
|
screen_flashing = false
|
|
$ColorRect.visible = false
|
|
|
|
if total_bads_spawned == 100:
|
|
bossMode()
|
|
|
|
func _on_bad_death(kill_money):
|
|
$Player.money += kill_money
|
|
updatePoints()
|
|
|
|
var a_round_of_bads = 20
|
|
var sendblob = 1
|
|
var bad_health_multi = 1
|
|
var total_bads_spawned = 0
|
|
func BaddieTimer():
|
|
if total_bads_spawned == 5:
|
|
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:
|
|
var bad_type
|
|
var badposition = Vector2()
|
|
if sendblob%20 == 0:
|
|
bad_type = 2
|
|
sendblob += 1
|
|
elif sendblob%5 == 0:
|
|
bad_type = 1
|
|
sendblob += 1
|
|
else:
|
|
bad_type = 0
|
|
sendblob += 1
|
|
|
|
bads_this_round += 1
|
|
if $BaddieTimer.wait_time > 0.5:
|
|
$BaddieTimer.wait_time = $BaddieTimer.wait_time * 0.975
|
|
if bads_this_round == a_round_of_bads:
|
|
bad_health_multi *= 1.5
|
|
|
|
badposition.x = 1200
|
|
badposition.y = (randi()%410) + 50
|
|
if get_tree().is_network_server():
|
|
rpc("spawnBad", bad_type, badposition, bad_health_multi)
|
|
else:
|
|
spawnBad(bad_type, badposition, bad_health_multi)
|
|
else:
|
|
bads_this_round = 0
|
|
|
|
sync func spawnBad(bad_type, position, health_multi):
|
|
var bad
|
|
if bad_type == 0:
|
|
bad = FirstBad.instance()
|
|
if bad_type == 1:
|
|
bad = BlobBad.instance()
|
|
if bad_type == 2:
|
|
bad = LaserBad.instance()
|
|
|
|
total_bads_spawned += 1
|
|
|
|
add_child(bad)
|
|
bad.connect("dead", self, "_on_bad_death")
|
|
bad.health_multi = health_multi
|
|
bad.position = position
|
|
|
|
func _on_PauseButton_pressed():
|
|
$Player.upgradeMenu()
|
|
|
|
func updatePoints():
|
|
$MoneyDisplay.text = str($Player.money, " points")
|
|
|
|
func _on_Player_update_display():
|
|
updatePoints()
|
|
|
|
func _on_Mothership_game_over():
|
|
$ShootButton.visible = false
|
|
$Player.gameOver()
|
|
|
|
func _on_Player_restart_game():
|
|
for child in self.get_children():
|
|
if (child.has_method("_on_Visibility_screen_exited")):
|
|
child.queue_free()
|
|
bads_this_round = 0
|
|
$BaddieTimer.wait_time = BADDIE_WAIT_TIME_DEFAULT
|
|
$ShootButton.visible = true
|
|
|
|
var touchy_feely
|
|
|
|
#func _input(event):
|
|
# if (event is InputEventScreenTouch || event is InputEventScreenDrag):
|
|
# if event.position.x < 800:
|
|
# touchy_feely = event
|
|
# prints(event.index)
|
|
# else:
|
|
# touchy_shooty = true
|
|
#
|
|
|
|
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:
|
|
touchy_shooty = true
|
|
|
|
func other_shooting_upgrade(id, other_bullet_delay):
|
|
prints("Other player shooting speed upgrade")
|
|
$OtherPlayer.timer.set_wait_time(other_bullet_delay)
|
|
|
|
func _on_Player_multiplayer_movement(id, position, is_shooting):
|
|
$OtherPlayer.visible = true
|
|
$OtherPlayer.username = str(id)
|
|
$OtherPlayer.position = position
|
|
if is_shooting:
|
|
$OtherPlayer.shoot()
|
|
|
|
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
|
|
|
|
func _launch_boss():
|
|
var bad
|
|
bad = RectangleBoss.instance()
|
|
add_child(bad)
|
|
bad.connect("flash", self, "_flash_screen")
|
|
bad.show_behind_parent = true
|
|
bad.connect("dead", self, "_on_bad_death")
|
|
|
|
func _flash_screen():
|
|
prints("_flash_screen")
|
|
screen_flashing = true
|
|
rectangle_opacity = 1
|
|
$ColorRect.visible = true |