summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Board.gd213
-rw-r--r--scripts/GameTable.gd245
-rw-r--r--scripts/Globals.gd28
-rw-r--r--scripts/HexSpace.gd86
-rw-r--r--scripts/MainMenu.gd84
-rw-r--r--scripts/MainScene.gd13
-rw-r--r--scripts/Plane.gd15
-rw-r--r--scripts/ServerBrowser.gd5
8 files changed, 467 insertions, 222 deletions
diff --git a/scripts/Board.gd b/scripts/Board.gd
new file mode 100644
index 0000000..f18ca74
--- /dev/null
+++ b/scripts/Board.gd
@@ -0,0 +1,213 @@
+extends Spatial
+
+enum { Y, X }
+
+# hex board represented in square-grid form like so (e.g., 3-length-side hex grid):
+# x x x
+# x x x x
+# x x x x x
+# x x x x
+# x x x
+# going up and to the right is done by decreasing the row by 1
+# going up and to the left is done by decreasing the row by 1 and the column by 1
+var board: Array = [] # 2D Array of JSON objects describing the board, which can be turned into objects
+var board_display: Array = []
+var available_board_coords: Array = [] # for population purposes
+var airports = {} # id : HexSpace of cell_type airport
+
+var side_len: int
+
+
+# Y R B G
+var airport_colors = [ Color(1, 1, 0), Color(1, 0, 0), Color(0.3, 0.3, 1), Color(0, 0.8, 0) ]
+enum { NUMBER, COLOR }
+
+onready var hex_space = preload("res://objects/HexSpace.tscn")
+
+# cell types
+enum { PLAIN, HILLS, MOUNTAINS, AIRPORT }
+
+# directions: E, NE, NW, W, SW, SE
+const adjacent_offsets = [ [0,1] , [-1, 0], [-1, -1], [0, -1], [1, 0], [1, 1] ]
+
+# indices of the offsets that are valid cells to approach from
+const approaches_i: Array= [ [0, 1, 2, 3, 4, 5], [0,1,3,4], [0,3] ]
+
+
+func _ready():
+ pass
+
+func reset_board():
+ for node in get_children():
+ node.queue_free()
+ board.clear()
+ board_display.clear()
+ available_board_coords.clear()
+
+func create_board_base(hex_side_length : int):
+ side_len = hex_side_length
+ var number_of_cells = 3*( pow(hex_side_length, 2) - hex_side_length) + 1
+
+ reset_board()
+
+ var board_diameter = hex_side_length * 2 - 1
+ for r in range(board_diameter):
+ var row_length: int = board_diameter - abs(r-(hex_side_length-1))
+
+ var row = []
+ row.resize(board_diameter)
+ row.fill(null) # not in hex grid
+
+ var offset : int = 0
+ if r > (hex_side_length - 1): offset = r - (hex_side_length - 1)
+ for i in range(row_length):
+ row[offset+i] = { "cell_type" : PLAIN, "pos" : [r, offset+i] } # ground cell
+ available_board_coords.push_back( [r, offset+i] )
+
+ board.append(row)
+
+
+func display_board():
+ var cell_size_x = 1 # distance between center of two adjacent hex cells
+ var row_offset_y:float = cos(deg2rad(30)) * cell_size_x
+ var board_diam:int = len(board)
+ var side_len:int = ( board_diam + 1 ) / 2
+
+ for r in range(board_diam):
+ var row_display = []
+ row_display.resize(board_diam)
+ row_display.fill(null)
+ var row = board[r]
+ var z = row_offset_y * (r - board_diam/2)
+ var offset_x = abs(side_len - (r+1)) * (cell_size_x / 2.0) if (r+1) <= side_len else -1*abs(side_len - (r+1)) * (cell_size_x/2.0)
+ offset_x -= board_diam/2 * cell_size_x
+ for c in range(board_diam):
+ if row[c] == null: continue
+ var x = offset_x + c * cell_size_x
+
+ var new_cell = hex_space.instance()
+ new_cell.call_deferred("set", "global_position", Vector3(x, randf()/15, z))
+ new_cell.set_up(row[c])
+ add_child(new_cell)
+ row_display[c] = new_cell
+ board_display.push_back(row_display)
+
+
+# populate board with airports, hills, and mountains
+# depending on game settings
+func populate_board(num_mountains : int, num_hills : int, num_airports : int, runway_count : int, use_names : bool = false) -> bool:
+ var board_diam:int = len(board)
+
+ for _m in range(num_mountains):
+ if len(available_board_coords) < 1: return false
+ var spot_i:int = randi() % len(available_board_coords)
+ var spot = available_board_coords[ spot_i ]
+ var args = {"cell_type" : MOUNTAINS, "orientation" : randi() % 6, "pos" : [spot[Y], spot[X]]}
+ board[spot[Y]][spot[X]] = args
+ available_board_coords.pop_at(spot_i)
+
+ for _h in range(num_hills):
+ if len(available_board_coords) < 1: return false
+ var spot_i:int = randi() % len(available_board_coords)
+ var spot = available_board_coords[ spot_i ]
+ var args = { "cell_type" : HILLS, "orientation" : randi() % 6, "pos" : [spot[Y], spot[X]] }
+ board[spot[Y]][spot[X]] = args
+ available_board_coords.pop_at(spot_i)
+
+ # airport identification
+ var used_airports : Array = []
+
+ var airport_id:int = 0
+ for a in range(num_airports):
+ var airport_display
+ if use_names:
+ airport_display = Globals.get_random_airport_name(used_airports)
+ else:
+ airport_display = [ randi() % 9 + 1, randi() % 4 ] # number, color
+ while airport_display in used_airports:
+ airport_display = [ randi() % 9 + 1, randi() % 4 ]
+ # find valid spot
+ var spot_okay:bool = false
+ var rot:int
+ var spot_r:int
+ var spot_c:int
+ var spot_i:int
+ var valid_approaches = []
+ var runways = (randi() % 3 + 1) if (runway_count == 0) else runway_count
+ while (not spot_okay) and (len(available_board_coords) > 0):
+ spot_i = randi() % len(available_board_coords)
+ var spot = available_board_coords[ spot_i ]
+ spot_r = spot[Y]
+ spot_c = spot[X]
+
+ var has_adjacent_airport = false
+ for offset in adjacent_offsets: # away from other airports
+ var new_r: int = spot_r + offset[Y]
+ var new_c: int = spot_c + offset[X]
+ if new_r < 0 or new_c < 0 or new_r >= board_diam or new_c >= board_diam: # offset out of square grid
+ continue
+ var adjacent_cell = board[new_r][new_c]
+ if adjacent_cell != null and adjacent_cell["cell_type"] == AIRPORT:
+ has_adjacent_airport = true
+ break
+ if has_adjacent_airport:
+ available_board_coords.pop_at(spot_i)
+ continue
+
+ spot_okay = true
+
+ # find rotation that leaves at least 1 runway open
+ rot = randi() % 3
+ var rot_okay = false
+ for _i in range(3):
+ var rot_approaches = adjacent_offsets.slice(rot, 5)
+ if rot != 0: rot_approaches += adjacent_offsets.slice(0, rot - 1)
+
+ var possible_approaches = []
+ for approach_index in approaches_i[runways]:
+ possible_approaches.push_back(rot_approaches[approach_index])
+
+ var has_runway = false
+ for approach in possible_approaches:
+ var app_r: int = spot_r + approach[0]
+ var app_c: int = spot_c + approach[1]
+ if app_r < 0 or app_r >= board_diam or app_c < 0 or app_c >= board_diam: continue # out of square map
+ if board[app_r][app_c] == null: continue # out of hex map
+ if board[app_r][app_c]["cell_type"] in [HILLS, MOUNTAINS]: continue # invalid approach square
+ has_runway = true
+ valid_approaches.push_back(approach)
+
+ if has_runway:
+ rot_okay = true
+ break
+ else:
+ rot += 1 # rotate 60 deg (effectively)
+ if not rot_okay:
+ available_board_coords.pop_at(spot_i)
+ continue
+
+ if not spot_okay:
+ return false # could not form valid map
+
+ var args = {"cell_type" : AIRPORT , "pos" : [spot_r, spot_c], "orientation" : rot, "airport_id" : airport_id, "runways" : runways, 'valid_approach_offsets' : valid_approaches, "use_names" : use_names}
+ if use_names:
+ args["airport_name"] = airport_display
+ else:
+ args["airport_color"] = airport_colors[airport_display[COLOR]]
+ args["airport_number"] = airport_display[NUMBER]
+ board[spot_r][spot_c] = args
+ available_board_coords.pop_at(spot_i)
+ airport_id += 1
+ return true
+
+func get_json():
+ return board
+
+func generate_board(hex_side_len: int, num_mountains : int, num_hills : int, num_airports : int, runway_count : int, use_names : bool = false) -> bool:
+ create_board_base(hex_side_len)
+ if not populate_board(num_mountains, num_hills, num_airports, runway_count, use_names):
+ reset_board()
+ print("Invalid board creation parameters")
+ return false
+ display_board()
+ return true
diff --git a/scripts/GameTable.gd b/scripts/GameTable.gd
index cbee40f..b0bedf2 100644
--- a/scripts/GameTable.gd
+++ b/scripts/GameTable.gd
@@ -1,207 +1,68 @@
-tool
extends Spatial
-const num_mountains = {"easy" : 0, "medium" : 3, "hard" : 6}
-const num_hills = {"easy" : 4, "medium" : 6, "hard" : 8}
+# MULTIPLAYER DATA
-export var hex_side_length = 6 setget set_hex_side_len
-export var airports_per_color = 6 setget set_airports_per_color
-export var num_airport_colors = 3 setget set_num_airport_colors
-export var _generate_board_editor: bool = false setget generate_board_editor
+var gc_client # to be assigned by MainScene upon game creation/joining
-export (String, "easy", "medium", "hard") var game_difficulty = "easy"
-# hex board represented in square-grid form like so (e.g., 3-length-side hex grid):
-# x x x
-# x x x x
-# x x x x x
-# x x x x
-# x x x
-# going up and to the right is done by decreasing the row by 1
-# going up and to the left is done by decreasing the row by 1 and the column by 1
-var board = []
-var available_board_coords = []
-enum { GROUND_LAYER, WEATHER_LAYER, PLANES_LAYER }
-# Y R B G
-var airport_colors = [ Color(1, 1, 0), Color(1, 0, 0), Color(0.3, 0.3, 1), Color(0, 0.8, 0) ]
-var airports = {} # id : HexSpace of cell_type airport
+# END MULTIPLAYER DATA
-onready var hex_space = preload("res://objects/HexSpace.tscn")
+# GAME DATA
+
+enum { PREGAME, PLACING, DETERMINE_ACTIONS, MOVEMENT }
+var game_state: int
+var BOARD_GEN_PARAMS = {
+ "airport_style" : 0, # 0 = colors + numbers, 1 = names
+ "num_airports" : 18,
+ "board_side_length" : 6,
+ "num_hills" : 8,
+ "num_mountains" : 4,
+ "runways_per_airport" : 0 # 0 random, 1-3
+}
+var RULES = {
+ "fly_over_airports" : 0, # 1 = only at altitude 2, 2 = any altitude
+ "must_land_on_final_action" : 0,
+ "takeoff_action" : 2, # 0 - 4
+ "move_forward_order" : 0, # 0 = either before or after, 1 = after, 2 = before
+ "gamemode" : 0, # 0 = cooperative, 1 = versus
+ "plane_assignment" : 0, # 0 = random, 1 = draft
+ "altitude_and_turn" : 0, # whether a plane can change altitude and turn in the same action
+ "event_frequency" : 1, # turns per event
+ "weather_enabled" : 1,
+ "misc_enabled" : 1,
+ "new_planes_per_turn" : 4, # 1 - 8
+ "ramp_up_enabled" : 0, # whether to ramp up to max planes per turn
+ "starting_planes_per_player": 4,
+ "round_timer" : 60, # seconds
+}
+
+onready var BOARD = $Board
+var PLANES = []
+
+var desired_player_count: int
+var is_board_generated: bool = false # determine whether host can begin the game
+
+# END GAME DATA
# directions: E, NE, NW, W, SW, SE
const adjacent_offsets = [ [0,1] , [-1, 0], [-1, -1], [0, -1], [1, 0], [1, 1] ]
-# indices of the offsets that are valid cells to approach from
-const approaches_i = {"easy": [0, 1, 2, 3, 4, 5], "medium" : [0,1,3,4], "hard" : [0,3]}
-func _ready():
- if not Engine.editor_hint:
- generate_hex_board()
- generate_board_cells()
- populate_board()
-
-func set_hex_side_len(side_length):
- hex_side_length = side_length
-
-func set_airports_per_color(num_airports):
- airports_per_color = num_airports
-
-func set_num_airport_colors(num_colors):
- num_airport_colors = num_colors
-
-func generate_hex_board():
- var number_of_cells = 3*( pow(hex_side_length, 2) - hex_side_length) + 1
- var player_spaces = number_of_cells - 1 # center should always be a mountain
- for node in $Board.get_children():
- $Board.remove_child(node)
- board = [] # reset board + contents
- available_board_coords = []
- var board_diameter = hex_side_length * 2 - 1
- for r in range(board_diameter):
- var row_length: int = board_diameter - abs(r-(hex_side_length-1))
-
- var row = []
- row.resize(board_diameter)
- row.fill(null) # not in hex grid
-
- if r <= (hex_side_length - 1):
- for i in range(row_length):
- row[i] = [ 1, [], [] ] # ground cell, weather effects, planes
- else:
- for i in range(row_length):
- row[board_diameter-1-i] = [ 1, [], [] ] # ground cell, weather effects, planes
-
- board.append(row)
-
-
-func generate_board_cells():
- var cell_size_x = 1 # distance between center of two adjacent hex cells
- var row_offset_y:float = cos(deg2rad(30)) * cell_size_x
- var board_diam:int = len(board)
- var side_len:int = ( board_diam + 1 ) / 2
-
- for r in range(board_diam):
- var row = board[r]
- var z = row_offset_y * (r - board_diam/2)
- var offset_x = abs(side_len - (r+1)) * (cell_size_x / 2.0) if (r+1) <= side_len else -1*abs(side_len - (r+1)) * (cell_size_x/2.0)
- offset_x -= board_diam/2 * cell_size_x
- for c in range(board_diam):
- if row[c] == null: continue
- var x = offset_x + c * cell_size_x
-
- var new_cell = hex_space.instance()
- new_cell.call_deferred("set", "global_position", Vector3(x, randf()/15, z))
- $Board.add_child(new_cell)
-
- board[r][c][GROUND_LAYER] = new_cell
- if (r == c) and (r == (board_diam/2)): # central cell always a mountain
- var cell_type = "mountain"
- var args = {}
- args["rotation"] = randi() % 6
- new_cell.set_up(cell_type, args)
- else:
- available_board_coords.push_back( [r, c] )
-
-# populate board with airports, hills, and mountains
-# depending on game settings
-func populate_board():
- var board_diam:int = len(board)
-
- for _m in range(num_mountains[game_difficulty]):
- if len(available_board_coords) < 1: return null
- var spot_i:int = randi() % len(available_board_coords)
- var spot = available_board_coords[ spot_i ]
- var args = {"rotation" : randi() % 6}
- board[spot[0]][spot[1]][GROUND_LAYER].set_up("mountain", args)
- available_board_coords.pop_at(spot_i)
-
- for _h in range(num_hills[game_difficulty]):
- if len(available_board_coords) < 1: return null
- var spot_i:int = randi() % len(available_board_coords)
- var spot = available_board_coords[ spot_i ]
- var args = {"rotation" : randi() % 6}
- board[spot[0]][spot[1]][GROUND_LAYER].set_up("hills", args)
- available_board_coords.pop_at(spot_i)
-
- var airport_id:int = 0
- for c in range(num_airport_colors):
- for a in range(airports_per_color):
- # find valid spot
- var spot_okay:bool = false
- var rot:int
- var spot_r:int
- var spot_c:int
- var spot_i:int
- var valid_approaches = []
- while (not spot_okay) and (len(available_board_coords) > 0):
- spot_i = randi() % len(available_board_coords)
- var spot = available_board_coords[ spot_i ]
- spot_r = spot[0]
- spot_c = spot[1]
-
- # should no longer be necessary
- #if board[spot_r][spot_c] == null: continue
-
- var has_adjacent_airport = false
- for offset in adjacent_offsets: # away from other airports
- var new_r: int = spot_r + offset[0]
- var new_c: int = spot_c + offset[1]
- if new_r < 0 or new_c < 0 or new_r >= board_diam or new_c >= board_diam: # offset out of square grid
- continue
- var adjacent_cell = board[new_r][new_c]
- if adjacent_cell != null and adjacent_cell[GROUND_LAYER].cell_type == "airport":
- has_adjacent_airport = true
- break
- if has_adjacent_airport:
- available_board_coords.pop_at(spot_i)
- continue
-
- spot_okay = true
-
- # find rotation that leaves at least 1 runway open
- rot = randi() % 3
- var rot_okay = false
- for _i in range(3):
- var rot_approaches = adjacent_offsets.slice(rot, 5)
- if rot != 0: rot_approaches += adjacent_offsets.slice(0, rot - 1)
-
- var possible_approaches = []
- for approach_index in approaches_i[game_difficulty]:
- possible_approaches.push_back(rot_approaches[approach_index])
-
- var has_runway = false
- for approach in possible_approaches:
- var app_r: int = spot_r + approach[0]
- var app_c: int = spot_c + approach[1]
- if app_r < 0 or app_r >= board_diam or app_c < 0 or app_c >= board_diam: continue # out of square map
- if board[app_r][app_c] == null: continue # out of hex map
- if board[app_r][app_c][GROUND_LAYER].cell_type in ["hills", "mountain"]: continue # invalid approach square
- has_runway = true
- valid_approaches.push_back(approach)
-
- if has_runway:
- rot_okay = true
- break
- else:
- rot += 1 # rotate 60 deg (effectively)
- if not rot_okay:
- available_board_coords.pop_at(spot_i)
- continue
-
- if not spot_okay:
- print('couldnt find spot')
- return null # could not form valid map
- #print(c, " ", a, "(", spot_r, ", ", spot_c, ")")
- var args = {"rotation" : rot, "airport_color" : airport_colors[c], "airport_number" : a+1, "airport_id" : airport_id, "difficulty" : game_difficulty, 'valid_approaches' : valid_approaches}
- board[spot_r][spot_c][GROUND_LAYER].set_up("airport", args)
- available_board_coords.pop_at(spot_i)
- airport_id += 1
+func _ready():
+ pass
+
+func set_up(ws_client, is_host: bool, lobby_id: String, player_id: String, rejoin_key: String):
+ self.ws_client = ws_client
+ self.is_host = is_host
+ self.lobby_id = lobby_id
+ self.player_id = player_id
+ self.rejoin_key = rejoin_key
+
+# ask host for complete game state. returned fields will depend on game state
+func request_complete_game_state():
+ if is_host: return
+ var request = { "type" : "request", "source" : host_id, "requested_data" : "ALL" }
-
-func generate_board_editor(_gbe):
- generate_hex_board()
- generate_board_cells()
- populate_board()
diff --git a/scripts/Globals.gd b/scripts/Globals.gd
index 18f3d19..3603dbd 100644
--- a/scripts/Globals.gd
+++ b/scripts/Globals.gd
@@ -1,7 +1,33 @@
extends Node
# Y R B G W Cy Pk O P dG
-const colors = [ Color(1, 1, 0), Color(1, 0, 0), Color(0.3, 0.3, 1), Color(0, 0.8, 0), Color(1, 1, 1), Color(0, 1, 1), Color(1, .35, 1), Color(1, 0.4, 0), Color(0.38, 0, 0.38), Color(0, 0.4, 0) ]
+const colors : Array = [ Color(1, 1, 0), Color(1, 0, 0), Color(0.3, 0.3, 1), Color(0, 0.8, 0), Color(1, 1, 1), Color(0, 1, 1), Color(1, .35, 1), Color(1, 0.4, 0), Color(0.38, 0, 0.38), Color(0, 0.4, 0) ]
+
+const airport_names_file : String = 'res://resources/airports.txt'
+var airport_names : Array = []
+
+const DEFAULT_GC_URL : String = "ws://192.168.7.112:8181"
+var GC_URL : String = "ws://192.168.7.112:8181"
func _ready():
+ load_airport_names()
set_process(false)
+
+func update_gc_url(new_url : String):
+ GC_URL = new_url
+
+
+
+func load_airport_names():
+ var f = File.new()
+ f.open(airport_names_file, File.READ)
+ var index = 1
+ while not f.eof_reached(): # iterate through all lines until the end of file is reached
+ airport_names.push_back(f.get_line())
+ f.close()
+
+func get_random_airport_name(exceptions=[]):
+ var name_index:int = randi() % len(airport_names)
+ while airport_names[name_index] in exceptions:
+ name_index = randi() % len(airport_names)
+ return airport_names[name_index]
diff --git a/scripts/HexSpace.gd b/scripts/HexSpace.gd
index c8269fd..bcf64f1 100644
--- a/scripts/HexSpace.gd
+++ b/scripts/HexSpace.gd
@@ -1,50 +1,92 @@
tool
extends StaticBody
-var cell_type : String = "normal"
+enum { PLAIN, HILLS, MOUNTAINS, AIRPORT }
+enum { Y, X }
+
+# general cell variables
+var x : int = -1
+var y : int = -1
+var cell_type : int = PLAIN
+var orientation : int = 0 # 0 - 5
# airport variables
var airport_number : int
var airport_color : Color
var airport_id : int
+var airport_name : String
+var runway_count : int
+var airport_closed : bool = false
+
# cell offsets that describe valid approaches based on runways and surroundings
# used to choose a takeoff position
+enum rotations { EAST, NORTHEAST, NORTHWEST, WEST, SOUTHWEST, SOUTHEAST }
const bearings = [ [0,1] , [-1, 0], [-1, -1], [0, -1], [1, 0], [1, 1] ]
-var valid_approaches = []
-var valid_bearings = []
+
+var valid_departure_bearings = []
+var valid_arrival_bearings = []
func _ready():
pass
-func set_up(tile_type, settings={}):
- valid_bearings = [] # reset
- cell_type = tile_type
+func reset():
+ $Hills.visible = false
+ $Mountain.visible = false
+ $Airport.visible = false
+ $Airport/EasyRunway.visible = true # reset runways
+ $Airport/MediumRunway.visible = true
+ $Airport/AirportName.visible = false
+ $Airport/AirportIcon.visible = false
+ orientation = 0
+ self.rotation.y = 0
+ cell_type = PLAIN
+ x = -1
+ y = -1
+ airport_closed = false
+
- if settings["rotation"]: # bearing according to E, NE, etc.
- self.global_rotation.y = settings["rotation"] * deg2rad(60)
+func set_up(settings):
+ x = settings["pos"][X] ; y = settings["pos"][Y]
+ cell_type = settings["cell_type"]
- if tile_type == "hills":
+ valid_departure_bearings.clear()
+ valid_arrival_bearings.clear()
+
+
+ if settings["orientation"]: # bearing according to E, NE, etc.
+ orientation = settings["orientation"]
+ self.global_rotation.y = orientation * deg2rad(60)
+
+ if cell_type == HILLS:
$Hills.visible = true
- elif tile_type == "mountain":
+ elif cell_type == MOUNTAINS:
$Mountain.visible = true
- elif tile_type == "airport":
+ elif cell_type == AIRPORT:
$Airport.visible = true
- airport_number = settings["airport_number"]
- airport_color = settings["airport_color"]
- valid_approaches = settings["valid_approaches"]
- for approach in valid_approaches:
- var bearing_i = bearings.find(approach)
- valid_bearings.push_back(bearings[bearing_i])
+ if settings["use_names"]:
+ airport_name = settings["airport_name"]
+ $Airport/AirportName.visible = true
+ else:
+ airport_number = settings["airport_number"]
+ airport_color = settings["airport_color"]
+ $Airport/AirportIcon.visible = true
+ $Airport/AirportIcon.texture = load("res://textures/airport_indicator_%d.png" % airport_number)
+ $Airport/AirportIcon.modulate = airport_color
+
+ valid_departure_bearings = settings["valid_approach_offsets"]
airport_id = settings["airport_id"]
- $Airport/AirportIcon.texture = load("res://textures/airport_indicator_%d.png" % airport_number)
- $Airport/AirportIcon.modulate = airport_color
+ for departure_bearing in valid_departure_bearings:
+ var bearing_i = bearings.find(departure_bearing)
+ bearing_i = (bearing_i + 3) % 6 # opposite bearing
+ valid_arrival_bearings.push_back(bearings[bearing_i])
- if settings["difficulty"] == "easy": return
- $Airport/EasyRunway.visible = false
- if settings["difficulty"] == "hard":
+ runway_count = int(clamp(settings["runway_count"], 1, 3))
+ if runway_count < 3:
+ $Airport/EasyRunway.visible = false
+ if runway_count == 1:
$Airport/MediumRunway.visible = false
diff --git a/scripts/MainMenu.gd b/scripts/MainMenu.gd
new file mode 100644
index 0000000..fca6658
--- /dev/null
+++ b/scripts/MainMenu.gd
@@ -0,0 +1,84 @@
+extends Control
+
+signal game_host_request(args)
+signal game_join_request(args)
+
+var lobby_name_changed : bool = false # automatically update lobby name to be based on player's name
+
+func _ready():
+ $BackButton.connect("pressed", self, "back_button")
+ $HostMenuButton.connect("pressed", self, "host_menu_button_pressed")
+ $JoinMenuButton.connect("pressed", self, "join_menu_button_pressed")
+ $SettingsButton.connect("pressed", self, "settings_menu_button_pressed")
+ $HostMenu/PrivateToggle.connect("toggled", $HostMenu/Password, "set_visible")
+ $SettingsMenu/GameCoordinatorURL.connect("text_changed", Globals, "update_gc_url")
+ $PlayerInfo/Username.connect("text_changed", self, "automatically_update_lobby_name")
+ $HostMenu/GameName.connect("text_changed", self, "set_lobby_name_changed")
+ #main_menu() # in case things are incorrectly visible from editing
+
+
+func set_lobby_name_changed(_disregard_new_text):
+ lobby_name_changed = true
+
+func automatically_update_lobby_name(username : String):
+ if lobby_name_changed: return
+ var suffix : String = "' Game" if username.ends_with("s") else "'s Game"
+ $HostMenu/GameName.set_text(username + suffix)
+
+func main_menu():
+ set_menu_buttons_visible(true)
+ set_player_info_visible(false)
+ set_join_menu_visible(false)
+ set_host_menu_visible(false)
+ set_settings_menu_visible(false)
+ set_back_button_visible(false)
+
+func set_menu_buttons_visible(visible : bool):
+ $HostMenuButton.visible = visible
+ $JoinMenuButton.visible = visible
+ $SettingsButton.visible = visible
+
+func set_player_info_visible(visible : bool):
+ $PlayerInfo.visible = visible
+
+func set_join_menu_visible(visible : bool):
+ $JoinMenu.visible = visible
+
+func set_host_menu_visible(visible : bool):
+ $HostMenu.visible = visible
+
+func set_settings_menu_visible(visible : bool):
+ $SettingsMenu.visible = visible
+
+func set_back_button_visible(visible : bool):
+ $BackButton.visible = visible
+ $BackButton.disabled = false # reset in case left disabled by other function
+
+# go to join game menu
+func join_menu_button_pressed(lobby_id_from_url : String = "", password_from_url : String = ""):
+ set_menu_buttons_visible(false)
+ set_player_info_visible(true)
+ set_join_menu_visible(true)
+ set_back_button_visible(true)
+ if lobby_id_from_url:
+ $JoinMenu/LobbyID.text = lobby_id_from_url
+ if password_from_url:
+ $JoinMenu/Password.text = password_from_url
+
+# go to host game menu
+func host_menu_button_pressed():
+ set_menu_buttons_visible(false)
+ set_player_info_visible(true)
+ set_host_menu_visible(true)
+ set_back_button_visible(true)
+
+# go to settings menu
+func settings_menu_button_pressed():
+ $SettingsMenu/GameCoordinatorURL.text = Globals.GC_URL
+ set_menu_buttons_visible(false)
+ set_settings_menu_visible(true)
+ set_back_button_visible(true)
+
+# return to main menu
+func back_button():
+ main_menu()
diff --git a/scripts/MainScene.gd b/scripts/MainScene.gd
new file mode 100644
index 0000000..fc15463
--- /dev/null
+++ b/scripts/MainScene.gd
@@ -0,0 +1,13 @@
+extends Control
+
+
+func _ready():
+ if OS.get_name() == "HTML5": # running on web
+ var lobby_id = JavaScript.eval("new URLSearchParams(document.location.search).get('lobby_id')")
+ var gc_url = JavaScript.eval("new URLSearchParams(document.location.search).get('gc_url')")
+ var password = JavaScript.eval("new URLSearchParams(document.location.search).get('pw')")
+ if lobby_id:
+ var pw : String = password if password else ""
+ $MainMenu.join_menu_button_pressed(lobby_id, pw)
+ if gc_url:
+ Globals.update_gc_url(gc_url)
diff --git a/scripts/Plane.gd b/scripts/Plane.gd
index 62ffc43..6889e31 100644
--- a/scripts/Plane.gd
+++ b/scripts/Plane.gd
@@ -1,22 +1,25 @@
extends Area
-var starting_altitude:int = 0 # initial altitude for the turn, determines number of actions
-var altitude:int = 0 # 0, 1, or 2
-var pos_x:int
-var pos_y:int
+var starting_altitude: int = 0 # initial altitude for the turn, determines number of actions
+var altitude: int = 0 # 0, 1, or 2
+var pos_x: int
+var pos_y: int
onready var meshes = [$Fuselage, $Cone, $Wings, $Tail]
# bearings: E, NE, NW, W, SW, SE
const bearings = [ [0,1] , [-1, 0], [-1, -1], [0, -1], [1, 0], [1, 1] ]
-var bearing:int = 0 # index of above list of potential bearings
+var bearing: int = 0 # index of above list of potential bearings
var destination_num: int # for display purposes only
var destination_col: Color # for display purposes only
+var destination_name: String # for display purposes
var destination_id: int # determines above ^
var rotation_tween: Tween = null
+var actions: Array = []
+
var plane_material
func _ready():
@@ -25,9 +28,7 @@ func _ready():
mesh.set_surface_material(0, plane_material)
var new_col = Color(randf(), randf(), randf() )
- print(new_col)
set_color(new_col)
-
func set_color(color: Color):
plane_material.set_albedo(color)
diff --git a/scripts/ServerBrowser.gd b/scripts/ServerBrowser.gd
index 3c59b9b..410eec2 100644
--- a/scripts/ServerBrowser.gd
+++ b/scripts/ServerBrowser.gd
@@ -16,6 +16,8 @@ var queued_messages = []
func _ready():
refresh_game_list()
$RefreshButton.connect("pressed", self, "refresh_game_list")
+ $HostPopup/Control/PrivateToggle.connect("toggled", self, "toggle_password_vis")
+ $Username.connect("text_changed", $HostPopup/Control/GameName, "set_text")
func join_game():
$HostPopup.visible = false
@@ -50,6 +52,9 @@ func add_games_to_list(games):
game_list.add_item( game_str, null, true if game["state"] == "LOBBY" else false )
game_ids.append( game["id"] )
+func toggle_password_vis(pressed):
+ $HostPopup/Control/Password.visible = pressed
+
func _process(_delta):
$GameCoordinatorStatus.text = "Game Coordinator Connection: " + str(ws_client.state)