108 lines
3.1 KiB
GDScript
108 lines
3.1 KiB
GDScript
extends Control
|
|
|
|
@onready var exit_button = $VBoxContainer/PanelContainer/MarginContainer/VBoxContainer/ExitButton
|
|
@onready var lan_button = $VBoxContainer/PanelContainer/MarginContainer/VBoxContainer/LANButton
|
|
|
|
const SETTINGS = preload("res://UI/Settings/Settings.tscn")
|
|
const RULES = preload("res://UI/Rules/Rules.tscn")
|
|
|
|
const ANT = preload("res://InsectTiles/Assets/UI/ant.png")
|
|
const BEE = preload("res://InsectTiles/Assets/UI/bee.png")
|
|
const BEETLE = preload("res://InsectTiles/Assets/UI/beetle.png")
|
|
const GRASSHOPPER = preload("res://InsectTiles/Assets/UI/grasshopper.png")
|
|
const HEX_WHITE = preload("res://InsectTiles/Assets/UI/hex_white.svg")
|
|
const LADYBUG = preload("res://InsectTiles/Assets/UI/ladybug.png")
|
|
const MOSQUITO = preload("res://InsectTiles/Assets/UI/mosquito.png")
|
|
const PILLBUG = preload("res://InsectTiles/Assets/UI/pillbug.png")
|
|
const SPIDER = preload("res://InsectTiles/Assets/UI/spider.png")
|
|
|
|
const INSECTS_UI = [ANT, BEE, BEETLE, GRASSHOPPER, LADYBUG, MOSQUITO, PILLBUG, SPIDER]
|
|
@onready var insects: Node2D = $Insects
|
|
|
|
@onready var credits_panel = $CreditsPanel
|
|
const INSECT_SPRITE = preload("res://UI/TestBG/InsectSprite.tscn")
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
if OS.has_feature("web"):
|
|
exit_button.visible = false
|
|
lan_button.visible = false
|
|
|
|
#WSClient.lobby_joined.connect(_on_lobby_joined)
|
|
Networking.offline_mode()
|
|
GameData.reset()
|
|
|
|
get_viewport().size_changed.connect(resize)
|
|
resize()
|
|
|
|
func resize() -> void:
|
|
var _size = get_viewport().size
|
|
print(_size)
|
|
|
|
var center = _size / 2
|
|
_create_insects(center)
|
|
|
|
func _create_insects(center: Vector2i) -> void:
|
|
# For circle
|
|
var circle_position = Vector2i(center.x, center.y)
|
|
var circle_radius = max(center.x, center.y)
|
|
var points = PoissonDiscSampling.generate_points_for_circle(circle_position, circle_radius, 150, 30)
|
|
|
|
for insect in insects.get_children():
|
|
insect.queue_free()
|
|
|
|
for point in points:
|
|
var sprite = INSECT_SPRITE.instantiate()
|
|
insects.add_child(sprite)
|
|
sprite.texture = INSECTS_UI.pick_random()
|
|
sprite.position = point
|
|
|
|
func _on_lobby_joined(lobby: String) -> void:
|
|
GameData.lobby_code = lobby
|
|
|
|
get_tree().change_scene_to_file("res://Multiplayer/Multiplayer.tscn")
|
|
|
|
|
|
func _on_host_button_pressed():
|
|
GameData.is_player_black = false
|
|
#WSClient.start(GameData.WEBSOCKET_ENDPOINT, "", false)
|
|
|
|
|
|
func _on_join_button_pressed():
|
|
get_tree().change_scene_to_file("res://UI/join_menu.tscn")
|
|
|
|
|
|
func _on_exit_button_pressed():
|
|
get_tree().quit()
|
|
|
|
|
|
func _on_rules_button_pressed():
|
|
var rules = RULES.instantiate()
|
|
|
|
get_tree().root.add_child(rules)
|
|
|
|
rules.show_panel()
|
|
|
|
|
|
func _on_online_button_pressed():
|
|
get_tree().change_scene_to_file("res://UI/Lobby/WebRTCLobby.tscn")
|
|
|
|
func _on_local_button_pressed():
|
|
GameData.is_hot_seat = true
|
|
get_tree().change_scene_to_file("res://Game.tscn")
|
|
|
|
|
|
func _on_settings_button_pressed():
|
|
var settings = SETTINGS.instantiate()
|
|
|
|
get_tree().root.add_child(settings)
|
|
|
|
settings.show_panel()
|
|
|
|
|
|
func _on_lan_button_pressed():
|
|
get_tree().change_scene_to_file("res://UI/Lobby/LANLobby.tscn")
|
|
|
|
|
|
func _on_credits_button_pressed():
|
|
credits_panel.visible = true
|
|
pass # Replace with function body.
|