1
Fork 0
mirror of https://github.com/Steffo99/nanogolf.git synced 2024-11-24 17:14:19 +00:00

Begin working on level manager

This commit is contained in:
Steffo 2024-03-12 17:31:26 +01:00
parent 151620216e
commit dd0ab7ee54
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
5 changed files with 93 additions and 0 deletions

2
scenes/golf_tee.gd Normal file
View file

@ -0,0 +1,2 @@
extends Node2D
class_name GolfTee

6
scenes/golf_tee.tscn Normal file
View file

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

8
scenes/golf_tilemap.tscn Normal file
View file

@ -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"

74
scenes/level_manager.gd Normal file
View file

@ -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())

View file

@ -0,0 +1,3 @@
[gd_scene format=3 uid="uid://dnryhtnk21ep1"]
[node name="LevelManager" type="Node"]