diff --git a/SimpleStory/Assets/Prefabs.meta b/SimpleStory/Assets/Prefabs.meta new file mode 100644 index 0000000..d415519 --- /dev/null +++ b/SimpleStory/Assets/Prefabs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 081fe3db83d7d5444b388995d5b94816 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SimpleStory/Assets/Prefabs/Bullet.prefab b/SimpleStory/Assets/Prefabs/Bullet.prefab new file mode 100644 index 0000000..6999a9c --- /dev/null +++ b/SimpleStory/Assets/Prefabs/Bullet.prefab @@ -0,0 +1,150 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &8846117881262828612 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4502105473314619106} + - component: {fileID: 4732168354431654582} + - component: {fileID: 4334604050393155427} + - component: {fileID: 8878215552580759865} + - component: {fileID: 1606121419832531571} + m_Layer: 0 + m_Name: Bullet + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4502105473314619106 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8846117881262828612} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 2.298, y: 3.252, z: 0} + m_LocalScale: {x: 0.196, y: 0.196, z: 0.196} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!212 &4732168354431654582 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8846117881262828612} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} + 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_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_Sprite: {fileID: -2413806693520163455, guid: 4adeaf2d2b1c7417e89f026626d8264f, 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_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!114 &4334604050393155427 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8846117881262828612} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9d77bc866132b8747afacc06e1a3ac52, type: 3} + m_Name: + m_EditorClassIdentifier: + _movementDirection: {x: 0, y: 0} + _enemyLayer: + serializedVersion: 2 + m_Bits: 128 +--- !u!50 &8878215552580759865 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8846117881262828612} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 0.1 + m_LinearDrag: 0 + m_AngularDrag: 0.05 + m_GravityScale: 0 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 0 +--- !u!61 &1606121419832531571 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8846117881262828612} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 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: 0 + serializedVersion: 2 + m_Size: {x: 1, y: 1} + m_EdgeRadius: 0 diff --git a/SimpleStory/Assets/Prefabs/Bullet.prefab.meta b/SimpleStory/Assets/Prefabs/Bullet.prefab.meta new file mode 100644 index 0000000..26a4c5d --- /dev/null +++ b/SimpleStory/Assets/Prefabs/Bullet.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 024b71c2d3d0d774d90792ae5c19e8ee +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SimpleStory/Assets/Prefabs/Weapon.prefab b/SimpleStory/Assets/Prefabs/Weapon.prefab new file mode 100644 index 0000000..05ee1ba --- /dev/null +++ b/SimpleStory/Assets/Prefabs/Weapon.prefab @@ -0,0 +1,46 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &5458620210228757012 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 8225046113528564438} + - component: {fileID: 9137503611948381808} + m_Layer: 0 + m_Name: Weapon + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &8225046113528564438 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5458620210228757012} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 1.2489539, y: 0.08193511, z: -0.13456821} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &9137503611948381808 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5458620210228757012} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8231e3fe688d5464ea6b0861f8587b50, type: 3} + m_Name: + m_EditorClassIdentifier: + _prefabBullet: {fileID: 8846117881262828612, guid: 024b71c2d3d0d774d90792ae5c19e8ee, type: 3} diff --git a/SimpleStory/Assets/Prefabs/Weapon.prefab.meta b/SimpleStory/Assets/Prefabs/Weapon.prefab.meta new file mode 100644 index 0000000..a0c9b1f --- /dev/null +++ b/SimpleStory/Assets/Prefabs/Weapon.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f53d1d40716f26841b47f02c8d367913 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SimpleStory/Assets/Scripts/Creatures/Creature.cs b/SimpleStory/Assets/Scripts/Creatures/Creature.cs index 4ded7c5..e31f85f 100644 --- a/SimpleStory/Assets/Scripts/Creatures/Creature.cs +++ b/SimpleStory/Assets/Scripts/Creatures/Creature.cs @@ -17,6 +17,9 @@ protected enum CreatureAction { idle, mooving, stopMooving, jumping }; [SerializeField] protected LayerMask _groundLayer; + [SerializeField] + protected Weapon _weapon; + protected const float _maxMovementSpeed = 10.0f; protected const float _minMovementSpeed = 0.0f; protected const float _movementForce = 40.0f; diff --git a/SimpleStory/Assets/Scripts/Creatures/Player.cs b/SimpleStory/Assets/Scripts/Creatures/Player.cs index a3d73dc..730f27a 100644 --- a/SimpleStory/Assets/Scripts/Creatures/Player.cs +++ b/SimpleStory/Assets/Scripts/Creatures/Player.cs @@ -41,6 +41,15 @@ private void Update() { _creatrureAction = CreatureAction.idle; } + + if (Input.GetKeyDown(KeyCode.RightArrow)) + { + _weapon.Shoot(transform.position, Vector2.right); + } + else if (Input.GetKeyDown(KeyCode.LeftArrow)) + { + _weapon.Shoot(transform.position, Vector2.left); + } } diff --git a/SimpleStory/Assets/Scripts/Weapons.meta b/SimpleStory/Assets/Scripts/Weapons.meta new file mode 100644 index 0000000..7eaedea --- /dev/null +++ b/SimpleStory/Assets/Scripts/Weapons.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2f4603c526392604c8121f0413cfe9c6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SimpleStory/Assets/Scripts/Weapons/Bullet.cs b/SimpleStory/Assets/Scripts/Weapons/Bullet.cs new file mode 100644 index 0000000..4a2546d --- /dev/null +++ b/SimpleStory/Assets/Scripts/Weapons/Bullet.cs @@ -0,0 +1,75 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Bullet : MonoBehaviour +{ + protected Rigidbody2D _rigidbody; + [SerializeField] + protected Vector2 _movementDirection; + public Vector2 MovementDirection + { + get + { + return _movementDirection; + } + set + { + _movementDirection = value; + } + } + + protected const float _maxMovementSpeed = 20.0f; + protected const float _minMovementSpeed = 00.0f; + protected const float _movementForce = 80.0f; + protected const float _defaultDamage = 10.0f; + protected const int _enemyLayerNumber = 7; + protected const double _defaultDestoryTime = 4.0f; + + protected double _damage; + + protected double _timeUntilDestory; + + private void Awake() + { + _movementDirection = Vector2.zero; + _damage = _defaultDamage; + _rigidbody = gameObject.GetComponent(); + + _timeUntilDestory = _defaultDestoryTime; + } + + private void Update() + { + _timeUntilDestory -= Time.deltaTime; + if (_timeUntilDestory <= 0.0f) + { + Destroy(this.gameObject); + } + } + + private void FixedUpdate() + { + Move(); + } + + protected void Move() + { + _rigidbody.AddForce(_movementDirection * _movementForce); + + if (Mathf.Abs(_rigidbody.velocity.x) > _maxMovementSpeed) + { + _rigidbody.velocity = new Vector2(Mathf.Sign(_rigidbody.velocity.x) * _maxMovementSpeed, _rigidbody.velocity.y); + } + } + + private void OnTriggerStay2D(Collider2D collision) + { + Debug.Log(collision.gameObject.layer); + if (collision.gameObject.layer == _enemyLayerNumber) + { + Debug.Log("Bullet entered col"); + Destroy(this.gameObject); + } + } +} diff --git a/SimpleStory/Assets/Scripts/Weapons/Bullet.cs.meta b/SimpleStory/Assets/Scripts/Weapons/Bullet.cs.meta new file mode 100644 index 0000000..7af7a5d --- /dev/null +++ b/SimpleStory/Assets/Scripts/Weapons/Bullet.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9d77bc866132b8747afacc06e1a3ac52 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SimpleStory/Assets/Scripts/Weapons/Weapon.cs b/SimpleStory/Assets/Scripts/Weapons/Weapon.cs new file mode 100644 index 0000000..7812e66 --- /dev/null +++ b/SimpleStory/Assets/Scripts/Weapons/Weapon.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Weapon : MonoBehaviour +{ + [SerializeField] + private GameObject _prefabBullet; + + public void Shoot(Vector2 initialPosition, Vector2 direction) + { + GameObject bullet = Instantiate(_prefabBullet, initialPosition, Quaternion.identity); + Bullet scr = bullet.GetComponent(); + scr.MovementDirection = direction; + } +} diff --git a/SimpleStory/Assets/Scripts/Weapons/Weapon.cs.meta b/SimpleStory/Assets/Scripts/Weapons/Weapon.cs.meta new file mode 100644 index 0000000..a8bc788 --- /dev/null +++ b/SimpleStory/Assets/Scripts/Weapons/Weapon.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8231e3fe688d5464ea6b0861f8587b50 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: