Skip to content

Commit

Permalink
Created Weapon and Bullet class, not finished tho| WIP| #15
Browse files Browse the repository at this point in the history
  • Loading branch information
UselessSaint committed May 3, 2021
1 parent bf36d35 commit 0cbfb99
Show file tree
Hide file tree
Showing 12 changed files with 351 additions and 0 deletions.
8 changes: 8 additions & 0 deletions SimpleStory/Assets/Prefabs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

150 changes: 150 additions & 0 deletions SimpleStory/Assets/Prefabs/Bullet.prefab
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions SimpleStory/Assets/Prefabs/Bullet.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions SimpleStory/Assets/Prefabs/Weapon.prefab
Original file line number Diff line number Diff line change
@@ -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}
7 changes: 7 additions & 0 deletions SimpleStory/Assets/Prefabs/Weapon.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions SimpleStory/Assets/Scripts/Creatures/Creature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions SimpleStory/Assets/Scripts/Creatures/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}


Expand Down
8 changes: 8 additions & 0 deletions SimpleStory/Assets/Scripts/Weapons.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions SimpleStory/Assets/Scripts/Weapons/Bullet.cs
Original file line number Diff line number Diff line change
@@ -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<Rigidbody2D>();

_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);
}
}
}
11 changes: 11 additions & 0 deletions SimpleStory/Assets/Scripts/Weapons/Bullet.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions SimpleStory/Assets/Scripts/Weapons/Weapon.cs
Original file line number Diff line number Diff line change
@@ -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<Bullet>();
scr.MovementDirection = direction;
}
}
11 changes: 11 additions & 0 deletions SimpleStory/Assets/Scripts/Weapons/Weapon.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0cbfb99

Please sign in to comment.