Platformer example started

This commit is contained in:
ThomasCharester committed 2026-02-22 13:59:04 +03:00
1 parent efcfaae647
commit 9f026b76d6
325 files changed
+23540 -270

No files matched your search

@@ -0,0 +1,52 @@
using System;
using Code.Infrastructure.Input;
using Reflex.Attributes;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Code.Example.Platformer.Entity
{
public class PlayerEntity : Entity
{
private IInputService _inputService;
[Inject]
private void Construct(IInputService inputService)
{
_inputService = inputService;
_inputService.BindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Move,
MovementPerformed);
_inputService.BindActionCancelled((int)ActionMappings.Gameplay, (int)GameplayActions.Move,
MovementCancelled);
_inputService.BindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, JumpPerformed);
}
private void OnDestroy()
{
_inputService.UnbindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Move,
MovementPerformed);
_inputService.UnbindActionCancelled((int)ActionMappings.Gameplay, (int)GameplayActions.Move,
MovementCancelled);
_inputService.UnbindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, JumpPerformed);
}
protected override void Move()
{
rigidbody2D.linearVelocityX = _moveDirection.x * 5f;
}
private Vector2 _moveDirection;
private void MovementPerformed(InputAction.CallbackContext callbackContext) =>
_moveDirection = callbackContext.ReadValue<Vector2>();
private void MovementCancelled(InputAction.CallbackContext callbackContext) =>
_moveDirection = Vector2.zero;
private void JumpPerformed(InputAction.CallbackContext callbackContext)
{
if (!onGround) return;
rigidbody2D.AddForceY(100f);
}
}
}