Multiplayer fixes and UI update

This commit is contained in:
Sage Vaillancourt 2018-05-27 02:20:51 -04:00
parent 7a383e432c
commit d9e05e12df
8 changed files with 92 additions and 39 deletions

15
Main.gd
View File

@ -13,6 +13,7 @@ var rectangle_opacity = 1
const BADDIE_WAIT_TIME_DEFAULT = 5 const BADDIE_WAIT_TIME_DEFAULT = 5
func _ready(): func _ready():
$ColorRect.visible = true
var mainmenu = preload("res://MainMenu.tscn").instance() var mainmenu = preload("res://MainMenu.tscn").instance()
add_child(mainmenu) add_child(mainmenu)
mainmenu.connect("multiplayer_menu", self, "_open_multiplayer_menu") mainmenu.connect("multiplayer_menu", self, "_open_multiplayer_menu")
@ -80,20 +81,20 @@ func BaddieTimer():
total_bads_spawned += 1 total_bads_spawned += 1
if $BaddieTimer.wait_time > 0.5: if $BaddieTimer.wait_time > 0.5:
$BaddieTimer.wait_time = $BaddieTimer.wait_time * 0.99 $BaddieTimer.wait_time = $BaddieTimer.wait_time * 0.975
if total_bads_spawned == a_round_of_bads: if total_bads_spawned == a_round_of_bads:
bad_health_multi *= 1.5 bad_health_multi *= 1.5
badposition.x = 1200 badposition.x = 1200
badposition.y = (randi()%410) + 50 badposition.y = (randi()%410) + 50
if get_tree().is_network_server(): if get_tree().is_network_server():
rpc("spawnBad", bad_type, badposition) rpc("spawnBad", bad_type, badposition, bad_health_multi)
else: else:
spawnBad(bad_type, badposition) spawnBad(bad_type, badposition, bad_health_multi)
else: else:
total_bads_spawned = 0 total_bads_spawned = 0
sync func spawnBad(bad_type, position): ### sync func ? sync func spawnBad(bad_type, position, health_multi): ### sync func ?
var bad var bad
if bad_type == 0: if bad_type == 0:
bad = FirstBad.instance() bad = FirstBad.instance()
@ -104,7 +105,7 @@ sync func spawnBad(bad_type, position): ### sync func ?
add_child(bad) add_child(bad)
bad.connect("dead", self, "_on_bad_death") bad.connect("dead", self, "_on_bad_death")
bad.health_multi = bad_health_multi bad.health_multi = health_multi
bad.position = position bad.position = position
func _on_PauseButton_pressed(): func _on_PauseButton_pressed():
@ -150,6 +151,10 @@ func _input(event):
else: else:
touchy_shooty = true 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): func _on_Player_multiplayer_movement(id, position, is_shooting):
$OtherPlayer.visible = true $OtherPlayer.visible = true
$OtherPlayer.username = str(id) $OtherPlayer.username = str(id)

View File

