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:
2026-06-17 22:43:59 +03:00
parent dabd056e8b
commit 39e4e51866
70 changed files with 1807 additions and 99 deletions
+80 -3
View File
@@ -2,19 +2,96 @@ using UnityEngine;
public class Hammer : MonoBehaviour
{
private float _life = 3;
[SerializeField] private float _lifespan = 5f;
[SerializeField] private float _stunDuration = 1f;
[SerializeField] private float _impactNoiseRadius = 10f;
[SerializeField] private bool _emitNoiseOnImpact = true;
private float _lifeTimer;
private Vector2 _velocity;
private bool _facingRight;
private Rigidbody2D _rigidbody;
private bool _hasCollided = false;
private void Awake()
{
Destroy(gameObject, _life);
_rigidbody = GetComponent<Rigidbody2D>();
_lifeTimer = _lifespan;
}
public void Initialize(bool facingRight, float speed)
{
_facingRight = facingRight;
_velocity = new Vector2(facingRight ? speed : -speed, 0);
if (_rigidbody != null)
{
_rigidbody.linearVelocity = _velocity;
}
}
private void Update()
{
// Self-destruct after lifespan expires
_lifeTimer -= Time.deltaTime;
if (_lifeTimer <= 0)
{
Destroy(gameObject);
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (_hasCollided)
return;
_hasCollided = true;
// Check for enemy collision (stun)
var enemy = collision.gameObject.GetComponent<Character>();
if (enemy != null)
{
HandleEnemyCollision(enemy, collision.relativeVelocity);
EmitImpactNoise(collision.GetContact(0).point);
Destroy(gameObject);
return;
}
// Check for breakable wall collision
var mapElement = collision.collider.GetComponent<MapElement>();
if (mapElement != null)
if (mapElement != null && mapElement is BreakableWall)
{
mapElement.Hit();
EmitImpactNoise(collision.GetContact(0).point);
Destroy(gameObject);
return;
}
// Fallback: destroy on any collision
EmitImpactNoise(collision.GetContact(0).point);
Destroy(gameObject);
}
private void HandleEnemyCollision(Character enemy, Vector2 impactVelocity)
{
// Apply stun to enemy
var enemyAI = enemy as EnemyAI;
if (enemyAI != null)
{
enemyAI.OnHitByHammer(_stunDuration);
}
}
private void EmitImpactNoise(Vector2 position)
{
if (!_emitNoiseOnImpact)
return;
// Check if NoiseSystem exists and emit noise
var noiseSystem = NoiseSystem.Instance;
if (noiseSystem != null)
{
noiseSystem.Emit(position, _impactNoiseRadius);
}
}
}