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,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")