@ -27,7 +27,7 @@ animations = [ {
"speed": 5.0 "speed": 5.0
} ] } ]
[node name="Main" type="Node"] [node name="Main" type="Node" index="0"]
script = ExtResource( 1 ) script = ExtResource( 1 )
_sections_unfolded = [ "Pause" ] _sections_unfolded = [ "Pause" ]
@ -146,6 +146,7 @@ align = 1
[node name="ColorRect" type="ColorRect" parent="." index="7"] [node name="ColorRect" type="ColorRect" parent="." index="7"]
visible = false
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 0.0 anchor_right = 0.0
@ -159,6 +160,7 @@ mouse_default_cursor_shape = 0
size_flags_horizontal = 1 size_flags_horizontal = 1
size_flags_vertical = 1 size_flags_vertical = 1
color = Color( 0, 0, 0, 1 ) color = Color( 0, 0, 0, 1 )
_sections_unfolded = [ "Visibility" ]
[node name="Pause" type="AnimatedSprite" parent="." index="8"] [node name="Pause" type="AnimatedSprite" parent="." index="8"]
@ -176,12 +178,12 @@ _sections_unfolded = [ "Transform", "Visibility" ]
[connection signal="multiplayer_movement" from="Player" to="." method="_on_Player_multiplayer_movement"] [connection signal="multiplayer_movement" from="Player" to="." method="_on_Player_multiplayer_movement"]
[connection signal="other_shooting_upgrade" from="Player" to="." method="other_shooting_upgrade"]
[connection signal="restart_game" from="Player" to="." method="_on_Player_restart_game"] [connection signal="restart_game" from="Player" to="." method="_on_Player_restart_game"]
[connection signal="restart_game" from="Player" to="Mothership" method="_on_Player_restart_game"] [connection signal="restart_game" from="Player" to="Mothership" method="_on_Player_restart_game"]
[connection signal="shooting_speed_upgrade" from="Player" to="." method="_on_Player_shooting_speed_upgrade"]
[connection signal="update_display" from="Player" to="." method="_on_Player_update_display"] [connection signal="update_display" from="Player" to="." method="_on_Player_update_display"]
[connection signal="timeout" from="BaddieTimer" to="." method="BaddieTimer"] [connection signal="timeout" from="BaddieTimer" to="." method="BaddieTimer"]

View File

@ -31,6 +31,9 @@ func _on_Server_pressed():
$EnterIP.visible = false $EnterIP.visible = false
$ServerEntry.visible = false $ServerEntry.visible = false
$ServerAcceptIcon.visible = false $ServerAcceptIcon.visible = false
$ConnectTo.visible = true
$StartServer.visible = false
$Server.visible = false
func _on_Client_pressed(): func _on_Client_pressed():
server_ip = $ServerEntry.text server_ip = $ServerEntry.text
@ -68,6 +71,7 @@ remote func register_player(id, info):
rpc_id(id, "register_player", peer_id, player_info[peer_id]) rpc_id(id, "register_player", peer_id, player_info[peer_id])
prints(player_info[id], id) prints(player_info[id], id)
emit_signal("player_info", player_info) emit_signal("player_info", player_info)
prints(player_info)
# Call function to update lobby UI here # Call function to update lobby UI here
@ -97,6 +101,7 @@ func _on_BackToMain_pressed():
$StartServer.visible = false $StartServer.visible = false
$ServerAcceptIcon.visible = false $ServerAcceptIcon.visible = false
$EnterIP.visible = false $EnterIP.visible = false
$ConnectTo.visible = false
func _on_UsernameEntry_text_changed(new_text): func _on_UsernameEntry_text_changed(new_text):
my_info = {name = new_text, color = my_info.color} my_info = {name = new_text, color = my_info.color}

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=2] [gd_scene load_steps=17 format=2]
[ext_resource path="res://Networking.gd" type="Script" id=1] [ext_resource path="res://Networking.gd" type="Script" id=1]
[ext_resource path="res://art/multiplayer_menu/start_server.png" type="Texture" id=2] [ext_resource path="res://art/multiplayer_menu/start_server.png" type="Texture" id=2]
@ -6,6 +6,7 @@
[ext_resource path="res://art/multiplayer_menu/back.png" type="Texture" id=4] [ext_resource path="res://art/multiplayer_menu/back.png" type="Texture" id=4]
[ext_resource path="res://art/multiplayer_menu/checkmark.png" type="Texture" id=5] [ext_resource path="res://art/multiplayer_menu/checkmark.png" type="Texture" id=5]
[ext_resource path="res://art/multiplayer_menu/enter_ip.png" type="Texture" id=6] [ext_resource path="res://art/multiplayer_menu/enter_ip.png" type="Texture" id=6]
[ext_resource path="res://art/multiplayer_menu/connect_to.png" type="Texture" id=7]
[sub_resource type="BitmapFont" id=1] [sub_resource type="BitmapFont" id=1]
@ -79,7 +80,16 @@ animations = [ {
"speed": 5.0 "speed": 5.0
} ] } ]
[node name="Networking" type="Node" index="0"] [sub_resource type="SpriteFrames" id=9]
animations = [ {
"frames": [ ExtResource( 7 ) ],
"loop": true,
"name": "default",
"speed": 5.0
} ]
[node name="Networking" type="Node"]
pause_mode = 2 pause_mode = 2
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -281,7 +291,6 @@ animation = "default"
[node name="ServerIP" type="Label" parent="." index="9"] [node name="ServerIP" type="Label" parent="." index="9"]
visible = false
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 0.0 anchor_right = 0.0
@ -385,6 +394,14 @@ frames = SubResource( 8 )
animation = "default" animation = "default"
_sections_unfolded = [ "Transform" ] _sections_unfolded = [ "Transform" ]
[node name="ConnectTo" type="AnimatedSprite" parent="." index="16"]
visible = false
position = Vector2( 788.86, 170.073 )
scale = Vector2( 0.553802, 0.553802 )
frames = SubResource( 9 )
animation = "default"
[connection signal="pressed" from="Client" to="." method="_on_Client_pressed"] [connection signal="pressed" from="Client" to="." method="_on_Client_pressed"]
[connection signal="pressed" from="Name" to="." method="_on_Name_pressed"] [connection signal="pressed" from="Name" to="." method="_on_Name_pressed"]

