generated from krampus/template-godot4
Extracted play management strategy to it's own resource
This commit is contained in:
parent
3d1da45673
commit
358d7c2eb4
|
@ -0,0 +1,23 @@
|
||||||
|
class_name PlayManager extends Resource
|
||||||
|
## Abstract base type for strategies to manage the flow of gameplay
|
||||||
|
|
||||||
|
## List of game player instances
|
||||||
|
@export var players: Array[WorldPlayer] = []
|
||||||
|
|
||||||
|
|
||||||
|
func initialize() -> void:
|
||||||
|
for player: WorldPlayer in players:
|
||||||
|
player.shot_setup.finished.connect(_on_turn_finished)
|
||||||
|
on_initialization()
|
||||||
|
|
||||||
|
|
||||||
|
func on_initialization() -> void:
|
||||||
|
pass # Implemented in derived type
|
||||||
|
|
||||||
|
|
||||||
|
func on_turn_finished(_shot_setup: ShotSetup) -> void:
|
||||||
|
pass # Implemented in derived type
|
||||||
|
|
||||||
|
|
||||||
|
func _on_turn_finished(shot_setup: ShotSetup) -> void:
|
||||||
|
on_turn_finished(shot_setup)
|
|
@ -0,0 +1,14 @@
|
||||||
|
class_name RoundRobinManager extends PlayManager
|
||||||
|
## Players take turns one after the other, looping back to the first player at the end.
|
||||||
|
|
||||||
|
|
||||||
|
func on_initialization() -> void:
|
||||||
|
print("IN ON_INITIALIZATION")
|
||||||
|
# Set first player as active
|
||||||
|
players[0].shot_setup.phase = ShotSetup.Phase.AIM
|
||||||
|
|
||||||
|
|
||||||
|
func on_turn_finished(source: ShotSetup) -> void:
|
||||||
|
print_debug("Shot finished for ", source.player.name)
|
||||||
|
players.push_back(players.pop_front())
|
||||||
|
players[0].shot_setup.queue_restart()
|
|
@ -6,7 +6,7 @@ class_name World extends Node
|
||||||
|
|
||||||
@export var initial_level: PackedScene = load("res://levels/debug_level/debug_level.tscn")
|
@export var initial_level: PackedScene = load("res://levels/debug_level/debug_level.tscn")
|
||||||
|
|
||||||
@export var players: Array[WorldPlayer] = []
|
@export var manager: PlayManager
|
||||||
|
|
||||||
@export var spawn_group := "PlayerSpawn"
|
@export var spawn_group := "PlayerSpawn"
|
||||||
|
|
||||||
|
@ -22,13 +22,11 @@ func _ready() -> void:
|
||||||
load_level(initial_level)
|
load_level(initial_level)
|
||||||
|
|
||||||
# Spawn players in the level
|
# Spawn players in the level
|
||||||
for player: WorldPlayer in players:
|
for player: WorldPlayer in manager.players:
|
||||||
_spawn_player(player)
|
_spawn_player(player)
|
||||||
|
|
||||||
# Set first player as active
|
manager.initialize()
|
||||||
if players:
|
if not manager.players:
|
||||||
players[0].shot_setup.phase = ShotSetup.Phase.AIM
|
|
||||||
else:
|
|
||||||
push_warning("Warning: Starting game world with no players!")
|
push_warning("Warning: Starting game world with no players!")
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,17 +44,10 @@ func _random_spawn() -> Node3D:
|
||||||
func _spawn_player(player: WorldPlayer) -> void:
|
func _spawn_player(player: WorldPlayer) -> void:
|
||||||
var spawn_point := _random_spawn()
|
var spawn_point := _random_spawn()
|
||||||
var shot_setup := player.shot_setup
|
var shot_setup := player.shot_setup
|
||||||
shot_setup.finished.connect(_on_shot_finished)
|
|
||||||
shot_setup.global_transform = spawn_point.global_transform
|
shot_setup.global_transform = spawn_point.global_transform
|
||||||
spawn_point.add_sibling(shot_setup)
|
spawn_point.add_sibling(shot_setup)
|
||||||
|
|
||||||
|
|
||||||
func _on_shot_finished(source: ShotSetup) -> void:
|
|
||||||
print_debug("Shot finished for ", source.player.name)
|
|
||||||
players.push_back(players.pop_front())
|
|
||||||
players[0].shot_setup.queue_restart()
|
|
||||||
|
|
||||||
|
|
||||||
## Instantiate and mantle the given level scene.
|
## Instantiate and mantle the given level scene.
|
||||||
##
|
##
|
||||||
## This will free any currently-loaded level!
|
## This will free any currently-loaded level!
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
[gd_scene load_steps=6 format=3 uid="uid://cwnwcd8kushl3"]
|
[gd_scene load_steps=9 format=3 uid="uid://cwnwcd8kushl3"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://src/world/world.gd" id="1_ybjyx"]
|
[ext_resource type="Script" path="res://src/world/world.gd" id="1_ybjyx"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://bm2o3mex10v11" path="res://levels/debug_level/debug_level.tscn" id="2_0xu5a"]
|
||||||
[ext_resource type="PackedScene" uid="uid://c4ifdiohng830" path="res://src/ui/shot_hud/shot_hud.tscn" id="2_5b7qb"]
|
[ext_resource type="PackedScene" uid="uid://c4ifdiohng830" path="res://src/ui/shot_hud/shot_hud.tscn" id="2_5b7qb"]
|
||||||
[ext_resource type="Script" path="res://src/player/world_player.gd" id="2_e743i"]
|
[ext_resource type="Script" path="res://src/player/world_player.gd" id="2_e743i"]
|
||||||
[ext_resource type="Script" path="res://src/ui/world_ui.gd" id="2_imewa"]
|
[ext_resource type="Script" path="res://src/ui/world_ui.gd" id="2_imewa"]
|
||||||
[ext_resource type="Resource" uid="uid://crock3revdn73" path="res://src/player/debug_player.tres" id="3_pyw81"]
|
[ext_resource type="Resource" uid="uid://crock3revdn73" path="res://src/player/debug_player.tres" id="3_pyw81"]
|
||||||
|
[ext_resource type="Script" path="res://src/world/play_manager/round_robin_manager.gd" id="5_h6mje"]
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id="Resource_rdjhi"]
|
||||||
|
script = ExtResource("5_h6mje")
|
||||||
|
players = Array[ExtResource("2_e743i")]([ExtResource("3_pyw81")])
|
||||||
|
|
||||||
[node name="World" type="Node" groups=["WorldGroup"]]
|
[node name="World" type="Node" groups=["WorldGroup"]]
|
||||||
script = ExtResource("1_ybjyx")
|
script = ExtResource("1_ybjyx")
|
||||||
players = Array[ExtResource("2_e743i")]([ExtResource("3_pyw81")])
|
initial_level = ExtResource("2_0xu5a")
|
||||||
|
manager = SubResource("Resource_rdjhi")
|
||||||
|
|
||||||
[node name="Level" type="Node3D" parent="."]
|
[node name="Level" type="Node3D" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
|
Loading…
Reference in New Issue