diff --git a/Assets/Code/Gameplay.meta b/Assets/Code/Gameplay.meta new file mode 100644 index 0000000..bcef71e --- /dev/null +++ b/Assets/Code/Gameplay.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6d1cbbd4cb454d23a8d6c16c6ef12c7b +timeCreated: 1769791134 \ No newline at end of file diff --git a/Assets/Code/Gameplay/Player.meta b/Assets/Code/Gameplay/Player.meta new file mode 100644 index 0000000..3c7db03 --- /dev/null +++ b/Assets/Code/Gameplay/Player.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6158f3abaa124e198d646274f7cea710 +timeCreated: 1769791162 \ No newline at end of file diff --git a/Assets/Code/Gameplay/Player/PlayerMovement.cs b/Assets/Code/Gameplay/Player/PlayerMovement.cs new file mode 100644 index 0000000..81a9fb3 --- /dev/null +++ b/Assets/Code/Gameplay/Player/PlayerMovement.cs @@ -0,0 +1,90 @@ +using UnityEngine; +using Code.Input; + +namespace Code.Gameplay.Player +{ + public class PlayerMovement : MonoBehaviour + { + [Header("References")] + [SerializeField] private Rigidbody2D _rb; + [SerializeField] private Transform _groundCheck; + [SerializeField] private LayerMask _groundLayer; + + [Header("Movement")] + [SerializeField] private float _moveSpeed = 5f; + [SerializeField] private float _sprintSpeedMultiplier = 1.8f; + [SerializeField] private float _jumpForce = 12f; + + [Header("Ground Check")] + [SerializeField] private float _groundCheckRadius = 0.2f; + + private IInputService _input; + private bool _isGrounded; + private bool _jumpRequested; + + public bool IsGrounded => _isGrounded; + + public void Construct(IInputService input) + { + _input = input; + } + + private void Update() + { + HandleInput(); + CheckGround(); + } + + private void FixedUpdate() + { + Move(); + HandleJump(); + } + + private void HandleInput() + { + transform.rotation = _input.MoveInput switch + { + > 0 => Quaternion.identity, + < 0 => Quaternion.Euler(0, -180, 0), + _ => transform.rotation + }; + + if (_input.JumpPressed && !_jumpRequested) + { + _jumpRequested = true; + } + } + + private void CheckGround() + { + _isGrounded = Physics2D.OverlapCircle(_groundCheck.position, _groundCheckRadius, _groundLayer); + } + + private void Move() + { + float moveInput = _input.MoveInput; + float speed = _input.SprintHeld ? _moveSpeed * _sprintSpeedMultiplier : _moveSpeed; + float targetVelocityX = moveInput * speed; + + // Плавное изменение скорости (опционально, можно и напрямую) + _rb.linearVelocity = new Vector2(targetVelocityX, _rb.linearVelocity.y); + } + + private void HandleJump() + { + if (_jumpRequested && _isGrounded) + { + _rb.linearVelocity = new Vector2(_rb.linearVelocity.x, _jumpForce); + _jumpRequested = false; + } + } + + // Для отладки + private void OnDrawGizmosSelected() + { + if (_groundCheck != null) + Gizmos.DrawWireSphere(_groundCheck.position, _groundCheckRadius); + } + } +} \ No newline at end of file diff --git a/Assets/Code/Gameplay/Player/PlayerMovement.cs.meta b/Assets/Code/Gameplay/Player/PlayerMovement.cs.meta new file mode 100644 index 0000000..3464801 --- /dev/null +++ b/Assets/Code/Gameplay/Player/PlayerMovement.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0c9ba2abef40495ca9fdfbe42f74330d +timeCreated: 1769791173 \ No newline at end of file diff --git a/Assets/Code/Input/IInputService.cs b/Assets/Code/Input/IInputService.cs index d3df596..ba4b995 100644 --- a/Assets/Code/Input/IInputService.cs +++ b/Assets/Code/Input/IInputService.cs @@ -12,6 +12,9 @@ namespace Code.Input Vector2 MainMenuParalax { get; } float MoveInput { get; } + bool JumpPressed { get; } + bool SprintHeld { get; } + bool AttackPressed { get; } void DebugBindAction(int mapId, int actionId, Action action); diff --git a/Assets/Code/Input/InputService.cs b/Assets/Code/Input/InputService.cs index 1492ccb..04dbe8c 100644 --- a/Assets/Code/Input/InputService.cs +++ b/Assets/Code/Input/InputService.cs @@ -11,6 +11,9 @@ namespace Code.Input public Vector2 MainMenuParalax { get; private set; } public float MoveInput { get; private set; } + public bool JumpPressed { get; private set; } + public bool SprintHeld { get; private set; } + public bool AttackPressed { get; private set; } public InputService(InputActionAsset inputActionAsset) { @@ -28,6 +31,9 @@ namespace Code.Input { var map = _inputActionAsset.actionMaps[(int)ActionMapping.Gameplay]; BindAxis(map, "Move", v => MoveInput = v); + BindButton(map, "Jump", v => JumpPressed = v); + BindButton(map, "Sprint", v => SprintHeld = v); + BindButton(map, "Attack", v => AttackPressed = v); } private void SetupMainMenuInputCallbacks() diff --git a/Assets/Code/UI/GameplayController.cs b/Assets/Code/UI/GameplayController.cs index bf86e2c..4624f05 100644 --- a/Assets/Code/UI/GameplayController.cs +++ b/Assets/Code/UI/GameplayController.cs @@ -1,4 +1,5 @@ using Code.DI; +using Code.Gameplay.Player; using Code.Input; using UnityEngine; @@ -12,11 +13,8 @@ namespace Code.UI { _inputService = FindFirstObjectByType().Resolve(); _inputService.EnableMap(ActionMapping.Gameplay); - } - - public void Update() - { - Debug.Log(_inputService.MoveInput); + + FindFirstObjectByType().Construct(_inputService); } } } \ No newline at end of file diff --git a/Assets/Resources/Scenes/Gameplay.unity b/Assets/Resources/Scenes/Gameplay.unity index 890a187..d16104c 100644 --- a/Assets/Resources/Scenes/Gameplay.unity +++ b/Assets/Resources/Scenes/Gameplay.unity @@ -1174,6 +1174,144 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1211830912} m_CullTransparentMesh: 1 +--- !u!1 &1464259587 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1464259589} + - component: {fileID: 1464259588} + - component: {fileID: 1464259590} + m_Layer: 3 + m_Name: ground + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!212 &1464259588 +SpriteRenderer: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1464259587} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RayTracingAccelStructBuildFlagsOverride: 0 + m_RayTracingAccelStructBuildFlags: 1 + m_SmallMeshCulling: 1 + m_ForceMeshLod: -1 + m_MeshLodSelectionBias: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_GlobalIlluminationMeshLod: 0 + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_MaskInteraction: 0 + m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 1, y: 1} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_SpriteSortPoint: 0 +--- !u!4 &1464259589 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1464259587} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 10, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!61 &1464259590 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1464259587} + m_Enabled: 1 + serializedVersion: 3 + m_Density: 1 + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_ForceSendLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ForceReceiveLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ContactCaptureLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_CallbackLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_CompositeOperation: 0 + m_CompositeOrder: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 1, y: 1} + newSize: {x: 1, y: 1} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 1 + m_Size: {x: 1, y: 1} + m_EdgeRadius: 0 --- !u!1 &1596676852 GameObject: m_ObjectHideFlags: 0 @@ -1221,6 +1359,217 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1596676852} m_CullTransparentMesh: 1 +--- !u!1 &1616841230 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1616841232} + - component: {fileID: 1616841231} + - component: {fileID: 1616841235} + - component: {fileID: 1616841233} + - component: {fileID: 1616841234} + - component: {fileID: 1616841236} + m_Layer: 0 + m_Name: Player + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!212 &1616841231 +SpriteRenderer: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1616841230} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RayTracingAccelStructBuildFlagsOverride: 0 + m_RayTracingAccelStructBuildFlags: 1 + m_SmallMeshCulling: 1 + m_ForceMeshLod: -1 + m_MeshLodSelectionBias: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_GlobalIlluminationMeshLod: 0 + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_MaskInteraction: 0 + m_Sprite: {fileID: 21300000, guid: 901639f1dddd7b04aa3c943786d274d5, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 1, y: 1} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_SpriteSortPoint: 0 +--- !u!4 &1616841232 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1616841230} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 4, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!50 &1616841233 +Rigidbody2D: + serializedVersion: 5 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1616841230} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 100 + m_LinearDamping: 0 + m_AngularDamping: 0.05 + m_GravityScale: 5 + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_Interpolate: 0 + m_SleepingMode: 0 + m_CollisionDetection: 1 + m_Constraints: 4 +--- !u!114 &1616841234 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1616841230} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0c9ba2abef40495ca9fdfbe42f74330d, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::Code.Gameplay.Player.PlayerMovement + _rb: {fileID: 1616841233} + _groundCheck: {fileID: 1464259589} + _groundLayer: + serializedVersion: 2 + m_Bits: 8 + _moveSpeed: 5 + _sprintSpeedMultiplier: 1.8 + _jumpForce: 12 + _groundCheckRadius: 0.2 +--- !u!61 &1616841235 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1616841230} + m_Enabled: 1 + serializedVersion: 3 + m_Density: 1 + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_ForceSendLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ForceReceiveLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ContactCaptureLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_CallbackLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_CompositeOperation: 0 + m_CompositeOrder: 0 + m_Offset: {x: -0.045, y: -1} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 5.12, y: 5.12} + newSize: {x: 1, y: 1} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + m_Size: {x: 1.85, y: 2.7} + m_EdgeRadius: 0 +--- !u!95 &1616841236 +Animator: + serializedVersion: 7 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1616841230} + m_Enabled: 1 + m_Avatar: {fileID: 0} + m_Controller: {fileID: 9100000, guid: ba9e8b2f4d5d07f4e84e9f05710f122c, type: 2} + m_CullingMode: 0 + m_UpdateMode: 0 + m_ApplyRootMotion: 0 + m_LinearVelocityBlending: 0 + m_StabilizeFeet: 0 + m_AnimatePhysics: 0 + m_WarningMessage: + m_HasTransformHierarchy: 1 + m_AllowConstantClipSamplingOptimization: 1 + m_KeepAnimatorStateOnDisable: 0 + m_WriteDefaultValuesOnDisable: 0 --- !u!1 &1677702646 GameObject: m_ObjectHideFlags: 0 @@ -1426,3 +1775,5 @@ SceneRoots: - {fileID: 619394802} - {fileID: 1163535557} - {fileID: 553971734} + - {fileID: 1464259589} + - {fileID: 1616841232} diff --git a/Assets/Settings/InputSystem_Actions.inputactions b/Assets/Settings/InputSystem_Actions.inputactions index f7289a5..a434a38 100644 --- a/Assets/Settings/InputSystem_Actions.inputactions +++ b/Assets/Settings/InputSystem_Actions.inputactions @@ -35,7 +35,7 @@ "id": "0d58d58e-82df-47fc-8847-b7d4ed12b3c1", "actions": [ { - "name": "New action", + "name": "Jump", "type": "Button", "id": "2be1437b-be70-49bc-968a-4211a82398ad", "expectedControlType": "", @@ -51,17 +51,35 @@ "processors": "", "interactions": "", "initialStateCheck": true + }, + { + "name": "Attack", + "type": "Button", + "id": "9cf15cdb-4f45-4453-9d26-cd8a660855c6", + "expectedControlType": "", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, + { + "name": "Sprint", + "type": "Button", + "id": "9b34ee00-3c84-4dc2-8d87-c617ee745260", + "expectedControlType": "", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ { "name": "", "id": "eeb7e7e7-fdf7-4f44-9cec-45cfe0fbc414", - "path": "", + "path": "/space", "interactions": "", "processors": "", - "groups": "", - "action": "New action", + "groups": ";Keyboard&Mouse", + "action": "Jump", "isComposite": false, "isPartOfComposite": false }, @@ -82,7 +100,18 @@ "path": "/a", "interactions": "", "processors": "", - "groups": "", + "groups": ";Keyboard&Mouse", + "action": "Move", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "negative", + "id": "6fefa1fa-2250-4435-ad8d-e32a6bc63a1d", + "path": "/leftArrow", + "interactions": "", + "processors": "", + "groups": ";Keyboard&Mouse", "action": "Move", "isComposite": false, "isPartOfComposite": true @@ -93,10 +122,54 @@ "path": "/d", "interactions": "", "processors": "", - "groups": "", + "groups": ";Keyboard&Mouse", "action": "Move", "isComposite": false, "isPartOfComposite": true + }, + { + "name": "positive", + "id": "877a48a0-8255-444d-9e4a-934937238c2f", + "path": "/rightArrow", + "interactions": "", + "processors": "", + "groups": ";Keyboard&Mouse", + "action": "Move", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "", + "id": "75a6406d-8d53-4e3f-88c4-53e8eb898f5c", + "path": "/f", + "interactions": "", + "processors": "", + "groups": ";Keyboard&Mouse", + "action": "Attack", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "58b873f6-fb11-4214-8819-97d4f68f9d8b", + "path": "/leftButton", + "interactions": "", + "processors": "", + "groups": ";Keyboard&Mouse", + "action": "Attack", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "5edbe4a6-65bd-4daf-ab2b-c2ed63691367", + "path": "/shift", + "interactions": "", + "processors": "", + "groups": "", + "action": "Sprint", + "isComposite": false, + "isPartOfComposite": false } ] }, diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 1c92a78..c0ad5fa 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -2,13 +2,13 @@ %TAG !u! tag:unity3d.com,2011: --- !u!78 &1 TagManager: - serializedVersion: 2 + serializedVersion: 3 tags: [] layers: - Default - TransparentFX - Ignore Raycast - - + - Provides Contact - Water - UI - @@ -41,3 +41,5 @@ TagManager: - name: Default uniqueID: 0 locked: 0 + m_RenderingLayers: + - Default