diff --git a/scenes/golf_tee.gd b/scenes/golf_tee.gd new file mode 100644 index 0000000..bb8a32d --- /dev/null +++ b/scenes/golf_tee.gd @@ -0,0 +1,2 @@ +extends Node2D +class_name GolfTee diff --git a/scenes/golf_tee.tscn b/scenes/golf_tee.tscn new file mode 100644 index 0000000..154bf6e --- /dev/null +++ b/scenes/golf_tee.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://c5vbxqhevocy7"] + +[ext_resource type="Script" path="res://scenes/golf_tee.gd" id="1_wboy6"] + +[node name="GolfTee" type="Node2D"] +script = ExtResource("1_wboy6") diff --git a/scenes/golf_tilemap.tscn b/scenes/golf_tilemap.tscn new file mode 100644 index 0000000..5c2b61d --- /dev/null +++ b/scenes/golf_tilemap.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=2 format=3 uid="uid://dck5lkoxskrel"] + +[ext_resource type="TileSet" uid="uid://17esn8g8xqik" path="res://tiles/hole_tile_set.tres" id="1_uf2u7"] + +[node name="TileMap" type="TileMap"] +tile_set = ExtResource("1_uf2u7") +format = 2 +layer_0/name = "Walls" diff --git a/scenes/level_manager.gd b/scenes/level_manager.gd new file mode 100644 index 0000000..69e1dda --- /dev/null +++ b/scenes/level_manager.gd @@ -0,0 +1,74 @@ +extends Node +class_name LevelManager + +## The levels that should be loaded by the server and sent to the clients. +const levels: Array[PackedScene] = [ + preload("res://scenes/golf_level_1.tscn"), + preload("res://scenes/golf_level_2.tscn"), +] + +## The index of the current level in [field levels]. +var level_idx: int = -1 + +## Class containing the components of a level. +class Components: + ## All levels must include a [TileMap] named "TileMap". + var tilemap: TileMap = null + + ## The [PackedScene] to initialize on clients as [TileMap]. + const tilemap_scene: PackedScene = preload("res://scenes/golf_tilemap.tscn") + + ## All levels must include a [GolfTee] named "GolfTee". + ## + ## It will be used to spawn the player + var tee: GolfTee = null + + ## The [PackedScene] to initialize on clients as [GolfTee]. + const tee_scene: PackedScene = preload("res://scenes/golf_tee.tscn") + + ## All levels must include a [GolfHole] named "GolfHole". + var hole: GolfHole = null + + ## The [PackedScene] to initialize on clients as [GolfHole]. + const hole_scene = preload("res://scenes/golf_hole.tscn") + + ## Create a new [Components] instance from a [PackedScene]. + static func from_scene(scene: PackedScene) -> Components: + var obj = new() + obj.tilemap = scene.get_node("TileMap") + obj.tee = scene.get_node("GolfTee") + obj.hole = scene.get_node("GolfHole") + return obj + + ## Create the [TileMap] object on clients. + @rpc("authority", "call_remote", "reliable") + func rpc_build_tilemap(parent: Node): + var obj = tilemap_scene.instantiate() + parent.add_child(obj) + + ## Create the [GolfTee] object on clients. + @rpc("authority", "call_remote", "reliable") + func rpc_build_tee(parent: Node, position: Vector2): + var obj = tee_scene.instantiate() + obj.position = position + parent.add_child(obj) + + ## Create the [GolfHole] object on clients. + @rpc("authority", "call_remote", "reliable") + func rpc_build_hole(parent: Node, position: Vector2, scale: Vector2): + var obj = hole_scene.instantiate() + obj.position = position + obj.scale = scale + parent.add_child(obj) + + ## TODO: Place tiles + + + +func get_current_level() -> PackedScene: + return levels[level_idx] + + +func load_level_components() -> Components: + return Components.from_scene(get_current_level()) + diff --git a/scenes/level_manager.tscn b/scenes/level_manager.tscn new file mode 100644 index 0000000..22265d2 --- /dev/null +++ b/scenes/level_manager.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://dnryhtnk21ep1"] + +[node name="LevelManager" type="Node"]