View File

@ -4,7 +4,7 @@
[ext_resource path="res://art/player/Rocket1.png" type="Texture" id=2] [ext_resource path="res://art/player/Rocket1.png" type="Texture" id=2]
[ext_resource path="res://art/player/Rocket2.png" type="Texture" id=3] [ext_resource path="res://art/player/Rocket2.png" type="Texture" id=3]
[sub_resource type="GDScript" id=3] [sub_resource type="GDScript" id=1]
script/source = "extends Area2D script/source = "extends Area2D
@ -129,7 +129,7 @@ func shoot():
timer.start()" timer.start()"
_sections_unfolded = [ "Resource" ] _sections_unfolded = [ "Resource" ]
[sub_resource type="SpriteFrames" id=1] [sub_resource type="SpriteFrames" id=2]
animations = [ { animations = [ {
"frames": [ ExtResource( 2 ), ExtResource( 3 ) ], "frames": [ ExtResource( 2 ), ExtResource( 3 ) ],
@ -138,13 +138,13 @@ animations = [ {
"speed": 15.0 "speed": 15.0
} ] } ]
[sub_resource type="CapsuleShape2D" id=2] [sub_resource type="CapsuleShape2D" id=3]
custom_solver_bias = 0.0 custom_solver_bias = 0.0
radius = 12.8998 radius = 12.8998
height = 40.4125 height = 40.4125
[node name="OtherPlayer" type="Area2D" index="0"] [node name="OtherPlayer" type="Area2D"]
input_pickable = true input_pickable = true
gravity_point = true gravity_point = true
@ -156,7 +156,7 @@ collision_layer = 29
collision_mask = 29 collision_mask = 29
audio_bus_override = false audio_bus_override = false
audio_bus_name = "Master" audio_bus_name = "Master"
script = SubResource( 3 ) script = SubResource( 1 )
Laser = ExtResource( 1 ) Laser = ExtResource( 1 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="." index="0"] [node name="AnimatedSprite" type="AnimatedSprite" parent="." index="0"]
@ -164,14 +164,14 @@ Laser = ExtResource( 1 )
modulate = Color( 0.276855, 0.445152, 0.84375, 1 ) modulate = Color( 0.276855, 0.445152, 0.84375, 1 )
position = Vector2( 1.01175, 7.07602 ) position = Vector2( 1.01175, 7.07602 )
scale = Vector2( 0.2, 0.2 ) scale = Vector2( 0.2, 0.2 )
frames = SubResource( 1 ) frames = SubResource( 2 )
animation = "default" animation = "default"
_sections_unfolded = [ "Visibility" ] _sections_unfolded = [ "Visibility" ]
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="1"] [node name="CollisionShape2D" type="CollisionShape2D" parent="." index="1"]
position = Vector2( 45.5518, -3.09424 ) position = Vector2( 45.5518, -3.09424 )
shape = SubResource( 2 ) shape = SubResource( 3 )
[node name="Username" type="Label" parent="." index="2"] [node name="Username" type="Label" parent="." index="2"]

View File

@ -5,6 +5,8 @@ signal update_display # tells parent to update points display
signal refund # will tell parent a refund is occuring, for 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 shooting_speed_upgrade # signals that a shooting speed upgrade has occured
signal ship_speed_upgrade signal ship_speed_upgrade
signal other_shooting_upgrade
signal other_ship_speed_upgrade
signal shooting_speed_fully_upgraded signal shooting_speed_fully_upgraded
signal ship_speed_fully_upgraded signal ship_speed_fully_upgraded
signal restart_game signal restart_game
@ -62,24 +64,32 @@ var shooting_speed_upgrade = SHOOTING_SPEED_UPGRADE_DEFAULT
var ship_speed_upgrade = SHIP_SPEED_UPGRADE_DEFAULT var ship_speed_upgrade = SHIP_SPEED_UPGRADE_DEFAULT
func upgradeMenu(): func upgradeMenu():
menu_open = true
var upgmenu = preload("res://UpgradeMenu.tscn").instance() var upgmenu = preload("res://UpgradeMenu.tscn").instance()
add_child(upgmenu) add_child(upgmenu)
upgmenu.connect("refund", self, "_refund_button") upgmenu.connect("refund", self, "_refund_button")
upgmenu.connect("bullet_delay_upgrade", self, "upgradeBulletDelay_button") upgmenu.connect("bullet_delay_upgrade", self, "upgradeBulletDelay_button")
upgmenu.connect("ship_speed_upgrade", self, "upgradeShipSpeed_button") upgmenu.connect("ship_speed_upgrade", self, "upgradeShipSpeed_button")
upgmenu.connect("menu_closed", self, "menuClosed")
upgmenu.bullet_delay_tier = bullet_delay_tier upgmenu.bullet_delay_tier = bullet_delay_tier
upgmenu.ship_speed_tier = ship_speed_tier upgmenu.ship_speed_tier = ship_speed_tier
get_tree().paused = true if !get_tree().has_network_peer():
get_tree().paused = true
func menuClosed():
menu_open = false
func upgradeShipSpeed_button(): func upgradeShipSpeed_button():
upgradeShipSpeed() upgradeShipSpeed()
emit_signal("update_display") emit_signal("update_display")
get_tree().paused = true if !get_tree().has_network_peer():
get_tree().paused = true
func upgradeBulletDelay_button(): func upgradeBulletDelay_button():
upgradeBulletDelay() upgradeBulletDelay()
emit_signal("update_display") emit_signal("update_display")
get_tree().paused = true if !get_tree().has_network_peer():
get_tree().paused = true
func upgradeBulletDelay(): func upgradeBulletDelay():
if (bullet_delay == BULLET_DELAY_TIER1 && money >= BULLET_DELAY_TIER2_COST): if (bullet_delay == BULLET_DELAY_TIER1 && money >= BULLET_DELAY_TIER2_COST):
@ -111,7 +121,9 @@ func upgradeBulletDelay():
shooting_speed_upgrade *= 1.1 shooting_speed_upgrade *= 1.1
bullet_delay_tier += 1 bullet_delay_tier += 1
timer.set_wait_time(bullet_delay) timer.set_wait_time(bullet_delay)
prints(bullet_delay)
rpc("other_shooting_speed_upgrade", get_tree().get_network_unique_id(), bullet_delay)
prints("rpc other_shootng_speed_upgrade", get_tree().get_network_unique_id(), bullet_delay)
func upgradeShipSpeed(): func upgradeShipSpeed():
prints("func upgradeShipSpeed():") prints("func upgradeShipSpeed():")
@ -142,6 +154,7 @@ func upgradeShipSpeed():
money -= ship_speed_upgrade money -= ship_speed_upgrade
ship_value += ship_speed_upgrade ship_value += ship_speed_upgrade
ship_speed_upgrade *= 1.1 ship_speed_upgrade *= 1.1
prints(ship_speed) prints(ship_speed)
func _ready(): func _ready():
@ -190,27 +203,32 @@ var y_down = false
var is_shooting var is_shooting
var menu_open = false
func moveto(finger_position): func moveto(finger_position):
if (finger_position.x > position.x && finger_position.x < 800): if !menu_open:
velocity.x += 1 if (finger_position.x > position.x && finger_position.x < 800):
x_up = true velocity.x += 1
if position.x > finger_position.x: x_up = true
velocity.x -= 1 if position.x > finger_position.x:
x_down = true velocity.x -= 1
if (finger_position.y - 100 > position.y && finger_position.x < 800): x_down = true
velocity.y += 1 if (finger_position.y - 100 > position.y && finger_position.x < 800):
y_up = true velocity.y += 1
if (position.y > finger_position.y - 100 && finger_position.x < 800): y_up = true
velocity.y -= 1 if (position.y > finger_position.y - 100 && finger_position.x < 800):
y_down = true velocity.y -= 1
# if (finger_position.x >= 800 && can_shoot): y_down = true
# shoot() # if (finger_position.x >= 800 && can_shoot):
# if get_tree().has_network_peer(): # shoot()
# rpc("move_player", get_tree().get_network_unique_id(), position, ~can_shoot) # if get_tree().has_network_peer():
# rpc("move_player", get_tree().get_network_unique_id(), position, ~can_shoot)
remote func move_player(id, position, is_shooting): remote func move_player(id, position, is_shooting):
emit_signal("multiplayer_movement", id, position, is_shooting) emit_signal("multiplayer_movement", id, position, is_shooting)
remote func other_shooting_speed_upgrade(id, bullet_delay):
emit_signal("other_shooting_upgrade", id, bullet_delay)
var velocity = Vector2() # the player's movement vector var velocity = Vector2() # the player's movement vector
func _process(delta): func _process(delta):
@ -240,7 +258,7 @@ func _process(delta):
is_shooting = true is_shooting = true
if get_tree().has_network_peer(): if get_tree().has_network_peer():
rpc("move_player", get_tree().get_network_unique_id(), position, is_shooting) rpc_unreliable("move_player", get_tree().get_network_unique_id(), position, is_shooting)
if ((Input.is_action_pressed("ui_accept") || shoot_down == true) && can_shoot == true): if ((Input.is_action_pressed("ui_accept") || shoot_down == true) && can_shoot == true):
shoot() shoot()

View File

@ -6,6 +6,7 @@ signal bullet_delay_upgrade
signal ship_speed_upgrade signal ship_speed_upgrade
signal add_laser signal add_laser
signal plasma_lasers signal plasma_lasers
signal menu_closed
var bullet_delay_tier var bullet_delay_tier
var shooting_speed_tier var shooting_speed_tier
@ -17,6 +18,10 @@ func _ready():
$ShootingSpeedUpgrade/Icon.frame = bullet_delay_tier $ShootingSpeedUpgrade/Icon.frame = bullet_delay_tier
ship_speed_tier = get_parent().ship_speed_tier ship_speed_tier = get_parent().ship_speed_tier
$ShipSpeedUpgrade/Icon.frame = ship_speed_tier $ShipSpeedUpgrade/Icon.frame = ship_speed_tier
if get_tree().has_network_peer():
$ColorRect.color = Color(1,1,1,0.5)
else:
$ColorRect.color = Color(1,1,1,0.5)
func _process(delta): func _process(delta):
$ShootingSpeedUpgrade/Icon.frame = bullet_delay_tier $ShootingSpeedUpgrade/Icon.frame = bullet_delay_tier
@ -28,6 +33,7 @@ func _process(delta):
func _on_Button_pressed(): func _on_Button_pressed():
get_tree().paused = false get_tree().paused = false
emit_signal("menu_closed")
queue_free() queue_free()
func _on_Refund_pressed(): func _on_Refund_pressed():

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB