Refactored to allow hotseat and multiplayer. TODO: Create interface class for webrtc/enet multiplayer
This commit is contained in:
parent
d688eaf9c6
commit
5fe8f22ccb
27 changed files with 798 additions and 135 deletions
|
|
@ -1,33 +1,6 @@
|
|||
extends CanvasLayer
|
||||
|
||||
@onready var insect_icons: HBoxContainer = $PanelContainer/VBoxContainer/InsectIcons
|
||||
|
||||
@onready var lobby_code: Label = $PanelContainer/VBoxContainer/LobbyCode
|
||||
const INSECT_BUTTON = preload("res://UI/insect_button.tscn")
|
||||
|
||||
const insect_resources = [
|
||||
preload("res://Tile/Prefabs/Ant.tres"),
|
||||
preload("res://Tile/Prefabs/Bee.tres"),
|
||||
preload("res://Tile/Prefabs/Beetle.tres"),
|
||||
preload("res://Tile/Prefabs/Grasshopper.tres"),
|
||||
preload("res://Tile/Prefabs/Ladybug.tres"),
|
||||
preload("res://Tile/Prefabs/Mosquito.tres"),
|
||||
preload("res://Tile/Prefabs/Pillbug.tres"),
|
||||
preload("res://Tile/Prefabs/Spider.tres")
|
||||
]
|
||||
|
||||
var insect_data = {
|
||||
|
||||
}
|
||||
|
||||
func prepare_insect_data() -> void:
|
||||
var c: int = 65
|
||||
|
||||
for i in insect_resources:
|
||||
for k in 2:
|
||||
insect_data[String.chr(c)] = {"resource": i, "is_black": k%2 != 0}
|
||||
c = c + 1
|
||||
|
||||
|
||||
@onready var start_game_button = $PanelContainer/VBoxContainer/StartGameButton
|
||||
|
||||
|
|
@ -41,23 +14,9 @@ func _ready():
|
|||
if not multiplayer.is_server():
|
||||
return
|
||||
|
||||
insect_icons.visible = true
|
||||
start_game_button.visible = true
|
||||
|
||||
lobby_code.text = GameData.lobby_code
|
||||
|
||||
prepare_insect_data()
|
||||
|
||||
for c in GameData.lobby_code:
|
||||
var b = INSECT_BUTTON.instantiate()
|
||||
b.deactivated = true
|
||||
b.disabled = true
|
||||
b.disable_amount_display = true
|
||||
var data = insect_data[c]
|
||||
b.is_black = data.is_black
|
||||
b.insect_resource = data.resource
|
||||
insect_icons.add_child(b)
|
||||
|
||||
lobby_code.text = GameData.lobby_code
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ func _ready():
|
|||
|
||||
func _mp_peer_disconnected(id: int) -> void:
|
||||
has_opponent = false
|
||||
GameData.peer_id = 1
|
||||
start_game_button.disabled = true
|
||||
|
||||
if game_in_progress or id == 1:
|
||||
|
|
@ -41,6 +42,7 @@ func _mp_server_disconnect():
|
|||
func _mp_peer_connected(id: int):
|
||||
_log("[Multiplayer] Peer %d connected" % id)
|
||||
has_opponent = true
|
||||
GameData.peer_id = id
|
||||
start_game_button.disabled = false
|
||||
|
||||
@onready var lobby_info = $LobbyInfo
|
||||
|
|
@ -62,4 +64,3 @@ func load_game() -> void:
|
|||
func _on_start_game_button_pressed():
|
||||
# tell other peer to now load the world via rpc
|
||||
load_game.rpc()
|
||||
pass # Replace with function body.
|
||||
|
|
|
|||
|
|
@ -27,10 +27,6 @@ alignment = 1
|
|||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="InsectIcons" type="HBoxContainer" parent="LobbyInfo/PanelContainer/VBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
[node name="StartGameButton" type="Button" parent="LobbyInfo/PanelContainer/VBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue