diff --git a/Scenes/Arena.tscn b/Scenes/Arena.tscn new file mode 100644 index 0000000..49a9ac6 --- /dev/null +++ b/Scenes/Arena.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Scripts/Arena.gd" type="Script" id=1] +[ext_resource path="res://Scripts/Camera.gd" type="Script" id=2] + +[node name="Arena" type="Spatial"] +script = ExtResource( 1 ) + +[node name="Camera" type="Camera" parent="."] +transform = Transform( 1, 0, 0, 0, 0.942566, 0.334021, 0, -0.334021, 0.942566, 0, 0.462908, 1.26081 ) +script = ExtResource( 2 ) diff --git a/Scenes/Lobby.tscn b/Scenes/Lobby.tscn new file mode 100644 index 0000000..a027c0a --- /dev/null +++ b/Scenes/Lobby.tscn @@ -0,0 +1,32 @@ +[gd_scene format=2] + +[node name="Lobby" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="IPLineEdit" type="LineEdit" parent="."] +anchor_left = 0.5 +anchor_top = 0.3 +anchor_right = 0.5 +anchor_bottom = 0.3 +margin_left = -100.0 +margin_right = 100.0 +margin_bottom = 25.0 +placeholder_text = "Enter IP Address of Server" + +[node name="StartButton" type="Button" parent="."] +anchor_left = 0.5 +anchor_top = 0.3 +anchor_right = 0.5 +anchor_bottom = 0.3 +margin_left = -40.0 +margin_top = 40.0 +margin_right = 40.0 +margin_bottom = 25.0 +text = "Start" +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/Scenes/Player.tscn b/Scenes/Player.tscn new file mode 100644 index 0000000..32730af --- /dev/null +++ b/Scenes/Player.tscn @@ -0,0 +1,14 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Scripts/Player.gd" type="Script" id=1] + +[sub_resource type="CapsuleMesh" id=1] +radius = 0.1 +mid_height = 0.5 + +[node name="Player" type="Spatial"] +script = ExtResource( 1 ) + +[node name="MeshInstance" type="MeshInstance" parent="."] +mesh = SubResource( 1 ) +material/0 = null diff --git a/Scenes/RootNode.tscn b/Scenes/RootNode.tscn index b0e8269..f938b10 100644 --- a/Scenes/RootNode.tscn +++ b/Scenes/RootNode.tscn @@ -1,40 +1,12 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://Scripts/RootNode.gd" type="Script" id=1] +[ext_resource path="res://Scenes/Lobby.tscn" type="PackedScene" id=2] [node name="RootNode" type="Node"] script = ExtResource( 1 ) -[node name="Lobby" type="Control" parent="."] -anchor_right = 1.0 -anchor_bottom = 1.0 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="IPLineEdit" type="LineEdit" parent="Lobby"] -anchor_left = 0.5 -anchor_top = 0.3 -anchor_right = 0.5 -anchor_bottom = 0.3 -margin_left = -100.0 -margin_right = 100.0 -margin_bottom = 25.0 -placeholder_text = "Enter IP Address of Server" - -[node name="StartButton" type="Button" parent="Lobby"] -anchor_left = 0.5 -anchor_top = 0.3 -anchor_right = 0.5 -anchor_bottom = 0.3 -margin_left = -40.0 -margin_top = 40.0 -margin_right = 40.0 -margin_bottom = 25.0 -text = "Start" -__meta__ = { -"_edit_use_anchors_": false -} +[node name="Lobby" parent="." instance=ExtResource( 2 )] [node name="ConsoleOutput" type="TextEdit" parent="."] visible = false @@ -46,4 +18,3 @@ caret_moving_by_right_click = false __meta__ = { "_edit_use_anchors_": false } -[connection signal="pressed" from="Lobby/StartButton" to="." method="_on_StartButton_pressed"] diff --git a/Scripts/Arena.gd b/Scripts/Arena.gd new file mode 100644 index 0000000..f4d7ad1 --- /dev/null +++ b/Scripts/Arena.gd @@ -0,0 +1,16 @@ +extends Spatial + + +var players = {} # keys are String, values are Players +const Player = preload("res://Scenes/Player.tscn") + +remote func place_player(player_id : int, position : Vector3, rotation : Vector3) -> void: + get_parent().console_print('Placing player with id: ' + String(player_id)) + var player = Player.instance() + player.translation = position + player.rotation = rotation + add_child(player) + players[player_id] = player + +func init(): + get_parent().arena_ready() diff --git a/Scripts/Camera.gd b/Scripts/Camera.gd new file mode 100644 index 0000000..20a35af --- /dev/null +++ b/Scripts/Camera.gd @@ -0,0 +1,16 @@ +extends Camera + + +func _physics_process(delta : float) -> void: + if Input.is_action_pressed("camera_forward"): + translate(Vector3(0, 0, 1)) + if Input.is_action_pressed("camera_backward"): + translate(Vector3(0, 0, -1)) + if Input.is_action_pressed("camera_strafe_up"): + translate(Vector3(0, 1, 0)) + if Input.is_action_pressed("camera_strafe_down"): + translate(Vector3(0, -1, 0)) + if Input.is_action_pressed("camera_strafe_right"): + translate(Vector3(1, 0, 0)) + if Input.is_action_pressed("camera_strafe_left"): + translate(Vector3(-1, 0, 0)) diff --git a/Scripts/Player.gd b/Scripts/Player.gd new file mode 100644 index 0000000..ea5165f --- /dev/null +++ b/Scripts/Player.gd @@ -0,0 +1,4 @@ +extends Spatial + + + diff --git a/Scripts/RootNode.gd b/Scripts/RootNode.gd index 89b7dca..761b334 100644 --- a/Scripts/RootNode.gd +++ b/Scripts/RootNode.gd @@ -2,13 +2,15 @@ extends Node const PORT : int = 9374 +const Arena = preload("res://Scenes/Arena.tscn") var console_output : TextEdit = null - +var peer : NetworkedMultiplayerENet = null func _ready() -> void: get_tree().connect("connected_to_server", self, "_connected_to_server") get_tree().connect("server_disconnected", self, "_server_disconnected") get_tree().connect("connection_failed", self, "_connection_failed") + $Lobby/StartButton.connect("pressed", self, "_on_StartButton_pressed") console_output = $ConsoleOutput func _process(delta : float) -> void: @@ -44,6 +46,17 @@ func _on_StartButton_pressed() -> void: var button : Button = $Lobby/StartButton var ip_addr : String = $Lobby/IPLineEdit.text button.disabled = true - var peer : NetworkedMultiplayerENet = NetworkedMultiplayerENet.new() + peer = NetworkedMultiplayerENet.new() peer.create_client(ip_addr, PORT) get_tree().set_network_peer(peer) + +func arena_ready() -> void: + rpc_id(1, 'client_ready', peer.get_unique_id()) + +remote func start_game() -> void: + $Lobby.queue_free() + var arena = Arena.instance() + add_child(arena) + arena.init() + console_print('Starting Game...') + diff --git a/project.godot b/project.godot index 0909772..04170c5 100644 --- a/project.godot +++ b/project.godot @@ -79,6 +79,66 @@ toggle_console={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":33554431,"unicode":0,"echo":false,"script":null) ] } +camera_forward={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) + ] +} +camera_backward={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null) + ] +} +camera_strafe_left={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) + ] +} +camera_strafe_right={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null) + ] +} +camera_strafe_up={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":69,"unicode":0,"echo":false,"script":null) + ] +} +camera_strafe_down={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"unicode":0,"echo":false,"script":null) + ] +} +camera_pitch_up={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":75,"unicode":0,"echo":false,"script":null) + ] +} +camera_pitch_down={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":73,"unicode":0,"echo":false,"script":null) + ] +} +camera_roll_right={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":79,"unicode":0,"echo":false,"script":null) + ] +} +camera_roll_left={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":85,"unicode":0,"echo":false,"script":null) + ] +} +camera_yaw_right={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":76,"unicode":0,"echo":false,"script":null) + ] +} +camera_yaw_left={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":74,"unicode":0,"echo":false,"script":null) + ] +} [rendering]