changed folder scructure
2
.gitignore
vendored
@ -2,5 +2,5 @@
|
|||||||
*.pck
|
*.pck
|
||||||
*.x86_64
|
*.x86_64
|
||||||
*.log
|
*.log
|
||||||
/Godot-Multiplayer-Shooter
|
|
||||||
/.import
|
/.import
|
||||||
|
/test
|
||||||
@ -1,3 +0,0 @@
|
|||||||
source_md5="9c64c312fe0c5859c87280aebe19b452"
|
|
||||||
dest_md5="7e50e59190bf14295c7cbedc26ee3b24"
|
|
||||||
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
extends Node2D
|
|
||||||
|
|
||||||
func _ready() -> void:
|
|
||||||
get_tree().connect("network_peer_disconnected", self, "_player_disconnected")
|
|
||||||
|
|
||||||
|
|
||||||
func _player_disconnected(id) -> void:
|
|
||||||
if Players.has_node(str(id)):
|
|
||||||
Players.get_node(str(id)).username_text_instance.queue_free()
|
|
||||||
Players.get_node(str(id)).queue_free()
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
[gd_scene load_steps=3 format=2]
|
|
||||||
|
|
||||||
[ext_resource path="res://scenes/floor.tscn" type="PackedScene" id=1]
|
|
||||||
[ext_resource path="res://code/game.gd" type="Script" id=2]
|
|
||||||
|
|
||||||
[node name="game" type="Node2D"]
|
|
||||||
script = ExtResource( 2 )
|
|
||||||
|
|
||||||
[node name="floor" parent="." instance=ExtResource( 1 )]
|
|
||||||
position = Vector2( 960, 1056 )
|
|
||||||
scale = Vector2( 2, 1 )
|
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
source_md5="ea99925cae38c148dc6a1c29df4fb92e"
|
||||||
|
dest_md5="f73af61b19494ec5bf488ba2a748b42b"
|
||||||
|
|
||||||
9
kristofers/game/code/UI.gd
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
extends CanvasLayer
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
Global.ui = self
|
||||||
|
|
||||||
|
|
||||||
|
func _exit_tree() -> void:
|
||||||
|
Global.ui = null
|
||||||
27
kristofers/game/code/game.gd
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
extends Node2D
|
||||||
|
|
||||||
|
var current_spawn_location_instance_number = 1
|
||||||
|
var current_player_location_instance_number = null
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
get_tree().connect("network_peer_disconnected", self, "_player_disconnected")
|
||||||
|
|
||||||
|
if get_tree().is_network_server():
|
||||||
|
setup_player_positions()
|
||||||
|
|
||||||
|
|
||||||
|
func setup_player_positions() -> void:
|
||||||
|
for player in Players.get_children():
|
||||||
|
if player.is_in_group("player"):
|
||||||
|
for spawn_location in $spawn_locations.get_children():
|
||||||
|
if int(spawn_location.name) == current_spawn_location_instance_number and current_player_location_instance_number != player:
|
||||||
|
player.rpc("update_position", spawn_location.global_position)
|
||||||
|
current_spawn_location_instance_number += 1
|
||||||
|
current_player_location_instance_number = player
|
||||||
|
|
||||||
|
|
||||||
|
func _player_disconnected(id) -> void:
|
||||||
|
if Players.has_node(str(id)):
|
||||||
|
Players.get_node(str(id)).username_text_instance.queue_free()
|
||||||
|
Players.get_node(str(id)).queue_free()
|
||||||
@ -1,5 +1,7 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
var ui = null
|
||||||
|
|
||||||
func instance_node_at_location(node: Object, parent: Object, location: Vector2) -> Object:
|
func instance_node_at_location(node: Object, parent: Object, location: Vector2) -> Object:
|
||||||
var node_instance = instance_node(node, parent)
|
var node_instance = instance_node(node, parent)
|
||||||
node_instance.global_position = location
|
node_instance.global_position = location
|
||||||
@ -39,9 +39,24 @@ func join_server() -> void:
|
|||||||
get_tree().set_network_peer(client)
|
get_tree().set_network_peer(client)
|
||||||
|
|
||||||
|
|
||||||
|
func reset_network_connections():
|
||||||
|
if get_tree().has_network_peer():
|
||||||
|
get_tree().network_peer = null
|
||||||
|
|
||||||
|
|
||||||
func _connected_to_server() -> void:
|
func _connected_to_server() -> void:
|
||||||
print("Successfully connected to the server")
|
print("Successfully connected to the server")
|
||||||
|
|
||||||
|
|
||||||
func _server_disconnected() -> void:
|
func _server_disconnected() -> void:
|
||||||
print("Disconnected from the server")
|
print("Disconnected from the server")
|
||||||
|
|
||||||
|
for child in Players.get_children():
|
||||||
|
if child.is_in_group("Net"):
|
||||||
|
child.queue_free()
|
||||||
|
|
||||||
|
reset_network_connections()
|
||||||
|
|
||||||
|
if Global.ui != null:
|
||||||
|
var prompt = Global.instance_node(load("res://scenes/simple_prompt.tscn"), Global.ui)
|
||||||
|
prompt.set_text("Disconnected from server")
|
||||||
@ -4,8 +4,8 @@ var player = load("res://scenes/player.tscn")
|
|||||||
|
|
||||||
onready var multiplayer_config_ui = $multiplayer_configure
|
onready var multiplayer_config_ui = $multiplayer_configure
|
||||||
onready var username_text_edit = $multiplayer_configure/username_text_edit
|
onready var username_text_edit = $multiplayer_configure/username_text_edit
|
||||||
onready var device_ip_address = $CanvasLayer/device_ip_address
|
onready var device_ip_address = $UI/device_ip_address
|
||||||
onready var start_game = $CanvasLayer/start_game
|
onready var start_game = $UI/start_game
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
10
kristofers/game/code/simple_prompt.gd
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
extends Control
|
||||||
|
|
||||||
|
|
||||||
|
func _on_ok_pressed():
|
||||||
|
get_tree().change_scene("res://scenes/main_menu.tscn")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func set_text(text) -> void:
|
||||||
|
$Label.text = text
|
||||||
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
@ -10,7 +10,7 @@ config_version=4
|
|||||||
|
|
||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Game #4"
|
config/name="Game_4"
|
||||||
run/main_scene="res://scenes/main_menu.tscn"
|
run/main_scene="res://scenes/main_menu.tscn"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
25
kristofers/game/scenes/game.tscn
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
[gd_scene load_steps=3 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://scenes/floor.tscn" type="PackedScene" id=1]
|
||||||
|
[ext_resource path="res://code/game.gd" type="Script" id=2]
|
||||||
|
|
||||||
|
[node name="game" type="Node2D"]
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="floor" parent="." instance=ExtResource( 1 )]
|
||||||
|
position = Vector2( 960, 1056 )
|
||||||
|
scale = Vector2( 2, 1 )
|
||||||
|
|
||||||
|
[node name="spawn_locations" type="Node" parent="."]
|
||||||
|
|
||||||
|
[node name="1" type="Position2D" parent="spawn_locations"]
|
||||||
|
position = Vector2( 512, 810 )
|
||||||
|
|
||||||
|
[node name="2" type="Position2D" parent="spawn_locations"]
|
||||||
|
position = Vector2( 1408, 810 )
|
||||||
|
|
||||||
|
[node name="3" type="Position2D" parent="spawn_locations"]
|
||||||
|
position = Vector2( 512, 270 )
|
||||||
|
|
||||||
|
[node name="4" type="Position2D" parent="spawn_locations"]
|
||||||
|
position = Vector2( 1408, 270 )
|
||||||
@ -1,7 +1,8 @@
|
|||||||
[gd_scene load_steps=3 format=2]
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://font/roboto.tres" type="DynamicFont" id=1]
|
[ext_resource path="res://font/roboto.tres" type="DynamicFont" id=1]
|
||||||
[ext_resource path="res://code/network_setup.gd" type="Script" id=2]
|
[ext_resource path="res://code/network_setup.gd" type="Script" id=2]
|
||||||
|
[ext_resource path="res://code/UI.gd" type="Script" id=3]
|
||||||
|
|
||||||
[node name="network_setup" type="Control"]
|
[node name="network_setup" type="Control"]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
@ -62,9 +63,10 @@ __meta__ = {
|
|||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
[node name="UI" type="CanvasLayer" parent="."]
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="start_game" type="Button" parent="CanvasLayer"]
|
[node name="start_game" type="Button" parent="UI"]
|
||||||
margin_left = 27.0
|
margin_left = 27.0
|
||||||
margin_top = 27.0
|
margin_top = 27.0
|
||||||
margin_right = 391.0
|
margin_right = 391.0
|
||||||
@ -75,7 +77,7 @@ __meta__ = {
|
|||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="device_ip_address" type="Label" parent="CanvasLayer"]
|
[node name="device_ip_address" type="Label" parent="UI"]
|
||||||
anchor_top = 1.0
|
anchor_top = 1.0
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
@ -89,4 +91,4 @@ __meta__ = {
|
|||||||
|
|
||||||
[connection signal="pressed" from="multiplayer_configure/create_server" to="." method="_on_create_server_pressed"]
|
[connection signal="pressed" from="multiplayer_configure/create_server" to="." method="_on_create_server_pressed"]
|
||||||
[connection signal="pressed" from="multiplayer_configure/join_server" to="." method="_on_join_server_pressed"]
|
[connection signal="pressed" from="multiplayer_configure/join_server" to="." method="_on_join_server_pressed"]
|
||||||
[connection signal="pressed" from="CanvasLayer/start_game" to="." method="_on_start_game_pressed"]
|
[connection signal="pressed" from="UI/start_game" to="." method="_on_start_game_pressed"]
|
||||||
68
kristofers/game/scenes/simple_prompt.tscn
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
[gd_scene load_steps=5 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://font/Roboto-Regular.ttf" type="DynamicFontData" id=1]
|
||||||
|
[ext_resource path="res://code/simple_prompt.gd" type="Script" id=2]
|
||||||
|
|
||||||
|
[sub_resource type="DynamicFont" id=1]
|
||||||
|
size = 100
|
||||||
|
use_mipmaps = true
|
||||||
|
use_filter = true
|
||||||
|
font_data = ExtResource( 1 )
|
||||||
|
|
||||||
|
[sub_resource type="DynamicFont" id=2]
|
||||||
|
size = 100
|
||||||
|
use_mipmaps = true
|
||||||
|
use_filter = true
|
||||||
|
font_data = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="simple_prompt" type="Control"]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Panel" type="Panel" parent="."]
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
margin_left = -704.0
|
||||||
|
margin_top = -330.0
|
||||||
|
margin_right = 704.0
|
||||||
|
margin_bottom = 330.0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="ok" type="Button" parent="Panel"]
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
margin_left = -257.0
|
||||||
|
margin_top = -310.0
|
||||||
|
margin_right = 257.0
|
||||||
|
margin_bottom = -113.0
|
||||||
|
custom_fonts/font = SubResource( 1 )
|
||||||
|
text = "OK"
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="."]
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
margin_left = -516.0
|
||||||
|
margin_top = -155.5
|
||||||
|
margin_right = 516.0
|
||||||
|
margin_bottom = -68.5
|
||||||
|
custom_fonts/font = SubResource( 2 )
|
||||||
|
text = "Simple prompt"
|
||||||
|
align = 1
|
||||||
|
valign = 1
|
||||||
|
|
||||||
|
[connection signal="pressed" from="Panel/ok" to="." method="_on_ok_pressed"]
|
||||||
@ -25,9 +25,9 @@
|
|||||||
showgrid="false"
|
showgrid="false"
|
||||||
width="7256.6929px"
|
width="7256.6929px"
|
||||||
units="px"
|
units="px"
|
||||||
inkscape:zoom="1.1224747"
|
inkscape:zoom="0.14030934"
|
||||||
inkscape:cx="959.93251"
|
inkscape:cx="416.9359"
|
||||||
inkscape:cy="109.5793"
|
inkscape:cy="1297.1339"
|
||||||
inkscape:window-width="1920"
|
inkscape:window-width="1920"
|
||||||
inkscape:window-height="1006"
|
inkscape:window-height="1006"
|
||||||
inkscape:window-x="1920"
|
inkscape:window-x="1920"
|
||||||
@ -41,7 +41,7 @@
|
|||||||
inkscape:groupmode="layer"
|
inkscape:groupmode="layer"
|
||||||
id="layer1">
|
id="layer1">
|
||||||
<rect
|
<rect
|
||||||
style="fill:#008000;stroke-width:0.259237"
|
style="fill:#b4cffa;stroke-width:0.259237;fill-opacity:1"
|
||||||
id="rect31"
|
id="rect31"
|
||||||
width="508"
|
width="508"
|
||||||
height="12.7"
|
height="12.7"
|
||||||
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
@ -10,7 +10,7 @@ config_version=4
|
|||||||
|
|
||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Game #1"
|
config/name="Game_1"
|
||||||
run/main_scene="res://Main.tscn"
|
run/main_scene="res://Main.tscn"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||