Added scene switching capabilities and player placement

pull/1/head
DAMO238 2020-03-01 23:18:15 +00:00
parent 00ef404d91
commit 7ab9f07fde
9 changed files with 171 additions and 34 deletions

11
Scenes/Arena.tscn Normal file
View File

@ -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 )

32
Scenes/Lobby.tscn Normal file
View File

@ -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
}

14
Scenes/Player.tscn Normal file
View File

@ -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

View File

@ -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"]

16
Scripts/Arena.gd Normal file
View File

@ -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()

16
Scripts/Camera.gd Normal file
View File

@ -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))

4
Scripts/Player.gd Normal file
View File

@ -0,0 +1,4 @@
extends Spatial

View File

@ -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...')

View File

@ -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]