From eddcd6d3885197176ef56d7ad8ee4dc647e36095 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Tue, 29 May 2018 02:39:43 -0400 Subject: [PATCH] More multiplayer work. Colors, usernames, and upgrades should be pretty set for the current system. Double lasers now available in upgrade menu --- Main.gd | 9 +++++++-- Main.tscn | 4 ++++ Mothership.gd | 32 ++++++++++---------------------- Networking.gd | 6 +++++- Networking.tscn | 2 +- Player.gd | 15 ++++++++++++++- UpgradeMenu.gd | 5 +++++ UpgradeMenu.tscn | 38 +++++++++++++++++++++++++++++++++++++- 8 files changed, 83 insertions(+), 28 deletions(-) diff --git a/Main.gd b/Main.gd index c6c1776..d50bc10 100644 --- a/Main.gd +++ b/Main.gd @@ -35,7 +35,7 @@ var rectangle_opacity = 1 var bad_spawning_enabled = true var player_info var touchy_shooty = false -var my_info = { name = "sagethesagesage", color = "D2691E" } +var my_info = { name = "sagethesagesage", color = "FFFFFF" } var mainmenu const BADDIE_WAIT_TIME_DEFAULT = 5 @@ -217,6 +217,10 @@ func other_ship_color_change(id, other_color): prints("Other player color change") get_node(str(id)).modulate(other_color) +func double_laser_upgrade(id): + prints("Double laser upgrade for", id) + get_node(str(id)).double_laser = true + # Show other player's movement func _on_Player_multiplayer_movement(id, position, is_shooting): get_node(str(id)).position = position @@ -253,8 +257,9 @@ func _launch_boss(): # Currently same as regular enemy death func _on_boss_death(kill_money): - # Give players appropriate money + # Give players appropriate money, and restart spawns $Player.money += kill_money + bad_spawning_enabled = true # Begins screen-flashing process func _flash_screen(): diff --git a/Main.tscn b/Main.tscn index d30366d..14f6aa3 100644 --- a/Main.tscn +++ b/Main.tscn @@ -39,6 +39,7 @@ RectangleBoss = ExtResource( 5 ) [node name="Sprite" type="Sprite" parent="." index="0"] +editor/display_folded = true z_index = -5 texture = SubResource( 1 ) _sections_unfolded = [ "Z Index" ] @@ -59,6 +60,7 @@ autostart = false [node name="Mothership" parent="." index="3" instance=ExtResource( 8 )] +editor/display_folded = true position = Vector2( 18.327, 304.835 ) [node name="Line2D" type="Line2D" parent="Mothership" index="2"] @@ -178,6 +180,8 @@ _sections_unfolded = [ "Visibility" ] [connection signal="body_entered" from="Player" to="Player" method="_on_Player_body_entered"] +[connection signal="double_laser_upgrade" from="Player" to="." method="double_laser_upgrade"] + [connection signal="multiplayer_movement" from="Player" to="." method="_on_Player_multiplayer_movement"] [connection signal="other_ship_color_change" from="Player" to="." method="other_ship_color_change"] diff --git a/Mothership.gd b/Mothership.gd index 11c617a..6192bcf 100644 --- a/Mothership.gd +++ b/Mothership.gd @@ -19,6 +19,8 @@ extends Area2D +slave var slave_health + signal game_over export (PackedScene) var Laser # class member variables go here, for example: @@ -44,30 +46,16 @@ func _ready(): # add_child(timer) func _process(delta): - pass - -# # Called every frame. Delta is time since last frame. -# # Update game logic here. -# pass - - - -#func _on_GunAimNode_area_entered(area): -# for i in range(20): -# #var laser = Laser.instance() -# #get_node("../").add_child(laser) -# #laser.position.y = position.y - 27 -# #laser.position.x = position.x + 46 -# 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 -# can_shoot = false -# timer.start() + if get_tree().has_network_peer() && not get_tree().is_network_server(): + #health = slave_health + pass func _on_Mothership_area_shape_entered(area_id, area, area_shape, self_shape): - health -= 50 + if not get_tree().has_network_peer(): + health -= 50 + if get_tree().is_network_server(): + health -= 50 + rset("slave_health", health) prints(health) var health_bar = Vector2(((health * (.8)) + 100), 200) $Line2D.set_point_position( 1, health_bar ) diff --git a/Networking.gd b/Networking.gd index 43c1ff1..3b5dab5 100644 --- a/Networking.gd +++ b/Networking.gd @@ -26,7 +26,7 @@ var my_ip var peer var player_info = {} var incoming_name -var my_info = { name = "", color = "green" } +var my_info = { name = "", color = "FFFFFF" } var server_ip var test_id @@ -148,6 +148,8 @@ func _on_BackToMain_pressed(): $ServerAcceptIcon.visible = false $EnterIP.visible = false $ConnectTo.visible = false + $UsernameLabel.visible = false + $Lobby/RichTextLabel.visible = false func _on_UsernameEntry_text_changed(new_text): my_info = {name = new_text, color = my_info.color} @@ -175,6 +177,8 @@ func startGame(): rpc("yeeper") sync func yeeper(): + $BackToMain.visible = false + $BackIcon.visible = false _on_BackToMain_pressed() emit_signal("start_multiplayer_game") $StartGame.visible = false \ No newline at end of file diff --git a/Networking.tscn b/Networking.tscn index 71bbe74..1df5cfb 100644 --- a/Networking.tscn +++ b/Networking.tscn @@ -99,7 +99,7 @@ animations = [ { "speed": 5.0 } ] -[node name="Networking" type="Node"] +[node name="Networking" type="Node" index="0"] pause_mode = 2 script = ExtResource( 1 ) diff --git a/Player.gd b/Player.gd index ae85e53..3e89b7e 100644 --- a/Player.gd +++ b/Player.gd @@ -26,6 +26,7 @@ signal shooting_speed_upgrade # signals that a shooting speed upgrade has occure signal ship_speed_upgrade signal other_shooting_upgrade signal other_ship_speed_upgrade +signal double_laser_upgrade signal other_ship_color_change signal shooting_speed_fully_upgraded signal ship_speed_fully_upgraded @@ -57,6 +58,9 @@ const BULLET_DELAY_TIER3_COST = 200 const BULLET_DELAY_TIER4_COST = 400 const BULLET_DELAY_TIER5_COST = 1000 +# double laser cost +const DOUBLE_LASER_COST = 20 + # the 5 tiers of ship speed const SHIP_SPEED_TIER1 = 150 const SHIP_SPEED_TIER2 = 200 @@ -213,6 +217,7 @@ func upgradeBulletDelay(): # upgrades the speed at which the ship moves # not relevant for touchscreen users +# may be deprecated func upgradeShipSpeed(): prints("func upgradeShipSpeed():") if (ship_speed == SHIP_SPEED_TIER1 && money >= SHIP_SPEED_TIER2_COST): @@ -238,6 +243,12 @@ func upgradeShipSpeed(): prints(ship_speed) +func doubleLaserUpgrade(): + if money >= DOUBLE_LASER_COST: + money -= DOUBLE_LASER_COST + double_laser = true + rpc("double_laser_upgrade", get_tree().get_network_unique_id()) + ###################### func _ready(): @@ -306,6 +317,8 @@ remote func other_shooting_speed_upgrade(id, bullet_delay): remote func _change_color(id, color): emit_signal("other_ship_color_change", id, color) +remote func double_laser_upgrade(id): + emit_signal("double_laser_upgrade", id) # the player's movement vector var velocity = Vector2() @@ -337,7 +350,7 @@ func _process(delta): # if in multiplayer mode, push position and shooting status as often as possible if get_tree().has_network_peer(): - rpc_unreliable("move_player", get_tree().get_network_unique_id(), position, is_shooting) + rpc("move_player", get_tree().get_network_unique_id(), position, is_shooting) # if shoot button is pressed, try shooting if Input.is_action_pressed("ui_accept"): diff --git a/UpgradeMenu.gd b/UpgradeMenu.gd index 60051c8..ffdc686 100644 --- a/UpgradeMenu.gd +++ b/UpgradeMenu.gd @@ -23,6 +23,7 @@ signal refund signal speed_upgrade signal bullet_delay_upgrade signal ship_speed_upgrade +signal double_laser_upgrade signal add_laser signal plasma_lasers signal menu_closed @@ -75,6 +76,10 @@ func _on_ShipSpeedUpgrade_pressed(): prints("UPGRADE SHIP SPEED SIGNAL EMITTED") ship_speed_tier = get_parent().ship_speed_tier +func _on_DoubleLaserUpgrade_pressed(): + get_tree().paused = false + emit_signal("double_laser_upgrade") + prints("UPGRADE SHIP SPEED SIGNAL EMITTED") func _on_Goldenrod_pressed(): emit_signal("change_color", "daa520") diff --git a/UpgradeMenu.tscn b/UpgradeMenu.tscn index 67e57af..39dd8b6 100644 --- a/UpgradeMenu.tscn +++ b/UpgradeMenu.tscn @@ -143,6 +143,8 @@ animation = "default" [node name="ShipSpeedUpgrade" type="Node" parent="." index="4"] +editor/display_folded = true + [node name="Button" type="Button" parent="ShipSpeedUpgrade" index="0"] anchor_left = 0.0 @@ -176,6 +178,8 @@ animation = "New Anim" [node name="ColorSelect" type="Node2D" parent="." index="5"] +editor/display_folded = true + [node name="ColorSelectBG" type="Sprite" parent="ColorSelect" index="0"] position = Vector2( 150, 210 ) @@ -398,7 +402,37 @@ group = null flat = true align = 1 -[connection signal="button_down" from="Resume" to="." method="_on_Resume_button_down"] +[node name="DoubleLaserUpgrade" type="Node2D" parent="." index="6"] + +[node name="Button" type="Button" parent="DoubleLaserUpgrade" index="0"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 860.0 +margin_top = 80.0 +margin_right = 1000.0 +margin_bottom = 180.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +focus_mode = 2 +mouse_filter = 0 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 1 +toggle_mode = false +enabled_focus_mode = 2 +shortcut = null +group = null +text = "Double Lasers!" +flat = false +align = 1 + +[node name="Icon" type="AnimatedSprite" parent="DoubleLaserUpgrade" index="1"] + +visible = false +animation = "default" [connection signal="pressed" from="Resume" to="." method="_on_Button_pressed"] @@ -426,4 +460,6 @@ align = 1 [connection signal="pressed" from="ColorSelect/ColorSelectBG/DeepSkyBlue" to="." method="_on_DeepSkyBlue_pressed"] +[connection signal="pressed" from="DoubleLaserUpgrade/Button" to="." method="_on_DoubleLaserUpgrade_pressed"] +