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:
@@ -6,43 +6,60 @@ public class HammerThrower : MonoBehaviour
|
||||
[SerializeField] private Transform _spawnPoint;
|
||||
[SerializeField] private GameObject _hammerPrefab;
|
||||
[SerializeField] private float _throwSpeed = 5f;
|
||||
[SerializeField] private float _throwCooldown = 1.5f;
|
||||
|
||||
private GameObject _currentHammer;
|
||||
private bool _hasHammer = true;
|
||||
private bool _facingRight = true;
|
||||
private float _cooldownTimer = 0f;
|
||||
|
||||
public bool HasHammer => _hasHammer;
|
||||
public bool CanThrow => _hasHammer && _cooldownTimer <= 0f;
|
||||
public float CooldownRemaining => Mathf.Max(0f, _cooldownTimer);
|
||||
|
||||
public void SetFacingDirection(bool facingRight)
|
||||
{
|
||||
_facingRight = facingRight;
|
||||
}
|
||||
|
||||
public void ThrowHammer()
|
||||
public bool TryThrowHammer()
|
||||
{
|
||||
if (!_hasHammer)
|
||||
return;
|
||||
if (!CanThrow)
|
||||
return false;
|
||||
|
||||
ThrowHammer();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ThrowHammer()
|
||||
{
|
||||
_hasHammer = false;
|
||||
_cooldownTimer = _throwCooldown;
|
||||
|
||||
_currentHammer = Instantiate(_hammerPrefab, _spawnPoint.position, _spawnPoint.rotation);
|
||||
|
||||
//float direction = _facingRight ? 1f : -1f;
|
||||
// Initialize hammer with direction and speed
|
||||
var hammerComponent = _currentHammer.GetComponent<Hammer>();
|
||||
if (hammerComponent != null)
|
||||
{
|
||||
hammerComponent.Initialize(_facingRight, _throwSpeed);
|
||||
}
|
||||
|
||||
//var rb = _currentHammer.GetComponent<Rigidbody2D>();
|
||||
//rb.linearVelocity = new Vector2(direction * _throwSpeed, 0);
|
||||
|
||||
//// Flip hammer visually
|
||||
//var scale = _currentHammer.transform.localScale;
|
||||
//scale.x = Mathf.Abs(scale.x) * direction;
|
||||
//_currentHammer.transform.localScale = scale;
|
||||
|
||||
_currentHammer.transform.localScale = new Vector2(_currentHammer.transform.localScale.x * (_facingRight ? 1 : -1), _currentHammer.transform.localScale.y);
|
||||
_currentHammer.GetComponent<Rigidbody2D>().linearVelocity = new Vector2(gameObject.transform.localScale.x * _throwSpeed, 0);
|
||||
// Flip hammer visual based on direction
|
||||
_currentHammer.transform.localScale = new Vector2(
|
||||
_currentHammer.transform.localScale.x * (_facingRight ? 1 : -1),
|
||||
_currentHammer.transform.localScale.y
|
||||
);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Update cooldown timer
|
||||
if (_cooldownTimer > 0f)
|
||||
{
|
||||
_cooldownTimer -= Time.deltaTime;
|
||||
}
|
||||
|
||||
// Hammer destroyed → hammer returned
|
||||
if (!_hasHammer && _currentHammer == null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user