Compare commits
2 Commits
master
...
b62478bbea
| Author | SHA1 | Date | |
|---|---|---|---|
| b62478bbea | |||
| 62bdf1ba39 |
@@ -1,5 +1,6 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.Autoloads;
|
namespace Mr.BrickAdventures.Autoloads;
|
||||||
@@ -15,7 +16,7 @@ public partial class AchievementManager : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
LoadAchievementsFromFolder();
|
LoadAchievementsFromFolder();
|
||||||
LoadUnlockedAchievements();
|
LoadUnlockedAchievements();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.Autoloads;
|
namespace Mr.BrickAdventures.Autoloads;
|
||||||
@@ -12,9 +13,9 @@ public partial class ConsoleManager : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_achievementManager = GetNode<AchievementManager>("/root/AchievementManager");
|
_achievementManager = GetNode<AchievementManager>(Constants.AchievementManagerPath);
|
||||||
_skillManager = GetNode<SkillManager>("/root/SkillManager");
|
_skillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddCoinsCommand(int amount)
|
private void AddCoinsCommand(int amount)
|
||||||
|
|||||||
@@ -1,9 +1,130 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures.scripts.components;
|
||||||
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.Autoloads;
|
namespace Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Global event bus for decoupled communication between game systems.
|
||||||
|
/// Use the static Instance property for easy access from anywhere.
|
||||||
|
/// </summary>
|
||||||
public partial class EventBus : Node
|
public partial class EventBus : Node
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Singleton instance. Available after the autoload is initialized.
|
||||||
|
/// </summary>
|
||||||
|
public static EventBus Instance { get; private set; }
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _ExitTree()
|
||||||
|
{
|
||||||
|
if (Instance == this)
|
||||||
|
Instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Level Events
|
||||||
|
|
||||||
[Signal] public delegate void LevelStartedEventHandler(int levelIndex, Node currentScene);
|
[Signal] public delegate void LevelStartedEventHandler(int levelIndex, Node currentScene);
|
||||||
[Signal] public delegate void LevelCompletedEventHandler(int levelIndex, Node currentScene, double completionTime);
|
[Signal] public delegate void LevelCompletedEventHandler(int levelIndex, Node currentScene, double completionTime);
|
||||||
|
[Signal] public delegate void LevelRestartedEventHandler(int levelIndex);
|
||||||
|
|
||||||
|
public static void EmitLevelStarted(int levelIndex, Node currentScene)
|
||||||
|
=> Instance?.EmitSignal(SignalName.LevelStarted, levelIndex, currentScene);
|
||||||
|
|
||||||
|
public static void EmitLevelCompleted(int levelIndex, Node currentScene, double completionTime)
|
||||||
|
=> Instance?.EmitSignal(SignalName.LevelCompleted, levelIndex, currentScene, completionTime);
|
||||||
|
|
||||||
|
public static void EmitLevelRestarted(int levelIndex)
|
||||||
|
=> Instance?.EmitSignal(SignalName.LevelRestarted, levelIndex);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Player Events
|
||||||
|
|
||||||
|
[Signal] public delegate void PlayerSpawnedEventHandler(PlayerController player);
|
||||||
|
[Signal] public delegate void PlayerDiedEventHandler(Vector2 position);
|
||||||
|
[Signal] public delegate void PlayerDamagedEventHandler(float damage, float remainingHealth, Vector2 position);
|
||||||
|
[Signal] public delegate void PlayerHealedEventHandler(float amount, float newHealth, Vector2 position);
|
||||||
|
|
||||||
|
public static void EmitPlayerSpawned(PlayerController player)
|
||||||
|
=> Instance?.EmitSignal(SignalName.PlayerSpawned, player);
|
||||||
|
|
||||||
|
public static void EmitPlayerDied(Vector2 position)
|
||||||
|
=> Instance?.EmitSignal(SignalName.PlayerDied, position);
|
||||||
|
|
||||||
|
public static void EmitPlayerDamaged(float damage, float remainingHealth, Vector2 position)
|
||||||
|
=> Instance?.EmitSignal(SignalName.PlayerDamaged, damage, remainingHealth, position);
|
||||||
|
|
||||||
|
public static void EmitPlayerHealed(float amount, float newHealth, Vector2 position)
|
||||||
|
=> Instance?.EmitSignal(SignalName.PlayerHealed, amount, newHealth, position);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Combat Events
|
||||||
|
|
||||||
|
[Signal] public delegate void EnemyDefeatedEventHandler(Node enemy, Vector2 position);
|
||||||
|
[Signal] public delegate void EnemyDamagedEventHandler(Node enemy, float damage, Vector2 position);
|
||||||
|
|
||||||
|
public static void EmitEnemyDefeated(Node enemy, Vector2 position)
|
||||||
|
=> Instance?.EmitSignal(SignalName.EnemyDefeated, enemy, position);
|
||||||
|
|
||||||
|
public static void EmitEnemyDamaged(Node enemy, float damage, Vector2 position)
|
||||||
|
=> Instance?.EmitSignal(SignalName.EnemyDamaged, enemy, damage, position);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Collection Events
|
||||||
|
|
||||||
|
[Signal] public delegate void CoinCollectedEventHandler(int amount, Vector2 position);
|
||||||
|
[Signal] public delegate void ItemCollectedEventHandler(CollectableType itemType, float amount, Vector2 position);
|
||||||
|
[Signal] public delegate void ChildRescuedEventHandler(Vector2 position);
|
||||||
|
|
||||||
|
public static void EmitCoinCollected(int amount, Vector2 position)
|
||||||
|
=> Instance?.EmitSignal(SignalName.CoinCollected, amount, position);
|
||||||
|
|
||||||
|
public static void EmitItemCollected(CollectableType itemType, float amount, Vector2 position)
|
||||||
|
=> Instance?.EmitSignal(SignalName.ItemCollected, (int)itemType, amount, position);
|
||||||
|
|
||||||
|
public static void EmitChildRescued(Vector2 position)
|
||||||
|
=> Instance?.EmitSignal(SignalName.ChildRescued, position);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Skill Events
|
||||||
|
|
||||||
|
[Signal] public delegate void SkillUnlockedEventHandler(string skillName, int level);
|
||||||
|
[Signal] public delegate void SkillActivatedEventHandler(string skillName);
|
||||||
|
[Signal] public delegate void SkillDeactivatedEventHandler(string skillName);
|
||||||
|
|
||||||
|
public static void EmitSkillUnlocked(string skillName, int level = 1)
|
||||||
|
=> Instance?.EmitSignal(SignalName.SkillUnlocked, skillName, level);
|
||||||
|
|
||||||
|
public static void EmitSkillActivated(string skillName)
|
||||||
|
=> Instance?.EmitSignal(SignalName.SkillActivated, skillName);
|
||||||
|
|
||||||
|
public static void EmitSkillDeactivated(string skillName)
|
||||||
|
=> Instance?.EmitSignal(SignalName.SkillDeactivated, skillName);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Game State Events
|
||||||
|
|
||||||
|
[Signal] public delegate void GamePausedEventHandler();
|
||||||
|
[Signal] public delegate void GameResumedEventHandler();
|
||||||
|
[Signal] public delegate void GameSavedEventHandler();
|
||||||
|
|
||||||
|
public static void EmitGamePaused()
|
||||||
|
=> Instance?.EmitSignal(SignalName.GamePaused);
|
||||||
|
|
||||||
|
public static void EmitGameResumed()
|
||||||
|
=> Instance?.EmitSignal(SignalName.GameResumed);
|
||||||
|
|
||||||
|
public static void EmitGameSaved()
|
||||||
|
=> Instance?.EmitSignal(SignalName.GameSaved);
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
using Double = System.Double;
|
using Double = System.Double;
|
||||||
@@ -11,7 +12,8 @@ public partial class GameManager : Node
|
|||||||
{
|
{
|
||||||
[Export] public Array<PackedScene> LevelScenes { get; set; } = [];
|
[Export] public Array<PackedScene> LevelScenes { get; set; } = [];
|
||||||
|
|
||||||
public PlayerController Player {
|
public PlayerController Player
|
||||||
|
{
|
||||||
get => GetPlayer();
|
get => GetPlayer();
|
||||||
private set => _player = value;
|
private set => _player = value;
|
||||||
}
|
}
|
||||||
@@ -19,7 +21,7 @@ public partial class GameManager : Node
|
|||||||
private List<Node> _sceneNodes = [];
|
private List<Node> _sceneNodes = [];
|
||||||
private PlayerController _player;
|
private PlayerController _player;
|
||||||
private SpeedRunManager _speedRunManager;
|
private SpeedRunManager _speedRunManager;
|
||||||
private EventBus _eventBus;
|
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public Dictionary PlayerState { get; set; } = new()
|
public Dictionary PlayerState { get; set; } = new()
|
||||||
@@ -54,8 +56,8 @@ public partial class GameManager : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_speedRunManager = GetNode<SpeedRunManager>("/root/SpeedRunManager");
|
_speedRunManager = GetNode<SpeedRunManager>(Constants.SpeedRunManagerPath);
|
||||||
_eventBus = GetNode<EventBus>("/root/EventBus");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnNodeAdded(Node node)
|
private void OnNodeAdded(Node node)
|
||||||
@@ -160,7 +162,7 @@ public partial class GameManager : Node
|
|||||||
{
|
{
|
||||||
PlayerState["current_level"] = next;
|
PlayerState["current_level"] = next;
|
||||||
GetTree().ChangeSceneToPacked(LevelScenes[next]);
|
GetTree().ChangeSceneToPacked(LevelScenes[next]);
|
||||||
_eventBus.EmitSignal(EventBus.SignalName.LevelStarted, next, GetTree().CurrentScene);
|
EventBus.EmitLevelStarted(next, GetTree().CurrentScene);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +187,7 @@ public partial class GameManager : Node
|
|||||||
ResetPlayerState();
|
ResetPlayerState();
|
||||||
ResetCurrentSessionState();
|
ResetCurrentSessionState();
|
||||||
GetTree().ChangeSceneToPacked(LevelScenes[0]);
|
GetTree().ChangeSceneToPacked(LevelScenes[0]);
|
||||||
GetNode<SaveSystem>("/root/SaveSystem").SaveGame();
|
GetNode<SaveSystem>(Constants.SaveSystemPath).SaveGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void QuitGame() => GetTree().Quit();
|
public void QuitGame() => GetTree().Quit();
|
||||||
@@ -201,12 +203,12 @@ public partial class GameManager : Node
|
|||||||
_speedRunManager?.StartTimer();
|
_speedRunManager?.StartTimer();
|
||||||
|
|
||||||
GetTree().ChangeSceneToPacked(LevelScenes[0]);
|
GetTree().ChangeSceneToPacked(LevelScenes[0]);
|
||||||
GetNode<SaveSystem>("/root/SaveSystem").SaveGame();
|
GetNode<SaveSystem>(Constants.SaveSystemPath).SaveGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ContinueGame()
|
public void ContinueGame()
|
||||||
{
|
{
|
||||||
var save = GetNode<SaveSystem>("/root/SaveSystem");
|
var save = GetNode<SaveSystem>(Constants.SaveSystemPath);
|
||||||
if (!save.LoadGame())
|
if (!save.LoadGame())
|
||||||
{
|
{
|
||||||
GD.PrintErr("Failed to load game. Starting a new game instead.");
|
GD.PrintErr("Failed to load game. Starting a new game instead.");
|
||||||
@@ -231,11 +233,11 @@ public partial class GameManager : Node
|
|||||||
UnlockSkill((SkillData)s);
|
UnlockSkill((SkillData)s);
|
||||||
|
|
||||||
var completionTime = _speedRunManager?.GetCurrentLevelTime() ?? 0.0;
|
var completionTime = _speedRunManager?.GetCurrentLevelTime() ?? 0.0;
|
||||||
_eventBus.EmitSignal(EventBus.SignalName.LevelCompleted, levelIndex, GetTree().CurrentScene, completionTime);
|
EventBus.EmitLevelCompleted(levelIndex, GetTree().CurrentScene, completionTime);
|
||||||
|
|
||||||
ResetCurrentSessionState();
|
ResetCurrentSessionState();
|
||||||
TryToGoToNextLevel();
|
TryToGoToNextLevel();
|
||||||
GetNode<SaveSystem>("/root/SaveSystem").SaveGame();
|
GetNode<SaveSystem>(Constants.SaveSystemPath).SaveGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Array<SkillData> GetUnlockedSkills()
|
public Array<SkillData> GetUnlockedSkills()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.Autoloads;
|
namespace Mr.BrickAdventures.Autoloads;
|
||||||
@@ -13,7 +14,7 @@ public partial class SaveSystem : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveGame()
|
public void SaveGame()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
using Mr.BrickAdventures.scripts.interfaces;
|
using Mr.BrickAdventures.scripts.interfaces;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
@@ -24,7 +25,7 @@ public partial class SkillManager : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.Autoloads;
|
namespace Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
@@ -11,8 +12,8 @@ public partial class StatisticsManager : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_achievementManager = GetNode<AchievementManager>("/root/AchievementManager");
|
_achievementManager = GetNode<AchievementManager>(Constants.AchievementManagerPath);
|
||||||
LoadStatistics();
|
LoadStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=58 format=3 uid="uid://bqi5s710xb1ju"]
|
[gd_scene load_steps=57 format=3 uid="uid://bqi5s710xb1ju"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://csel4s0e4g5uf" path="res://scripts/components/PlayerController.cs" id="1_yysbb"]
|
[ext_resource type="Script" uid="uid://csel4s0e4g5uf" path="res://scripts/components/PlayerController.cs" id="1_yysbb"]
|
||||||
[ext_resource type="Shader" uid="uid://bs4xvm4qkurpr" path="res://shaders/hit_flash.tres" id="2_lgb3u"]
|
[ext_resource type="Shader" uid="uid://bs4xvm4qkurpr" path="res://shaders/hit_flash.tres" id="2_lgb3u"]
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
[ext_resource type="PackedScene" uid="uid://dre1vit1m4d2n" path="res://objects/movement_abilities/grid_movement_ability.tscn" id="8_xuhvf"]
|
[ext_resource type="PackedScene" uid="uid://dre1vit1m4d2n" path="res://objects/movement_abilities/grid_movement_ability.tscn" id="8_xuhvf"]
|
||||||
[ext_resource type="Script" uid="uid://dy78ak8eykw6e" path="res://scripts/components/FlipComponent.cs" id="9_yysbb"]
|
[ext_resource type="Script" uid="uid://dy78ak8eykw6e" path="res://scripts/components/FlipComponent.cs" id="9_yysbb"]
|
||||||
[ext_resource type="Script" uid="uid://mnjg3p0aw1ow" path="res://scripts/components/CanPickUpComponent.cs" id="10_yysbb"]
|
[ext_resource type="Script" uid="uid://mnjg3p0aw1ow" path="res://scripts/components/CanPickUpComponent.cs" id="10_yysbb"]
|
||||||
[ext_resource type="Script" uid="uid://ccqb8kd5m0eh7" path="res://scripts/components/ScoreComponent.cs" id="11_o1ihh"]
|
|
||||||
[ext_resource type="Script" uid="uid://dgb8bqcri7nsj" path="res://scripts/components/HealthComponent.cs" id="12_ur2y5"]
|
[ext_resource type="Script" uid="uid://dgb8bqcri7nsj" path="res://scripts/components/HealthComponent.cs" id="12_ur2y5"]
|
||||||
[ext_resource type="Script" uid="uid://byw1legrv1ep2" path="res://scripts/components/PlayerDeathComponent.cs" id="13_7til7"]
|
[ext_resource type="Script" uid="uid://byw1legrv1ep2" path="res://scripts/components/PlayerDeathComponent.cs" id="13_7til7"]
|
||||||
[ext_resource type="Script" uid="uid://cecelixl41t3j" path="res://scripts/components/InvulnerabilityComponent.cs" id="15_xuhvf"]
|
[ext_resource type="Script" uid="uid://cecelixl41t3j" path="res://scripts/components/InvulnerabilityComponent.cs" id="15_xuhvf"]
|
||||||
@@ -175,9 +174,6 @@ shape = SubResource("RectangleShape2D_vad0t")
|
|||||||
[node name="CanPickUpComponent" type="Node" parent="."]
|
[node name="CanPickUpComponent" type="Node" parent="."]
|
||||||
script = ExtResource("10_yysbb")
|
script = ExtResource("10_yysbb")
|
||||||
|
|
||||||
[node name="ScoreComponent" type="Node" parent="."]
|
|
||||||
script = ExtResource("11_o1ihh")
|
|
||||||
|
|
||||||
[node name="HealthComponent" type="Node2D" parent="." node_paths=PackedStringArray("HurtSfx", "HealSfx")]
|
[node name="HealthComponent" type="Node2D" parent="." node_paths=PackedStringArray("HurtSfx", "HealSfx")]
|
||||||
script = ExtResource("12_ur2y5")
|
script = ExtResource("12_ur2y5")
|
||||||
HurtSfx = NodePath("../sfx_hurt")
|
HurtSfx = NodePath("../sfx_hurt")
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ EventBus="*res://Autoloads/EventBus.cs"
|
|||||||
StatisticsManager="*res://Autoloads/StatisticsManager.cs"
|
StatisticsManager="*res://Autoloads/StatisticsManager.cs"
|
||||||
SpeedRunManager="res://Autoloads/SpeedRunManager.cs"
|
SpeedRunManager="res://Autoloads/SpeedRunManager.cs"
|
||||||
GhostManager="res://objects/ghost_manager.tscn"
|
GhostManager="res://objects/ghost_manager.tscn"
|
||||||
|
ScoreEventHandler="*res://scripts/Events/ScoreEventHandler.cs"
|
||||||
|
StatisticsEventHandler="*res://scripts/Events/StatisticsEventHandler.cs"
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
|
|
||||||
|
|||||||
24
scripts/Constants.cs
Normal file
24
scripts/Constants.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
namespace Mr.BrickAdventures;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constants for autoload paths and other commonly used values.
|
||||||
|
/// </summary>
|
||||||
|
public static class Constants
|
||||||
|
{
|
||||||
|
// Autoload paths
|
||||||
|
public const string EventBusPath = "/root/EventBus";
|
||||||
|
public const string GameManagerPath = "/root/GameManager";
|
||||||
|
public const string SaveSystemPath = "/root/SaveSystem";
|
||||||
|
public const string SpeedRunManagerPath = "/root/SpeedRunManager";
|
||||||
|
public const string GhostManagerPath = "/root/GhostManager";
|
||||||
|
public const string AchievementManagerPath = "/root/AchievementManager";
|
||||||
|
public const string StatisticsManagerPath = "/root/StatisticsManager";
|
||||||
|
public const string SkillManagerPath = "/root/SkillManager";
|
||||||
|
public const string FloatingTextManagerPath = "/root/FloatingTextManager";
|
||||||
|
public const string UIManagerPath = "/root/UIManager";
|
||||||
|
public const string ConsoleManagerPath = "/root/ConsoleManager";
|
||||||
|
public const string ConfigFileHandlerPath = "/root/ConfigFileHandler";
|
||||||
|
|
||||||
|
// Group names
|
||||||
|
public const string CoinsGroup = "coins";
|
||||||
|
}
|
||||||
1
scripts/Constants.cs.uid
Normal file
1
scripts/Constants.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bn7o3n3bomvrd
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.Events;
|
namespace Mr.BrickAdventures.scripts.Events;
|
||||||
@@ -10,11 +11,10 @@ public partial class GhostEventHandler : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_ghostManager = GetNode<GhostManager>("/root/GhostManager");
|
_ghostManager = GetNode<GhostManager>(Constants.GhostManagerPath);
|
||||||
var eventBus = GetNode<EventBus>("/root/EventBus");
|
|
||||||
|
|
||||||
eventBus.LevelStarted += OnLevelStarted;
|
EventBus.Instance.LevelStarted += OnLevelStarted;
|
||||||
eventBus.LevelCompleted += OnLevelCompleted;
|
EventBus.Instance.LevelCompleted += OnLevelCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnLevelStarted(int levelIndex, Node currentScene)
|
private void OnLevelStarted(int levelIndex, Node currentScene)
|
||||||
|
|||||||
34
scripts/Events/ScoreEventHandler.cs
Normal file
34
scripts/Events/ScoreEventHandler.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
|
namespace Mr.BrickAdventures.scripts.Events;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles coin collection events and updates the session state.
|
||||||
|
/// Replaces the manual signal wiring in ScoreComponent.
|
||||||
|
/// </summary>
|
||||||
|
public partial class ScoreEventHandler : Node
|
||||||
|
{
|
||||||
|
private GameManager _gameManager;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
|
|
||||||
|
EventBus.Instance.CoinCollected += OnCoinCollected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _ExitTree()
|
||||||
|
{
|
||||||
|
if (EventBus.Instance != null)
|
||||||
|
EventBus.Instance.CoinCollected -= OnCoinCollected;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCoinCollected(int amount, Vector2 position)
|
||||||
|
{
|
||||||
|
var currentCoins = (int)_gameManager.CurrentSessionState["coins_collected"];
|
||||||
|
_gameManager.CurrentSessionState["coins_collected"] = currentCoins + amount;
|
||||||
|
GD.Print($"ScoreEventHandler: Collected {amount} coins. Total session coins: {currentCoins + amount}");
|
||||||
|
}
|
||||||
|
}
|
||||||
1
scripts/Events/ScoreEventHandler.cs.uid
Normal file
1
scripts/Events/ScoreEventHandler.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://cs4cfk7g5vh2v
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.Events;
|
namespace Mr.BrickAdventures.scripts.Events;
|
||||||
@@ -10,10 +11,9 @@ public partial class SpeedRunEventHandler : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_speedRunManager = GetNode<SpeedRunManager>("/root/SpeedRunManager");
|
_speedRunManager = GetNode<SpeedRunManager>(Constants.SpeedRunManagerPath);
|
||||||
var eventBus = GetNode<EventBus>("/root/EventBus");
|
|
||||||
|
|
||||||
eventBus.LevelCompleted += OnLevelCompleted;
|
EventBus.Instance.LevelCompleted += OnLevelCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime)
|
private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime)
|
||||||
|
|||||||
62
scripts/Events/StatisticsEventHandler.cs
Normal file
62
scripts/Events/StatisticsEventHandler.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
|
namespace Mr.BrickAdventures.scripts.Events;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles game events and updates statistics accordingly.
|
||||||
|
/// Listens to EventBus signals and increments relevant stats.
|
||||||
|
/// </summary>
|
||||||
|
public partial class StatisticsEventHandler : Node
|
||||||
|
{
|
||||||
|
private StatisticsManager _statisticsManager;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
_statisticsManager = GetNode<StatisticsManager>(Constants.StatisticsManagerPath);
|
||||||
|
|
||||||
|
// Subscribe to events
|
||||||
|
EventBus.Instance.CoinCollected += OnCoinCollected;
|
||||||
|
EventBus.Instance.EnemyDefeated += OnEnemyDefeated;
|
||||||
|
EventBus.Instance.PlayerDied += OnPlayerDied;
|
||||||
|
EventBus.Instance.LevelCompleted += OnLevelCompleted;
|
||||||
|
EventBus.Instance.ChildRescued += OnChildRescued;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _ExitTree()
|
||||||
|
{
|
||||||
|
if (EventBus.Instance == null) return;
|
||||||
|
|
||||||
|
EventBus.Instance.CoinCollected -= OnCoinCollected;
|
||||||
|
EventBus.Instance.EnemyDefeated -= OnEnemyDefeated;
|
||||||
|
EventBus.Instance.PlayerDied -= OnPlayerDied;
|
||||||
|
EventBus.Instance.LevelCompleted -= OnLevelCompleted;
|
||||||
|
EventBus.Instance.ChildRescued -= OnChildRescued;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCoinCollected(int amount, Vector2 position)
|
||||||
|
{
|
||||||
|
_statisticsManager.IncrementStat("coins_collected", amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEnemyDefeated(Node enemy, Vector2 position)
|
||||||
|
{
|
||||||
|
_statisticsManager.IncrementStat("enemies_defeated");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPlayerDied(Vector2 position)
|
||||||
|
{
|
||||||
|
_statisticsManager.IncrementStat("deaths");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime)
|
||||||
|
{
|
||||||
|
_statisticsManager.IncrementStat("levels_completed");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnChildRescued(Vector2 position)
|
||||||
|
{
|
||||||
|
_statisticsManager.IncrementStat("children_rescued");
|
||||||
|
}
|
||||||
|
}
|
||||||
1
scripts/Events/StatisticsEventHandler.cs.uid
Normal file
1
scripts/Events/StatisticsEventHandler.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://l68tjau3k6bw
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -16,8 +17,8 @@ public partial class AudioSettings : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_uiManager = GetNode<UIManager>("/root/UIManager");
|
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
||||||
_configFileHandler = GetNode<ConfigFileHandler>("/root/ConfigFileHandler");
|
_configFileHandler = GetNode<ConfigFileHandler>(Constants.ConfigFileHandlerPath);
|
||||||
Initialize();
|
Initialize();
|
||||||
MasterVolumeSlider.ValueChanged += OnMasterVolumeChanged;
|
MasterVolumeSlider.ValueChanged += OnMasterVolumeChanged;
|
||||||
MusicVolumeSlider.ValueChanged += OnMusicVolumeChanged;
|
MusicVolumeSlider.ValueChanged += OnMusicVolumeChanged;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
@@ -17,7 +18,7 @@ public partial class ChargeProgressBar : ProgressBar
|
|||||||
{
|
{
|
||||||
ProgressBar.Hide();
|
ProgressBar.Hide();
|
||||||
|
|
||||||
_skillManager = GetNodeOrNull<SkillManager>("/root/SkillManager");
|
_skillManager = GetNodeOrNull<SkillManager>(Constants.SkillManagerPath);
|
||||||
if (_skillManager == null)
|
if (_skillManager == null)
|
||||||
{
|
{
|
||||||
GD.PrintErr("ChargeProgressBar: SkillManager autoload not found.");
|
GD.PrintErr("ChargeProgressBar: SkillManager autoload not found.");
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -9,7 +10,7 @@ public partial class Credits : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_uiManager = GetNode<UIManager>("/root/UIManager");
|
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _UnhandledInput(InputEvent @event)
|
public override void _UnhandledInput(InputEvent @event)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ public partial class DeathScreen : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
SetLabels();
|
SetLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -14,7 +15,7 @@ public partial class GameOverScreen : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
RestartButton.Pressed += OnRestartClicked;
|
RestartButton.Pressed += OnRestartClicked;
|
||||||
MainMenuButton.Pressed += OnMainMenuClicked;
|
MainMenuButton.Pressed += OnMainMenuClicked;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ public partial class Hud : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -21,9 +22,9 @@ public partial class MainMenu : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_saveSystem = GetNode<SaveSystem>("/root/SaveSystem");
|
_saveSystem = GetNode<SaveSystem>(Constants.SaveSystemPath);
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_uiManager = GetNode<UIManager>("/root/UIManager");
|
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
||||||
|
|
||||||
NewGameButton.Pressed += OnNewGamePressed;
|
NewGameButton.Pressed += OnNewGamePressed;
|
||||||
ContinueButton.Pressed += OnContinuePressed;
|
ContinueButton.Pressed += OnContinuePressed;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
@@ -25,8 +26,8 @@ public partial class Marketplace : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_skillManager = GetNode<SkillManager>("/root/SkillManager");
|
_skillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||||
_skillManager.SkillRemoved += OnSkillRemoved;
|
_skillManager.SkillRemoved += OnSkillRemoved;
|
||||||
|
|
||||||
Skills = _skillManager.AvailableSkills;
|
Skills = _skillManager.AvailableSkills;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
@@ -18,7 +19,7 @@ public partial class MarketplaceButton : Button
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
var player = _gameManager.Player;
|
var player = _gameManager.Player;
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ public partial class MarketplaceButton : Button
|
|||||||
_skillUnlockerComponent.SkillUnlocked += OnSkillStateChanged;
|
_skillUnlockerComponent.SkillUnlocked += OnSkillStateChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
_skillManager = GetNode<SkillManager>("/root/SkillManager");
|
_skillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||||
_skillManager.SkillRemoved += OnSkillStateChanged;
|
_skillManager.SkillRemoved += OnSkillStateChanged;
|
||||||
|
|
||||||
UpdateButtonState();
|
UpdateButtonState();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -18,8 +19,8 @@ public partial class PauseMenu : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_uiManager = GetNode<UIManager>("/root/UIManager");
|
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
||||||
|
|
||||||
ResumeButton.Pressed += OnResumePressed;
|
ResumeButton.Pressed += OnResumePressed;
|
||||||
MainMenuButton.Pressed += OnMainMenuPressed;
|
MainMenuButton.Pressed += OnMainMenuPressed;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -19,7 +20,7 @@ public partial class SettingsMenu : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_uiManager = GetNode<UIManager>("/root/UIManager");
|
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
||||||
|
|
||||||
InputSettingsButton.Pressed += OnInputSettingsPressed;
|
InputSettingsButton.Pressed += OnInputSettingsPressed;
|
||||||
AudioSettingsButton.Pressed += OnAudioSettingsPressed;
|
AudioSettingsButton.Pressed += OnAudioSettingsPressed;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -12,7 +13,7 @@ public partial class SpeedRunHud : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_speedRunManager = GetNode<SpeedRunManager>("/root/SpeedRunManager");
|
_speedRunManager = GetNode<SpeedRunManager>(Constants.SpeedRunManagerPath);
|
||||||
|
|
||||||
_speedRunManager.TimeUpdated += OnTimerUpdated;
|
_speedRunManager.TimeUpdated += OnTimerUpdated;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.interfaces;
|
using Mr.BrickAdventures.scripts.interfaces;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
@@ -19,8 +20,8 @@ public partial class BrickShieldSkillComponent : Node, ISkill
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_skillManager = GetNode<SkillManager>("/root/SkillManager");
|
_skillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize(Node owner, SkillData data)
|
public void Initialize(Node owner, SkillData data)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ public partial class CollectableComponent : Node
|
|||||||
if (Owner.HasNode("FadeAwayComponent"))
|
if (Owner.HasNode("FadeAwayComponent"))
|
||||||
_hasFadeAway = true;
|
_hasFadeAway = true;
|
||||||
|
|
||||||
_floatingTextManager = GetNode<FloatingTextManager>("/root/FloatingTextManager");
|
_floatingTextManager = GetNode<FloatingTextManager>(Constants.FloatingTextManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnArea2DBodyEntered(Node2D body)
|
private async void OnArea2DBodyEntered(Node2D body)
|
||||||
@@ -53,12 +54,18 @@ public partial class CollectableComponent : Node
|
|||||||
{
|
{
|
||||||
case CollectableType.Coin:
|
case CollectableType.Coin:
|
||||||
_floatingTextManager?.ShowCoin((int)Data.Amount, ownerNode.GlobalPosition);
|
_floatingTextManager?.ShowCoin((int)Data.Amount, ownerNode.GlobalPosition);
|
||||||
|
EventBus.EmitCoinCollected((int)Data.Amount, ownerNode.GlobalPosition);
|
||||||
break;
|
break;
|
||||||
case CollectableType.Health:
|
case CollectableType.Health:
|
||||||
_floatingTextManager?.ShowMessage("Healed!", ownerNode.GlobalPosition);
|
_floatingTextManager?.ShowMessage("Healed!", ownerNode.GlobalPosition);
|
||||||
|
EventBus.EmitItemCollected(Data.Type, Data.Amount, ownerNode.GlobalPosition);
|
||||||
break;
|
break;
|
||||||
case CollectableType.Kid:
|
case CollectableType.Kid:
|
||||||
_floatingTextManager?.ShowMessage("Rescued!", ownerNode.GlobalPosition);
|
_floatingTextManager?.ShowMessage("Rescued!", ownerNode.GlobalPosition);
|
||||||
|
EventBus.EmitChildRescued(ownerNode.GlobalPosition);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
EventBus.EmitItemCollected(Data.Type, Data.Amount, ownerNode.GlobalPosition);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.components;
|
namespace Mr.BrickAdventures.scripts.components;
|
||||||
|
|
||||||
@@ -34,6 +35,12 @@ public partial class EnemyDeathComponent : Node
|
|||||||
|
|
||||||
private async Task Die()
|
private async Task Die()
|
||||||
{
|
{
|
||||||
|
// Emit enemy defeated event for statistics and other systems
|
||||||
|
if (Owner is Node2D ownerNode)
|
||||||
|
{
|
||||||
|
EventBus.EmitEnemyDefeated(Owner, ownerNode.GlobalPosition);
|
||||||
|
}
|
||||||
|
|
||||||
CollisionShape.SetDisabled(true);
|
CollisionShape.SetDisabled(true);
|
||||||
var tween = CreateTween();
|
var tween = CreateTween();
|
||||||
tween.TweenProperty(Owner, "scale", Vector2.Zero, TweenDuration);
|
tween.TweenProperty(Owner, "scale", Vector2.Zero, TweenDuration);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.interfaces;
|
using Mr.BrickAdventures.scripts.interfaces;
|
||||||
|
|
||||||
@@ -20,8 +21,8 @@ public partial class ExitDoorComponent : Area2D, IUnlockable
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_achievementManager = GetNode<AchievementManager>("/root/AchievementManager");
|
_achievementManager = GetNode<AchievementManager>(Constants.AchievementManagerPath);
|
||||||
|
|
||||||
BodyEntered += OnExitAreaBodyEntered;
|
BodyEntered += OnExitAreaBodyEntered;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.components;
|
namespace Mr.BrickAdventures.scripts.components;
|
||||||
@@ -19,7 +20,7 @@ public partial class HealthComponent : Node2D
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_floatingTextManager = GetNode<FloatingTextManager>("/root/FloatingTextManager");
|
_floatingTextManager = GetNode<FloatingTextManager>(Constants.FloatingTextManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetHealth(float newValue)
|
public void SetHealth(float newValue)
|
||||||
@@ -70,10 +71,21 @@ public partial class HealthComponent : Node2D
|
|||||||
if (Health <= 0f)
|
if (Health <= 0f)
|
||||||
{
|
{
|
||||||
EmitSignalDeath();
|
EmitSignalDeath();
|
||||||
|
// Emit global event if this is the player
|
||||||
|
if (Owner is PlayerController)
|
||||||
|
EventBus.EmitPlayerDied(GlobalPosition);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EmitSignalHealthChanged(delta, Health);
|
EmitSignalHealthChanged(delta, Health);
|
||||||
|
// Emit global events if this is the player
|
||||||
|
if (Owner is PlayerController)
|
||||||
|
{
|
||||||
|
if (delta < 0f)
|
||||||
|
EventBus.EmitPlayerDamaged(Mathf.Abs(delta), Health, GlobalPosition);
|
||||||
|
else
|
||||||
|
EventBus.EmitPlayerHealed(delta, Health, GlobalPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.components;
|
namespace Mr.BrickAdventures.scripts.components;
|
||||||
@@ -20,7 +21,7 @@ public partial class LeverComponent : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_floatingTextManager = GetNode<FloatingTextManager>("/root/FloatingTextManager");
|
_floatingTextManager = GetNode<FloatingTextManager>(Constants.FloatingTextManagerPath);
|
||||||
|
|
||||||
if (Area == null)
|
if (Area == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.components;
|
namespace Mr.BrickAdventures.scripts.components;
|
||||||
@@ -33,7 +34,7 @@ public partial class PlayerController : CharacterBody2D
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
var skillManager = GetNodeOrNull<SkillManager>("/root/SkillManager");
|
var skillManager = GetNodeOrNull<SkillManager>(Constants.SkillManagerPath);
|
||||||
skillManager?.RegisterPlayer(this);
|
skillManager?.RegisterPlayer(this);
|
||||||
|
|
||||||
_inputHandler = GetNode<PlayerInputHandler>("PlayerInputHandler");
|
_inputHandler = GetNode<PlayerInputHandler>("PlayerInputHandler");
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.components;
|
namespace Mr.BrickAdventures.scripts.components;
|
||||||
@@ -15,7 +16,7 @@ public partial class PlayerDeathComponent : Node2D
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
HealthComponent.Death += OnDeath;
|
HealthComponent.Death += OnDeath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
using Godot;
|
|
||||||
using Mr.BrickAdventures.Autoloads;
|
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.components;
|
|
||||||
|
|
||||||
[GlobalClass]
|
|
||||||
public partial class ScoreComponent : Node
|
|
||||||
{
|
|
||||||
private GameManager _gameManager;
|
|
||||||
private const string CoinsGroupName = "coins";
|
|
||||||
|
|
||||||
public override async void _Ready()
|
|
||||||
{
|
|
||||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
||||||
|
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
|
||||||
if (_gameManager == null)
|
|
||||||
{
|
|
||||||
GD.PrintErr("GameManager not found in the scene tree.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var coins = GetTree().GetNodesInGroup(CoinsGroupName);
|
|
||||||
foreach (var coin in coins)
|
|
||||||
{
|
|
||||||
var c = coin.GetNodeOrNull<CollectableComponent>("CollectableComponent");
|
|
||||||
if (c != null)
|
|
||||||
{
|
|
||||||
c.Collected += OnCollected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnCollected(float amount, CollectableType type, Node2D body)
|
|
||||||
{
|
|
||||||
if (type != CollectableType.Coin) return;
|
|
||||||
|
|
||||||
var coinAmount = (int)amount;
|
|
||||||
var currentCoins = (int)_gameManager.CurrentSessionState["coins_collected"];
|
|
||||||
_gameManager.CurrentSessionState["coins_collected"] = currentCoins + coinAmount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://ccqb8kd5m0eh7
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.interfaces;
|
using Mr.BrickAdventures.scripts.interfaces;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
@@ -18,8 +19,8 @@ public partial class SkillUnlockerComponent : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
SkillManager = GetNode<SkillManager>("/root/SkillManager");
|
SkillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool HasEnoughCoins(int amount)
|
private bool HasEnoughCoins(int amount)
|
||||||
|
|||||||
Reference in New Issue
Block a user