Add player controller, state management, and input handling
- Implemented PlayerController.cs to manage player movement and actions. - Created PlayerState.cs to track player lives, coins, and key status. - Added CameraFollow.cs for smooth camera movement following the player. - Developed Character.cs as an abstract class for character behavior. - Introduced Enums.cs for defining TreasureType and MapElementType. - Added IDoor interface for door interactions. - Created InputActions.cs for handling player input actions. - Implemented MainMenu.cs for basic menu functionality including play and exit options.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public static GameManager Instance { get; private set; }
|
||||
|
||||
[SerializeField] private bool _debugMode = false;
|
||||
|
||||
private bool _hasKey = false;
|
||||
private int _treasureCount = 0;
|
||||
|
||||
public bool HasKey => _hasKey;
|
||||
public int TreasureCount => _treasureCount;
|
||||
|
||||
public event EventHandler<bool> OnKeyStateChanged;
|
||||
public event EventHandler<int> OnTreasureCountChanged;
|
||||
public event EventHandler OnLevelComplete;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Singleton pattern
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
public void SetKeyState(bool hasKey)
|
||||
{
|
||||
if (_hasKey == hasKey)
|
||||
return;
|
||||
|
||||
_hasKey = hasKey;
|
||||
OnKeyStateChanged?.Invoke(this, _hasKey);
|
||||
|
||||
if (_debugMode)
|
||||
Debug.Log($"[GameManager] Key state changed: {_hasKey}");
|
||||
}
|
||||
|
||||
public void AddTreasure(int amount = 1)
|
||||
{
|
||||
_treasureCount += amount;
|
||||
OnTreasureCountChanged?.Invoke(this, _treasureCount);
|
||||
|
||||
if (_debugMode)
|
||||
Debug.Log($"[GameManager] Treasure count: {_treasureCount}");
|
||||
}
|
||||
|
||||
public void CompletLevel()
|
||||
{
|
||||
if (_debugMode)
|
||||
Debug.Log("[GameManager] Level completed!");
|
||||
|
||||
OnLevelComplete?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_hasKey = false;
|
||||
_treasureCount = 0;
|
||||
|
||||
if (_debugMode)
|
||||
Debug.Log("[GameManager] Reset");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user