initial commit

This commit is contained in:
2020-05-09 12:45:05 +02:00
commit a3549d357b
46 changed files with 3051 additions and 0 deletions

View File

@ -0,0 +1,45 @@
extends Node
const SERVER_IP = "willipink.eu"
const SERVER_PORT = 14600
onready var _start_button = get_node("Start_button")
onready var _disconnect_button = get_node("Disconnect_button")
var _connected = false
func _ready():
get_tree().connect("connected_to_server", self, "_connected_ok")
initialize_connection()
func initialize_connection():
$Try_to_connect_to_server_timer.start()
connect_to_server()
_start_button.text = "Connecting..."
func connect_to_server():
print("Try to join the server.")
var peer = NetworkedMultiplayerENet.new()
peer.create_client(SERVER_IP, SERVER_PORT)
get_tree().set_network_peer(peer)
func _connected_ok():
$Try_to_connect_to_server_timer.stop()
Player.set_player_id(get_tree().get_network_unique_id())
_connected = true
_start_button.text = "Start"
_start_button.disabled = false
_disconnect_button.text = "Disconnect"
func _on_Try_to_connect_to_server_timer_timeout():
if !_connected:
connect_to_server()
func disconnect_from_server():
get_tree().set_network_peer(null)
func _on_Start_button_pressed():
get_tree().change_scene("res://Scenes/Matchmaking/Lobby/Lobby.tscn")
func _on_Disconnect_button_pressed():
disconnect_from_server()
get_tree().change_scene("res://Scenes/Matchmaking/Menu/Menu.tscn")

View File

@ -0,0 +1,51 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Scenes/Matchmaking/Client/Network_connection.gd" type="Script" id=2]
[node name="Network_connection" type="Node"]
script = ExtResource( 2 )
[node name="Background_image" type="TextureRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 1 )
stretch_mode = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Start_button" type="Button" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -188.5
margin_top = -70.0
margin_right = 188.5
margin_bottom = 70.0
disabled = true
text = "Connecting..."
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Disconnect_button" type="Button" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -188.5
margin_top = 103.958
margin_right = 188.5
margin_bottom = 243.958
text = "Cancel"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Try_to_connect_to_server_timer" type="Timer" parent="."]
wait_time = 2.0
[connection signal="pressed" from="Start_button" to="." method="_on_Start_button_pressed"]
[connection signal="pressed" from="Disconnect_button" to="." method="_on_Disconnect_button_pressed"]
[connection signal="timeout" from="Try_to_connect_to_server_timer" to="." method="_on_Try_to_connect_to_server_timer_timeout"]

View File

@ -0,0 +1,36 @@
extends Spatial
const MOVE_MARGIN = 20
const MOVE_SPEED = 15
const X_BORDER_LIMIT = 8
const X_MAP_OFFSET = 2
const Z_BORDER_LIMIT = 3
const Z_MAP_OFFSET = 1
onready var cam = $Camera
func _process(delta):
var mouse_position = get_viewport().get_mouse_position()
calc_move(mouse_position, delta)
func calc_move(mouse_position, delta):
var screen_size = get_viewport().size
var position = translation
if mouse_position.x < MOVE_MARGIN:
position.x -= MOVE_SPEED * delta
if mouse_position.y < MOVE_MARGIN:
position.z -= MOVE_SPEED * delta
if mouse_position.x > screen_size.x - MOVE_MARGIN:
position.x += MOVE_SPEED * delta
if mouse_position.y > screen_size.y - MOVE_MARGIN:
position.z += MOVE_SPEED * delta
position.x = clamp(position.x, -X_BORDER_LIMIT, X_BORDER_LIMIT + X_MAP_OFFSET)
position.z = clamp(position.z, -Z_BORDER_LIMIT - Z_MAP_OFFSET, Z_BORDER_LIMIT - Z_MAP_OFFSET)
translation = position

View File

@ -0,0 +1,178 @@
extends Spatial
var _current_player_index
var _turn_number
var _round_counter = 0
var _other_players = []
var _map
var _game_started = false
var _ability_left = false
var _previous_hex = null
func _ready():
$GUI/Player_name_panel/HBoxContainer/Player_name.text = Player.get_player_name()
_other_players = NetworkingSync._player_in_same_game_room_list.duplicate()
_other_players.erase([Player.get_player_id(), Player.get_player_name()])
init_game()
fill_player_list()
if Player.is_host():
init_game_state()
NetworkingSync.send_ready_signal()
func init_game():
create_map()
_turn_number = 1
$GUI/Bottom_left_panel/VBoxContainer/HBoxContainer/Turn_indicator.text = str(_turn_number)
func fill_player_list():
for player in _other_players:
add_other_players_to_list(player[1])
func update_player_list():
for child in $GUI/Player_info/VBoxContainer/Player_list.get_children():
child.queue_free()
fill_player_list()
func add_other_players_to_list(player_name):
var player = load("res://Scenes/Matchmaking/Game_room/Player_entry.tscn").instance()
player.set_player_name(player_name)
$GUI/Player_info/VBoxContainer/Player_list.add_child(player)
func create_map():
_map = load("res://Scenes/Matchmaking/Game/Map/Map.tscn").instance()
add_child(_map)
func init_game_state():
yield(NetworkingSync, "all_ready")
var starting_player_index = calculate_stating_player_index()
set_starting_player(starting_player_index)
for player in _other_players:
rpc_id(player[0], "set_starting_player", starting_player_index)
func is_my_turn():
return NetworkingSync._player_in_same_game_room_list[_current_player_index][0] == Player.get_player_id()
func calculate_stating_player_index():
return int(rand_range(0, len(NetworkingSync._player_in_same_game_room_list)))
remote func set_starting_player(starting_player_index):
_current_player_index = starting_player_index
$GUI/Top_panel/Top_panel_container/Player_indicator.text = str(NetworkingSync._player_in_same_game_room_list[_current_player_index][1])
update_current_player()
func update_current_player():
if is_my_turn():
_ability_left = true
_round_counter = 0
_previous_hex = null
$GUI/Bottom_left_panel/VBoxContainer/Next_turn_button.disabled = false
else:
$GUI/Bottom_left_panel/VBoxContainer/Next_turn_button.disabled = true
func _on_Next_turn_button_pressed():
next_turn()
func next_turn():
next_player()
for player in _other_players:
rpc_id(player[0], "next_player")
_turn_number += 1
$GUI/Bottom_left_panel/VBoxContainer/HBoxContainer/Turn_indicator.text = str(_turn_number)
remote func next_player():
_current_player_index = (_current_player_index + 1) % len(NetworkingSync._player_in_same_game_room_list)
$GUI/Top_panel/Top_panel_container/Player_indicator.text = str(NetworkingSync._player_in_same_game_room_list[_current_player_index][1])
update_current_player()
func game_started():
return _game_started
func color_the_hex(hex_node):
for player in _other_players:
rpc_id(player[0], "color_the_hex_to_player_color", hex_node._x, hex_node._y)
color_the_hex_to_player_color(hex_node._x, hex_node._y)
remote func color_the_hex_to_player_color(hex_x, hex_y):
_map._hexes[hex_x][hex_y].set_color(_current_player_index)
func ability_left():
return _ability_left
func get_previous_hex():
return _previous_hex
func try_to_occupy_hex(hex_node):
color_the_hex(hex_node)
occupy_hex(hex_node._x, hex_node._y)
for player in _other_players:
rpc_id(player[0], "occupy_hex", hex_node._x, hex_node._y)
_previous_hex = hex_node
_round_counter += 1
if _round_counter >= _turn_number:
next_turn()
else:
if !hex_node.is_any_neighbour_free():
left_game()
remote func occupy_hex(hex_x, hex_y):
_map._hexes[hex_x][hex_y].occupy_hex()
#func _process(delta):
# if len(_other_players) <= 0 and _game_started:
# end_game(true)
func left_game():
for player in _other_players:
rpc_id(player[0], "player_left", Player.get_player_id(), Player.get_player_name())
end_game(false)
func end_game(is_winning):
if is_winning:
$End_game_panel/Label.text = "You won."
$GUI.visible = false
$End_game_panel.visible = true
remote func player_left(player_id, player_name):
print("Player: " + str(player_id) + " left.")
_other_players.erase([player_id, player_name])
NetworkingSync._player_in_same_game_room_list.erase([player_id, player_name])
update_player_list()
check_for_win()
next_player()
func check_for_win():
if len(_other_players) <= 0:
end_game(true)
func back_to_lobby():
get_tree().change_scene("res://Scenes/Matchmaking/Lobby/Lobby.tscn")
func _on_Back_to_lobby_button_pressed():
back_to_lobby()
func _on_Surrender_button_pressed():
$Menu_panel.visible = false
left_game()
func _input(event):
if Input.is_key_pressed(KEY_ESCAPE) and $Menu_panel.visible:
$Menu_panel.visible = false
elif Input.is_key_pressed(KEY_ESCAPE) and !$Menu_panel.visible:
$Menu_panel.visible = true
func _on_Close_pressed():
$Menu_panel.visible = false

View File

@ -0,0 +1,303 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://Scenes/Matchmaking/Game/Camera_controller/Camera_controller.gd" type="Script" id=2]
[ext_resource path="res://Scenes/Matchmaking/Game/Game_manager.gd" type="Script" id=3]
[ext_resource path="res://Scenes/Matchmaking/Game/Mouse_controller/Mouse_controller.gd" type="Script" id=4]
[node name="Game_manager" type="Spatial"]
script = ExtResource( 3 )
[node name="End_game_panel" type="Control" parent="."]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ColorRect" type="ColorRect" parent="End_game_panel"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 1.22772
margin_right = 1.22778
color = Color( 0.156863, 0.611765, 0.160784, 0.392157 )
[node name="Label" type="Label" parent="End_game_panel"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -223.5
margin_top = -89.0
margin_right = 223.5
margin_bottom = 89.0
text = "You lose"
align = 1
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ColorRect2" type="ColorRect" parent="End_game_panel/Label"]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0, 1, 1, 0.235294 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Back_to_lobby_button" type="Button" parent="End_game_panel"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -183.0
margin_top = 135.815
margin_right = 183.0
margin_bottom = 313.815
text = "Back to lobby"
[node name="GUI" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player_info" type="Control" parent="GUI"]
margin_left = 1650.14
margin_top = 68.4775
margin_right = 1910.14
margin_bottom = 283.477
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ColorRect" type="ColorRect" parent="GUI/Player_info"]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.831373, 0, 0, 0.137255 )
[node name="VBoxContainer" type="VBoxContainer" parent="GUI/Player_info"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="GUI/Player_info/VBoxContainer"]
margin_right = 260.0
margin_bottom = 14.0
size_flags_horizontal = 3
size_flags_vertical = 1
text = "Oponents left:"
align = 1
valign = 1
[node name="Player_list" type="VBoxContainer" parent="GUI/Player_info/VBoxContainer"]
margin_top = 18.0
margin_right = 260.0
margin_bottom = 214.0
size_flags_horizontal = 3
size_flags_vertical = 3
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player_name_panel" type="Control" parent="GUI"]
margin_right = 306.0
margin_bottom = 40.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxContainer" type="HBoxContainer" parent="GUI/Player_name_panel"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player_name_info_laabel" type="Label" parent="GUI/Player_name_panel/HBoxContainer"]
margin_right = 47.0
margin_bottom = 40.0
size_flags_vertical = 3
text = "Player: "
align = 1
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player_name" type="Label" parent="GUI/Player_name_panel/HBoxContainer"]
margin_left = 51.0
margin_right = 306.0
margin_bottom = 40.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Bob"
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Top_panel" type="Control" parent="GUI"]
anchor_left = 0.5
anchor_right = 0.5
margin_left = -960.0
margin_right = 960.0
margin_bottom = 50.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Top_panel_container" type="HBoxContainer" parent="GUI/Top_panel"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 0
size_flags_vertical = 0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player_label" type="Label" parent="GUI/Top_panel/Top_panel_container"]
margin_right = 958.0
margin_bottom = 50.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Turn of:"
align = 2
valign = 1
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Player_indicator" type="Label" parent="GUI/Top_panel/Top_panel_container"]
margin_left = 962.0
margin_right = 1920.0
margin_bottom = 50.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Player 1"
valign = 1
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Bottom_left_panel" type="Control" parent="GUI"]
anchor_top = 0.924074
anchor_right = 0.233333
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": true
}
[node name="VBoxContainer" type="VBoxContainer" parent="GUI/Bottom_left_panel"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 3
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Next_turn_button" type="Button" parent="GUI/Bottom_left_panel/VBoxContainer"]
visible = false
margin_right = 447.0
margin_bottom = 39.0
size_flags_horizontal = 3
size_flags_vertical = 3
disabled = true
text = "Next turn"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxContainer" type="HBoxContainer" parent="GUI/Bottom_left_panel/VBoxContainer"]
margin_right = 447.0
margin_bottom = 82.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="Turn_label" type="Label" parent="GUI/Bottom_left_panel/VBoxContainer/HBoxContainer"]
margin_right = 221.0
margin_bottom = 82.0
size_flags_horizontal = 3
size_flags_vertical = 7
text = "Turn:"
align = 2
valign = 1
[node name="Turn_indicator" type="Label" parent="GUI/Bottom_left_panel/VBoxContainer/HBoxContainer"]
margin_left = 225.0
margin_right = 447.0
margin_bottom = 82.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "1"
valign = 1
[node name="Menu_panel" type="Control" parent="."]
visible = false
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -382.5
margin_top = -186.0
margin_right = 382.5
margin_bottom = 186.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Background" type="ColorRect" parent="Menu_panel"]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.235294, 0.219608, 0.301961, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Surrender_button" type="Button" parent="Menu_panel"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -112.5
margin_top = -77.5851
margin_right = 112.5
margin_bottom = -23.5851
text = "Surrender"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Close" type="Button" parent="Menu_panel"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -112.5
margin_top = 35.5883
margin_right = 112.5
margin_bottom = 89.5883
text = "Close"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Camera_base" type="Spatial" parent="."]
script = ExtResource( 2 )
[node name="Camera" type="Camera" parent="Camera_base"]
transform = Transform( 1, 0, 0, 0, 0.422618, 0.906308, 0, -0.906308, 0.422618, 12, 12, 12 )
[node name="Mouse_controller" type="Spatial" parent="."]
script = ExtResource( 4 )
[connection signal="tree_exited" from="." to="." method="_on_Game_manager_tree_exited"]
[connection signal="pressed" from="End_game_panel/Back_to_lobby_button" to="." method="_on_Back_to_lobby_button_pressed"]
[connection signal="pressed" from="GUI/Bottom_left_panel/VBoxContainer/Next_turn_button" to="." method="_on_Next_turn_button_pressed"]
[connection signal="pressed" from="Menu_panel/Surrender_button" to="." method="_on_Surrender_button_pressed"]
[connection signal="pressed" from="Menu_panel/Close" to="." method="_on_Close_pressed"]

View File

@ -0,0 +1,94 @@
extends Spatial
var _is_free
var _x
var _y
var _neighbours
var _map
func _ready():
_is_free = true
_map = get_node("/root/Game_manager/Map")
func set_coordinates(x, y):
_x = x
_y = y
func _on_Area_input_event(camera, event, click_position, click_normal, shape_idx):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
get_node("/root/Game_manager/Mouse_controller").left_click_on_hex(self)
if event.button_index == BUTTON_RIGHT and event.pressed:
get_node("/root/Game_manager/Mouse_controller").right_click_on_hex(self)
func set_color(color_id):
# TODO: make color better?
var material = SpatialMaterial.new()
material.albedo_color = Color(1, 0, 1)
$Cylinder.set_surface_material(0, material)
func occupy_hex():
_is_free = false
func is_free():
return _is_free
func is_any_neighbour_free():
var is_free = false
for neighbour in get_neighbours():
if neighbour.is_free():
is_free = true
continue
return is_free
func get_neighbours():
if _neighbours == null:
_neighbours = []
# left neighbour
if _x > 0:
_neighbours.append(_map.get_hex_at(_x - 1, _y))
# odd-row, starting below
##########
if _y % 2 == 0:
# top left neighbour if(y%2)
if _x > 0 && _y < _map._map_height - 1:
_neighbours.append(_map.get_hex_at(_x - 1, _y + 1))
# top right neighbour if(y%2)
if _y < _map._map_height - 1:
_neighbours.append(_map.get_hex_at(_x, _y + 1))
# bottom right neighbour if(y%2)
if _y > 0:
_neighbours.append(_map.get_hex_at(_x, _y - 1));
# bottom left neighbour if(y%2)
if _x > 0 && _y > 0:
_neighbours.append(_map.get_hex_at(_x - 1, _y - 1));
##########
else:
# top left neighbour
if _y < _map._map_height - 1:
_neighbours.append(_map.get_hex_at(_x, _y + 1));
# top right neighbour
if _x < _map._map_width - 1 && _y < _map._map_height - 1:
_neighbours.append(_map.get_hex_at(_x + 1, _y + 1))
# bottom right neighbour
if _x < _map._map_width - 1 && _y > 0:
_neighbours.append(_map.get_hex_at(_x + 1, _y - 1))
# bottom left neighbour
if _y > 0:
_neighbours.append(_map.get_hex_at(_x, _y - 1))
##########
## right neighbour
if _x < _map._map_width - 1:
_neighbours.append(_map.get_hex_at(_x + 1, _y))
return _neighbours

View File

@ -0,0 +1,22 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Material/hex.dae" type="PackedScene" id=1]
[ext_resource path="res://Scenes/Matchmaking/Game/Map/Hex.gd" type="Script" id=2]
[sub_resource type="SpatialMaterial" id=1]
albedo_color = Color( 0, 0.27451, 1, 1 )
[sub_resource type="CylinderShape" id=2]
radius = 0.986306
[node name="Hex" instance=ExtResource( 1 )]
script = ExtResource( 2 )
[node name="Cylinder" parent="." index="0"]
material/0 = SubResource( 1 )
[node name="Area" type="Area" parent="Cylinder" index="0"]
[node name="CollisionShape" type="CollisionShape" parent="Cylinder/Area" index="0"]
shape = SubResource( 2 )
[connection signal="input_event" from="Cylinder/Area" to="." method="_on_Area_input_event"]

View File

@ -0,0 +1,49 @@
extends Spatial
export var _map_width = 12
export var _map_height = 8
var _width_offset = 2.0
var _height_offset = 2.0 * 0.75
var gap = 0.1
var _hexes = []
func _ready():
add_gap_between_hexes()
generate_map()
func calculate_world_position(grid_position):
var offset = 0
if int(grid_position.y) % 2 != 0:
offset = _width_offset / 2
var x = grid_position.x * _width_offset + offset
var z = grid_position.y * _height_offset
return Vector3(x, 0, z)
func add_gap_between_hexes():
_width_offset += _width_offset * gap
_height_offset += _height_offset * gap
func generate_map():
for x in range(0, _map_width):
_hexes.append([])
_hexes[x].resize(_map_height)
for y in range(0, _map_height):
var hex_node = load("res://Scenes/Matchmaking/Game/Map/Hex.tscn").instance()
hex_node.set_coordinates(x, y)
var position = (calculate_world_position(Vector2(x,y)))
hex_node.name = "hex_%d_%d" % [x, y]
hex_node.translation = position
add_child(hex_node)
_hexes[x][y] = hex_node
func get_hex_at(x, y):
return _hexes[x][y]

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Matchmaking/Game/Map/Map.gd" type="Script" id=1]
[node name="Map" type="Spatial"]
script = ExtResource( 1 )

View File

@ -0,0 +1,25 @@
extends Spatial
var _game_manager
func _ready():
_game_manager = get_node("/root/Game_manager")
func left_click_on_hex(hex_node):
if _game_manager.is_my_turn():
if _game_manager.ability_left():
if hex_node.is_free():
if _game_manager.get_previous_hex() != null:
print("try to occupy")
if hex_node in _game_manager.get_previous_hex().get_neighbours():
print("Yea")
_game_manager.try_to_occupy_hex(hex_node)
else:
_game_manager.try_to_occupy_hex(hex_node)
func right_click_on_hex(hex_node):
print("Right click")

View File

@ -0,0 +1,66 @@
extends Control
func _ready():
for player_id in NetworkingSync._open_games[Player.get_game_id()][3]:
if player_id != Player.get_player_id():
rpc_id(player_id, "update_game_room_player_list")
update_game_room_player_list()
remote func update_game_room_player_list():
NetworkingSync.send_open_games_request_to_server()
yield(NetworkingSync, "updated_games")
for child in $Player_list/ScrollContainer/Player_list_container.get_children():
child.queue_free()
NetworkingSync._player_in_same_game_room_list = []
for player_id in NetworkingSync._open_games[Player.get_game_id()][3]:
add_player_entry_to_list(player_id)
func add_player_entry_to_list(player_id):
var player = load("res://Scenes/Matchmaking/Game_room/Player_entry.tscn").instance()
var player_name = str(NetworkingSync._open_games[Player.get_game_id()][3][player_id][0])
player.set_player_name(player_name)
$Player_list/ScrollContainer/Player_list_container.add_child(player)
var player_info = [player_id, player_name]
NetworkingSync._player_in_same_game_room_list.append(player_info)
func _on_Game_room_tree_entered():
if Player._is_host:
$Start_button.show()
$Ready_button.hide()
else:
$Start_button.hide()
$Ready_button.hide() # TODO: change this to .show(), if ready-feature is implemented.
func _on_Start_button_pressed():
NetworkingSync._players_ready = []
NetworkingSync.close_game()
if len(NetworkingSync._player_in_same_game_room_list) >= 2:
for player_id in NetworkingSync._player_in_same_game_room_list:
if player_id[0] != Player.get_player_id():
rpc_id(player_id[0], "start_game")
start_game()
rpc_id(1, "remove_game_from_game_list", Player.get_game_id())
remote func start_game():
get_tree().change_scene("res://Scenes/Matchmaking/Game/Game_manager.tscn")
func _on_Leave_button_pressed():
if Player.is_host():
#TODO: kick everyone out of the game
NetworkingSync.close_game()
else:
NetworkingSync.left_game()
yield(NetworkingSync, "updated_games")
for player in NetworkingSync._open_games[Player.get_game_id()][3]:
print(player)
if player != Player.get_player_id():
rpc_id(player, "update_game_room_player_list")
Player.set_game_id(0)
get_tree().change_scene("res://Scenes/Matchmaking/Lobby/Lobby.tscn")

View File

@ -0,0 +1,88 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Scenes/Matchmaking/Game_room/Game_room.gd" type="Script" id=2]
[node name="Game_room" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Background" type="TextureRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 1 )
expand = true
stretch_mode = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Start_button" type="Button" parent="."]
margin_left = 185.965
margin_top = 324.728
margin_right = 522.965
margin_bottom = 502.728
text = "Start"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Ready_button" type="Button" parent="."]
visible = false
margin_left = 185.965
margin_top = 324.728
margin_right = 522.965
margin_bottom = 502.728
text = "Ready"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Leave_button" type="Button" parent="."]
margin_left = 179.497
margin_top = 615.335
margin_right = 526.497
margin_bottom = 810.335
text = "Leave"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player_list" type="Control" parent="."]
anchor_left = 0.314583
anchor_top = 0.266667
anchor_right = 0.939583
anchor_bottom = 0.822222
margin_left = -3.99939
margin_top = 1.99963
margin_right = -3.99939
margin_bottom = 2.00024
__meta__ = {
"_edit_use_anchors_": true
}
[node name="ColorRect" type="ColorRect" parent="Player_list"]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.282353, 0.0235294, 0.0235294, 0.823529 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ScrollContainer" type="ScrollContainer" parent="Player_list"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player_list_container" type="VBoxContainer" parent="Player_list/ScrollContainer"]
margin_right = 1200.0
size_flags_horizontal = 3
[connection signal="tree_entered" from="." to="." method="_on_Game_room_tree_entered"]
[connection signal="pressed" from="Start_button" to="." method="_on_Start_button_pressed"]
[connection signal="pressed" from="Leave_button" to="." method="_on_Leave_button_pressed"]

View File

@ -0,0 +1,4 @@
extends HBoxContainer
func set_player_name(player_name):
$Player_name_label.text = player_name

View File

@ -0,0 +1,19 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Matchmaking/Game_room/Player_entry.gd" type="Script" id=1]
[node name="Player_entry" type="HBoxContainer"]
margin_right = 800.0
margin_bottom = 40.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player_name_label" type="Label" parent="."]
margin_right = 800.0
margin_bottom = 40.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Player 1"
valign = 1

View File

@ -0,0 +1,33 @@
extends Node
var _game_id
var _game_name
var _max_players
var _player_list
func _init(game_id, game_name, max_players):
_game_id = game_id
_game_name = game_name
_max_players = max_players
_player_list = {}
func get_parsable_game_information():
return [_game_id, _game_name, _max_players, _player_list]
func add_player_to_game(player):
_player_list.append(player)
func remove_player_from_game():
pass
func set_game_id(game_id):
_game_id = game_id
func set_game_name(game_name):
_game_name = game_name
func set_max_players(max_players):
_max_players = max_players
func is_full():
return _max_players <= len(_player_list)

View File

@ -0,0 +1,28 @@
extends Button
var _game_name
var _max_players
var _game_id
func set_game_id(game_id):
_game_id = game_id
func set_game_name(game_name):
_game_name = game_name
func set_max_players(max_players):
_max_players = max_players
func update_gui():
$HBoxContainer/Game_name.text = _game_name
$HBoxContainer/Number_of_player.text = str(len(NetworkingSync._open_games[_game_id][3])) + "/" + str(_max_players)
func _on_Games_entry_pressed():
NetworkingSync.send_open_games_request_to_server()
yield(NetworkingSync, "updated_games")
if _game_id in NetworkingSync._open_games and !is_full():
NetworkingSync.join_game(_game_id)
func is_full():
var number_of_players = len(NetworkingSync._open_games[_game_id][3])
return number_of_players >= _max_players

View File

@ -0,0 +1,36 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Matchmaking/Lobby/Games_entry.gd" type="Script" id=1]
[node name="Games_entry" type="Button"]
margin_right = 661.0
margin_bottom = 77.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxContainer" type="HBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Game_name" type="Label" parent="HBoxContainer"]
margin_right = 80.0
margin_bottom = 77.0
size_flags_vertical = 1
text = "Game_name"
valign = 1
[node name="Number_of_player" type="Label" parent="HBoxContainer"]
margin_left = 84.0
margin_right = 661.0
margin_bottom = 77.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "2/2"
align = 2
valign = 1
[connection signal="pressed" from="." to="." method="_on_Games_entry_pressed"]

View File

@ -0,0 +1,80 @@
extends Control
const MIN_PLAYERS = 2
const MAX_PLAYERS = 8
const MIN_GAME_NAME_LENGTH = 1
const MAX_GAME_NAME_LENGTH = 20
func _on_Refresh_button_pressed():
refresh_game_list()
func refresh_game_list():
NetworkingSync.send_open_games_request_to_server()
yield(NetworkingSync, "updated_games")
for child in $Lobby/Games_list/Open_games/VBoxContainer.get_children():
child.queue_free()
for game in NetworkingSync.get_open_games().values():
add_entry_to_lobby(game[0], game[1], game[2])
func add_entry_to_lobby(game_id, game_name, max_players):
var new_game = load("res://Scenes/Matchmaking/Lobby/Games_entry.tscn").instance()
new_game.set_game_id(game_id)
new_game.set_game_name(game_name)
new_game.set_max_players(max_players)
new_game.name = "Game_entry_" + game_name
new_game.update_gui()
$Lobby/Games_list/Open_games/VBoxContainer.add_child(new_game)
func _on_Create_game_button_pressed():
$Lobby.hide()
$Lobby_game_creation_panel.show()
func _on_Ok_button_pressed():
create_game_room()
func _on_Cancel_button_pressed():
$Lobby_game_creation_panel.hide()
$Lobby.show()
func _on_Exit_button_pressed():
get_tree().change_scene("res://Scenes/Matchmaking/Menu/Menu.tscn")
func _on_Lobby_controller_tree_entered():
refresh_game_list()
func _on_Game_name_line_edit_text_changed(new_text):
check_input_fields()
func _on_Number_of_players_line_edit_text_changed(new_text):
check_input_fields()
func is_number_of_players_text_field_ok():
var result = false
var text_field = $Lobby_game_creation_panel/HBoxContainer2/Number_of_players_line_edit.text
if int(text_field) >= MIN_PLAYERS and int(text_field) <= MAX_PLAYERS:
result = true
return result
func is_game_name_text_field_ok():
var result = false
var text_field = $Lobby_game_creation_panel/HBoxContainer/Game_name_line_edit.text
if len(text_field) <= MAX_GAME_NAME_LENGTH and len(text_field) >= MIN_GAME_NAME_LENGTH:
result = true
return result
func check_input_fields():
if is_number_of_players_text_field_ok() and is_game_name_text_field_ok():
$Lobby_game_creation_panel/Ok_button.disabled = false
else:
$Lobby_game_creation_panel/Ok_button.disabled = true
func _input(ev):
if Input.is_key_pressed(KEY_ENTER) and not $Lobby_game_creation_panel/Ok_button.disabled:
create_game_room()
func create_game_room():
var game_name = $Lobby_game_creation_panel/HBoxContainer/Game_name_line_edit.text
var max_players = int($Lobby_game_creation_panel/HBoxContainer2/Number_of_players_line_edit.text)
var game_id = get_tree().get_network_unique_id()
NetworkingSync.create_game([game_id, game_name, max_players, {}], Player)

View File

@ -0,0 +1,221 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Scenes/Matchmaking/Lobby/Lobby.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[node name="Lobby_controller" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Lobby_background" type="TextureRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 2 )
stretch_mode = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Lobby" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Games_list" type="Control" parent="Lobby"]
anchor_left = 0.31283
anchor_top = 0.147956
anchor_right = 0.965434
anchor_bottom = 0.834067
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Background" type="ColorRect" parent="Lobby/Games_list"]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.196078, 0.254902, 0.352941, 0.843137 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Open_games" type="ScrollContainer" parent="Lobby/Games_list"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="Lobby/Games_list/Open_games"]
margin_right = 1253.0
size_flags_horizontal = 3
[node name="Lobby_buttons" type="Control" parent="Lobby"]
anchor_left = 0.0234375
anchor_top = 0.407407
anchor_right = 0.283854
anchor_bottom = 0.796296
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Background" type="ColorRect" parent="Lobby/Lobby_buttons"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -3.05176e-05
margin_bottom = -20.0
color = Color( 0.196078, 0.254902, 0.352941, 0.843137 )
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Create_game_button" type="Button" parent="Lobby/Lobby_buttons"]
margin_left = 20.0
margin_top = 20.0
margin_right = 480.0
margin_bottom = 80.0
text = "Create Game"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Search_game_button" type="Button" parent="Lobby/Lobby_buttons"]
margin_left = 20.0
margin_top = 120.0
margin_right = 480.0
margin_bottom = 180.0
disabled = true
text = "Search Game"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Refresh_button" type="Button" parent="Lobby/Lobby_buttons"]
margin_left = 20.0
margin_top = 220.0
margin_right = 480.0
margin_bottom = 280.0
text = "Refresh"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Exit_button" type="Button" parent="Lobby/Lobby_buttons"]
margin_left = 20.0
margin_top = 320.0
margin_right = 480.0
margin_bottom = 380.0
text = "Exit"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Auto_refresh_timer" type="Timer" parent="Lobby"]
[node name="Lobby_game_creation_panel" type="Control" parent="."]
visible = false
anchor_left = 0.183854
anchor_top = 0.200463
anchor_right = 0.816146
anchor_bottom = 0.799537
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Background" type="ColorRect" parent="Lobby_game_creation_panel"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = 1.75809
margin_bottom = 1.75806
color = Color( 0.360784, 0.360784, 0.360784, 0.823529 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxContainer" type="HBoxContainer" parent="Lobby_game_creation_panel"]
anchor_left = 0.0881384
anchor_top = 0.0772798
anchor_right = 0.911862
anchor_bottom = 0.200927
margin_bottom = -40.0
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Game_name_label" type="Label" parent="Lobby_game_creation_panel/HBoxContainer"]
margin_right = 78.0
margin_bottom = 39.0
size_flags_vertical = 3
text = "Gamename:"
valign = 1
[node name="Game_name_line_edit" type="LineEdit" parent="Lobby_game_creation_panel/HBoxContainer"]
margin_left = 82.0
margin_right = 1000.0
margin_bottom = 39.0
size_flags_horizontal = 3
[node name="HBoxContainer2" type="HBoxContainer" parent="Lobby_game_creation_panel"]
anchor_left = 0.0881384
anchor_top = 0.278207
anchor_right = 0.911862
anchor_bottom = 0.401855
margin_bottom = -40.0
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Max_player_label" type="Label" parent="Lobby_game_creation_panel/HBoxContainer2"]
margin_right = 80.0
margin_bottom = 40.0
size_flags_vertical = 3
text = "Max Players:"
valign = 1
[node name="Number_of_players_line_edit" type="LineEdit" parent="Lobby_game_creation_panel/HBoxContainer2"]
margin_left = 84.0
margin_right = 1000.0
margin_bottom = 40.0
size_flags_horizontal = 3
[node name="Ok_button" type="Button" parent="Lobby_game_creation_panel"]
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = -457.0
margin_top = -247.0
margin_right = -57.0
margin_bottom = -147.0
disabled = true
text = "Ok"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Cancel_button" type="Button" parent="Lobby_game_creation_panel"]
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = 43.0001
margin_top = -247.0
margin_right = 443.0
margin_bottom = -147.0
text = "Cancel"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="tree_entered" from="." to="." method="_on_Lobby_controller_tree_entered"]
[connection signal="pressed" from="Lobby/Lobby_buttons/Create_game_button" to="." method="_on_Create_game_button_pressed"]
[connection signal="pressed" from="Lobby/Lobby_buttons/Refresh_button" to="." method="_on_Refresh_button_pressed"]
[connection signal="pressed" from="Lobby/Lobby_buttons/Exit_button" to="." method="_on_Exit_button_pressed"]
[connection signal="text_changed" from="Lobby_game_creation_panel/HBoxContainer/Game_name_line_edit" to="." method="_on_Game_name_line_edit_text_changed"]
[connection signal="text_changed" from="Lobby_game_creation_panel/HBoxContainer2/Number_of_players_line_edit" to="." method="_on_Number_of_players_line_edit_text_changed"]
[connection signal="pressed" from="Lobby_game_creation_panel/Ok_button" to="." method="_on_Ok_button_pressed"]
[connection signal="pressed" from="Lobby_game_creation_panel/Cancel_button" to="." method="_on_Cancel_button_pressed"]

View File

@ -0,0 +1,22 @@
extends Node
func _on_Button_pressed():
connect_to_server()
func _on_LineEdit_text_changed(new_text):
if len(new_text) <= 0 or len(new_text) >= 20:
$GUI/Start_button.disabled = true
else:
$GUI/Start_button.disabled = false
func _input(ev):
if Input.is_key_pressed(KEY_ENTER) and not $GUI/Start_button.disabled:
connect_to_server()
func connect_to_server():
Player.set_player_name($GUI/LineEdit.text)
get_tree().change_scene("res://Scenes/Matchmaking/Client/Network_connection.tscn")
func _on_Exit_button_pressed():
get_tree().quit()

View File

@ -0,0 +1,59 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Matchmaking/Menu/Menu.gd" type="Script" id=1]
[node name="Menu" type="Node"]
script = ExtResource( 1 )
[node name="GUI" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Start_button" type="Button" parent="GUI"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -134.5
margin_top = 91.7361
margin_right = 134.5
margin_bottom = 162.736
disabled = true
text = "Connect to Server"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Exit_button" type="Button" parent="GUI"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -134.5
margin_top = 193.832
margin_right = 134.5
margin_bottom = 264.832
text = "Exit"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="LineEdit" type="LineEdit" parent="GUI"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -300.0
margin_top = -15.0
margin_right = 300.0
margin_bottom = 15.0
placeholder_text = "Playername..."
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="GUI/Start_button" to="." method="_on_Button_pressed"]
[connection signal="pressed" from="GUI/Exit_button" to="." method="_on_Exit_button_pressed"]
[connection signal="text_changed" from="GUI/LineEdit" to="." method="_on_LineEdit_text_changed"]

