Платформер враги, инфраструктура, герой
This commit is contained in:
1 parent
28125eb382
commit
93819c1dd3
61 files changed
+1463
-423
No files matched your search
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Code.Infrastructure.Audio;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Code.Infrastructure.Input;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
@@ -8,34 +10,48 @@ namespace Code.Example.Platformer.Entity
|
||||
{
|
||||
public class PlayerEntity : Entity
|
||||
{
|
||||
private static readonly int OnAttack = Animator.StringToHash("OnAttack");
|
||||
private IInputService _inputService;
|
||||
|
||||
[Inject]
|
||||
private void Construct(IInputService inputService)
|
||||
private void Construct(IInputService inputService, IAudioService audioService)
|
||||
{
|
||||
_audioService = audioService;
|
||||
|
||||
_inputService = inputService;
|
||||
_inputService.BindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Move,
|
||||
_inputService.BindActionPerformed((int)ActionMappings.Platformer, (int)PlatformerActions.Move,
|
||||
MovementPerformed);
|
||||
_inputService.BindActionCancelled((int)ActionMappings.Gameplay, (int)GameplayActions.Move,
|
||||
_inputService.BindActionCancelled((int)ActionMappings.Platformer, (int)PlatformerActions.Move,
|
||||
MovementCancelled);
|
||||
_inputService.BindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, JumpPerformed);
|
||||
_inputService.BindActionPerformed((int)ActionMappings.Platformer, (int)PlatformerActions.Jump, JumpPerformed);
|
||||
_inputService.BindActionPerformed((int)ActionMappings.Platformer, (int)PlatformerActions.Attack, AttackPerformed);
|
||||
_inputService.BindActionPerformed((int)ActionMappings.Platformer, (int)PlatformerActions.Sprint, SprintPerformed);
|
||||
_inputService.BindActionCancelled((int)ActionMappings.Platformer, (int)PlatformerActions.Sprint, SprintCancelled);
|
||||
|
||||
//cameraFactory.GetCinematicCamera(CameraMode.Platformer).Follow = transform; , CameraFactory cameraFactory
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_inputService.UnbindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Move,
|
||||
_inputService.UnbindActionPerformed((int)ActionMappings.Platformer, (int)PlatformerActions.Move,
|
||||
MovementPerformed);
|
||||
_inputService.UnbindActionCancelled((int)ActionMappings.Gameplay, (int)GameplayActions.Move,
|
||||
_inputService.UnbindActionCancelled((int)ActionMappings.Platformer, (int)PlatformerActions.Move,
|
||||
MovementCancelled);
|
||||
_inputService.UnbindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, JumpPerformed);
|
||||
_inputService.UnbindActionPerformed((int)ActionMappings.Platformer, (int)PlatformerActions.Jump, JumpPerformed);
|
||||
_inputService.UnbindActionPerformed((int)ActionMappings.Platformer, (int)PlatformerActions.Attack, AttackPerformed);
|
||||
_inputService.UnbindActionPerformed((int)ActionMappings.Platformer, (int)PlatformerActions.Sprint, SprintPerformed);
|
||||
_inputService.UnbindActionCancelled((int)ActionMappings.Platformer, (int)PlatformerActions.Sprint, SprintCancelled);
|
||||
}
|
||||
|
||||
private float _acceleration = 1f;
|
||||
|
||||
protected override void Move()
|
||||
{
|
||||
rigidbody2D.linearVelocityX = _moveDirection.x * 5f;
|
||||
rigidbody2D.linearVelocityX = _moveDirection.x * 2f * _acceleration;
|
||||
}
|
||||
|
||||
private Vector2 _moveDirection;
|
||||
private IAudioService _audioService;
|
||||
|
||||
private void MovementPerformed(InputAction.CallbackContext callbackContext) =>
|
||||
_moveDirection = callbackContext.ReadValue<Vector2>();
|
||||
@@ -46,7 +62,48 @@ namespace Code.Example.Platformer.Entity
|
||||
private void JumpPerformed(InputAction.CallbackContext callbackContext)
|
||||
{
|
||||
if (!onGround) return;
|
||||
rigidbody2D.AddForceY(100f);
|
||||
rigidbody2D.AddForceY(150f);
|
||||
|
||||
_acceleration = 1f;
|
||||
}
|
||||
|
||||
[SerializeField] private Vector2 attackOffset;
|
||||
|
||||
private void AttackPerformed(InputAction.CallbackContext callbackContext)
|
||||
{
|
||||
if (!onGround) return;
|
||||
//
|
||||
|
||||
//
|
||||
_audioService.PlayOneShot(AudioNames.UISounds, 1);
|
||||
animator.SetBool(OnAttack, true);
|
||||
}
|
||||
|
||||
public void CastAttack()
|
||||
{
|
||||
var damagedOnes =
|
||||
Physics2D.OverlapPointAll((Vector2)transform.position + attackOffset, LayerMasks.Masks[LayerMaskType.PlatformerEnemy]);
|
||||
|
||||
if (damagedOnes == null) return;
|
||||
|
||||
foreach (var damaged in damagedOnes)
|
||||
{
|
||||
damaged.gameObject.GetComponent<Entity>().GetDamage(1);
|
||||
_audioService.PlayOneShot(AudioNames.UISounds, 2);
|
||||
}
|
||||
}
|
||||
|
||||
private void SprintPerformed(InputAction.CallbackContext callbackContext)
|
||||
{
|
||||
if (!onGround) return;
|
||||
//
|
||||
_acceleration = 3f;
|
||||
}
|
||||
private void SprintCancelled(InputAction.CallbackContext callbackContext)
|
||||
{
|
||||
_acceleration = 1f;
|
||||
}
|
||||
|
||||
public void AttackEnd() => animator.SetBool(OnAttack, false);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user