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,63 @@
|
||||
using Assets.Scripts;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class Door : MonoBehaviour, IDoor
|
||||
{
|
||||
[SerializeField]
|
||||
private Sprite _openDoor;
|
||||
[SerializeField]
|
||||
private bool _debugMode = false;
|
||||
|
||||
private SpriteRenderer _spriteRenderer;
|
||||
private BoxCollider2D _boxCollider;
|
||||
private bool _isLocked = true;
|
||||
|
||||
public bool IsLocked => _isLocked;
|
||||
|
||||
public event EventHandler OnDoorOpened;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_spriteRenderer = GetComponentInChildren<SpriteRenderer>();
|
||||
_boxCollider = gameObject.GetComponent<BoxCollider2D>();
|
||||
}
|
||||
|
||||
public void OpenDoor()
|
||||
{
|
||||
if (!_isLocked)
|
||||
return;
|
||||
|
||||
_isLocked = false;
|
||||
|
||||
// Update visuals
|
||||
if (_spriteRenderer != null && _openDoor != null)
|
||||
{
|
||||
_spriteRenderer.sprite = _openDoor;
|
||||
}
|
||||
|
||||
// Disable collision
|
||||
if (_boxCollider != null)
|
||||
{
|
||||
_boxCollider.enabled = false;
|
||||
}
|
||||
|
||||
if (_debugMode)
|
||||
Debug.Log("[Door] Door opened!");
|
||||
|
||||
OnDoorOpened?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void LockDoor()
|
||||
{
|
||||
_isLocked = true;
|
||||
|
||||
if (_boxCollider != null)
|
||||
{
|
||||
_boxCollider.enabled = true;
|
||||
}
|
||||
|
||||
if (_debugMode)
|
||||
Debug.Log("[Door] Door locked!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user