View File

@ -0,0 +1,53 @@
extends Node
signal updated_games
signal all_ready
var _open_games = {}
var _player_in_same_game_room_list = []
var _players_ready = []
func send_open_games_request_to_server():
rpc_id(1, "get_open_games_from_server", get_tree().get_network_unique_id())
remote func update_open_games(open_games):
_open_games = open_games
emit_signal("updated_games")
func get_open_games():
return _open_games
func create_game(game_information, host_player):
Player.set_game_id(host_player.get_player_id())
Player.set_host(true)
rpc_id(1, "add_game_to_game_list", host_player.get_player_id(), game_information, host_player.get_parsable_player())
yield(NetworkingSync, "updated_games")
get_tree().change_scene("res://Scenes/Matchmaking/Game_room/Game_room.tscn")
func join_game(game_id):
Player.set_game_id(game_id)
Player.set_host(false)
rpc_id(1, "join_open_game", game_id, Player.get_parsable_player())
get_tree().change_scene("res://Scenes/Matchmaking/Game_room/Game_room.tscn")
func left_game():
rpc_id(1, "remove_player_from_open_game", Player.get_game_id(), Player.get_player_id())
send_open_games_request_to_server()
func _on_Server_is_reachable_timeout():
print("Server is reachable.")
# TODO: check if connection still exists.
func close_game():
rpc_id(1, "remove_game_from_game_list", Player.get_game_id())
func send_ready_signal():
if Player.is_host():
send_host_ready_signal(Player.get_player_id())
else:
rpc_id(Player.get_game_id(), "send_host_ready_signal", Player.get_player_id())
remote func send_host_ready_signal(id):
_players_ready.append(id)
if len(_players_ready) == len(_player_in_same_game_room_list):
emit_signal("all_ready")

View File

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Matchmaking/Networking/Networking_sync.gd" type="Script" id=1]
[node name="Networking" type="Node"]
script = ExtResource( 1 )
[node name="Server_is_reachable_timer" type="Timer" parent="."]
[connection signal="timeout" from="Server_is_reachable_timer" to="." method="_on_Server_is_reachable_timeout"]

View File

@ -0,0 +1,33 @@
extends Node
var _player_id
var _player_name
var _game_id
var _is_host
func set_player_name(player_name):
_player_name = player_name
func set_player_id(player_id):
_player_id = player_id
func set_host(is_host):
_is_host = is_host
func is_host():
return _is_host
func get_player_name():
return _player_name
func get_player_id():
return _player_id
func set_game_id(game_id):
_game_id = game_id
func get_game_id():
return _game_id
func get_parsable_player():
return [_player_name, _player_id, _game_id, _is_host]

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Matchmaking/Player/Player.gd" type="Script" id=1]
[node name="Player" type="Node"]
script = ExtResource( 1 )