summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Player
diff options
context:
space:
mode:
authornirav <nirav@airmail.cc>2020-12-12 07:18:36 +0000
committernirav <nirav@airmail.cc>2020-12-12 07:18:36 +0000
commit115f77bda0246a00f6e17469685c67746bdbd29d (patch)
tree4bbea1e59109bb1d1fddc71736f89289bab03073 /Assets/Scripts/Player
download01-master.tar.gz
01-master.zip
Initial commitHEADmaster
Diffstat (limited to 'Assets/Scripts/Player')
-rwxr-xr-xAssets/Scripts/Player/Bullet.cs54
-rwxr-xr-xAssets/Scripts/Player/Bullet.cs.meta14
-rwxr-xr-xAssets/Scripts/Player/GroundCheckScript.cs25
-rwxr-xr-xAssets/Scripts/Player/GroundCheckScript.cs.meta12
-rwxr-xr-xAssets/Scripts/Player/PlayerHealthScript.cs66
-rwxr-xr-xAssets/Scripts/Player/PlayerHealthScript.cs.meta12
-rwxr-xr-xAssets/Scripts/Player/PlayerMovementScript.cs120
-rwxr-xr-xAssets/Scripts/Player/PlayerMovementScript.cs.meta12
-rwxr-xr-xAssets/Scripts/Player/PlayerShootingScript.cs33
-rwxr-xr-xAssets/Scripts/Player/PlayerShootingScript.cs.meta13
10 files changed, 361 insertions, 0 deletions
diff --git a/Assets/Scripts/Player/Bullet.cs b/Assets/Scripts/Player/Bullet.cs
new file mode 100755
index 0000000..e96c245
--- /dev/null
+++ b/Assets/Scripts/Player/Bullet.cs
@@ -0,0 +1,54 @@
+using UnityEngine;
+using System.Collections;
+
+public class Bullet : MonoBehaviour {
+
+ public float Speed = 10;
+ Vector2 Direction;
+
+ GameObject Player;
+
+ void Start ()
+ {
+ Player = GameObject.FindGameObjectWithTag("Player") as GameObject;
+ if (Player.GetComponent<PlayerMovementScript>().FacingRight)
+ Direction = Vector2.right;
+ else
+ Direction = Vector2.left;
+ }
+
+ void Update ()
+ {
+ GetComponent<Rigidbody2D>().velocity = Direction * Speed;
+
+ //Destroy after 2 seconds
+ Destroy(gameObject, 2f);
+ }
+
+ void OnTriggerEnter2D(Collider2D col)
+ {
+ if(col.tag == "Enemy")
+ {
+ col.gameObject.GetComponent<EnemyHealthScript>().TakeDamage(25);
+ Destroy(gameObject);
+ }
+
+ if (col.tag == "Enemy2")
+ {
+ col.gameObject.GetComponent<NewEnemyHealth>().TakeDamage(25);
+ Destroy(gameObject);
+ }
+
+ if (col.tag == "Boss1")
+ {
+ col.gameObject.GetComponentInParent<Boss1HealthScript>().TakeDamage(25);
+ Destroy(gameObject);
+ }
+
+ if (col.tag == "Enemy3")
+ {
+ col.gameObject.GetComponent<Enemy3HealthScript>().TakeDamage(25);
+ Destroy(gameObject);
+ }
+ }
+}
diff --git a/Assets/Scripts/Player/Bullet.cs.meta b/Assets/Scripts/Player/Bullet.cs.meta
new file mode 100755
index 0000000..1d15cc9
--- /dev/null
+++ b/Assets/Scripts/Player/Bullet.cs.meta
@@ -0,0 +1,14 @@
+fileFormatVersion: 2
+guid: 51982e4f66782f348b0f711b4a4d3cc8
+timeCreated: 1467296479
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences:
+ - Enemy: {fileID: 132632, guid: 887f4befebfaeac41bced6bcba983245, type: 2}
+ - Player: {instanceID: 0}
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Player/GroundCheckScript.cs b/Assets/Scripts/Player/GroundCheckScript.cs
new file mode 100755
index 0000000..4dbace7
--- /dev/null
+++ b/Assets/Scripts/Player/GroundCheckScript.cs
@@ -0,0 +1,25 @@
+using UnityEngine;
+using System.Collections;
+
+public class GroundCheckScript : MonoBehaviour {
+
+ public PlayerMovementScript player;
+
+ void OnTriggerEnter2D(Collider2D col)
+ {
+ if (col.tag == "Ground" || col.tag == "Platform")
+ player.grounded = true;
+ }
+
+ void OnTriggerStay2D(Collider2D col)
+ {
+ if (col.tag == "Ground" || col.tag == "Platform")
+ player.grounded = true;
+ }
+
+ void OnTriggerExit2D(Collider2D col)
+ {
+ if (col.tag == "Ground" || col.tag == "Platform")
+ player.grounded = false;
+ }
+}
diff --git a/Assets/Scripts/Player/GroundCheckScript.cs.meta b/Assets/Scripts/Player/GroundCheckScript.cs.meta
new file mode 100755
index 0000000..5ae354a
--- /dev/null
+++ b/Assets/Scripts/Player/GroundCheckScript.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: d87d752f992bcf042ae9ba927253d1ce
+timeCreated: 1466852149
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Player/PlayerHealthScript.cs b/Assets/Scripts/Player/PlayerHealthScript.cs
new file mode 100755
index 0000000..38e354a
--- /dev/null
+++ b/Assets/Scripts/Player/PlayerHealthScript.cs
@@ -0,0 +1,66 @@
+using UnityEngine;
+using System.Collections;
+using UnityEngine.UI;
+using UnityEngine.SceneManagement;
+
+public class PlayerHealthScript : MonoBehaviour {
+
+ public float Health;
+ public float MaxHealth = 100;
+ bool Damaged;
+
+ //HUD
+ GameObject HUD;
+ Text HealthText;
+ Text GameOverText;
+ Image DamageIndicator;
+
+ void Start ()
+ {
+ HUD = GameObject.FindGameObjectWithTag("HUD");
+ HealthText = HUD.transform.Find("HealthText").GetComponent<Text>();
+ GameOverText = HUD.transform.Find("GameOverText").GetComponent<Text>();
+ DamageIndicator = HUD.transform.Find("DamageIndicatorImage").GetComponent<Image>();
+ Health = 100;
+ HealthText.text = Health + "/100";
+ }
+
+
+ void Update ()
+ {
+ //Damage Animation
+ if (Damaged)
+ {
+ DamageIndicator.color = new Color(1, 0, 0, .1f);
+ }
+ else
+ {
+ DamageIndicator.color = Color.Lerp(DamageIndicator.color, Color.clear, 1f * Time.deltaTime);
+ }
+ Damaged = false;
+ }
+
+ public void TakeDamage(float damage)
+ {
+ Health -= damage;
+ if (Health <= 0) Health = 0;
+ HealthText.text = Health + "/100";
+
+ Damaged = true;
+
+ if (Health <= 0)
+ {
+ Health = 0;
+ gameObject.GetComponent<PlayerMovementScript>().enabled = false;
+ gameObject.GetComponentInChildren<PlayerShootingScript>().enabled = false;
+ StartCoroutine(Restart());
+ }
+ }
+
+ IEnumerator Restart()
+ {
+ GameOverText.text = "Game Over";
+ yield return new WaitForSeconds(3f);
+ SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().name);
+ }
+}
diff --git a/Assets/Scripts/Player/PlayerHealthScript.cs.meta b/Assets/Scripts/Player/PlayerHealthScript.cs.meta
new file mode 100755
index 0000000..133d4f3
--- /dev/null
+++ b/Assets/Scripts/Player/PlayerHealthScript.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: e542a83a152079041999a3050d683b6f
+timeCreated: 1468167547
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Player/PlayerMovementScript.cs b/Assets/Scripts/Player/PlayerMovementScript.cs
new file mode 100755
index 0000000..c28067c
--- /dev/null
+++ b/Assets/Scripts/Player/PlayerMovementScript.cs
@@ -0,0 +1,120 @@
+using UnityEngine;
+using System.Collections;
+
+public class PlayerMovementScript : MonoBehaviour {
+
+ Rigidbody2D rb2d;
+
+ //Movement
+ float MaxSpeed;
+ public float MaxNormalSpeed = 10f;
+ public float MaxSprintSpeed = 15f;
+ public float ForceFactor = 60f;
+ public bool FacingRight = true;
+
+ //Movement animation
+ GameObject PlayerTrail;
+
+ //Jump
+ public float jumpShortSpeed = 10f;
+ public float jumpSpeed = 30f;
+ bool jump = false;
+ bool jumpCancal = false;
+ public bool grounded = true;
+
+ void Start ()
+ {
+ rb2d = gameObject.GetComponent<Rigidbody2D>();
+ MaxSpeed = MaxNormalSpeed;
+ PlayerTrail = GameObject.FindGameObjectWithTag("PlayerTrail");
+ }
+
+ void Update ()
+ {
+ //Jump
+ if (Input.GetButtonDown("Jump") && grounded)
+ {
+ jump = true;
+ }
+ if (Input.GetButtonUp("Jump") && !grounded)
+ {
+ jumpCancal = true;
+ }
+ }
+
+ void FixedUpdate()
+ {
+ //Horizontal
+ rb2d.AddForce(Vector2.right * Input.GetAxis("Horizontal") * ForceFactor);
+
+ //Left-Right Movement
+ if (rb2d.velocity.x > 0.0001f)
+ {
+ transform.localScale = new Vector3(1, 1, 1);
+ FacingRight = true;
+ }
+ if (rb2d.velocity.x < -0.0001f)
+ {
+ transform.localScale = new Vector3(-1, 1, 1);
+ FacingRight = false;
+ }
+
+ //Max Speed
+ if (rb2d.velocity.x > MaxSpeed)
+ {
+ rb2d.velocity = new Vector2(MaxSpeed, rb2d.velocity.y);
+ }
+ else if (rb2d.velocity.x < -MaxSpeed)
+ {
+ rb2d.velocity = new Vector2(-MaxSpeed, rb2d.velocity.y);
+ }
+
+ //Sprint
+ if (Input.GetAxis("Sprint") == 1)
+ {
+ MaxSpeed = MaxSprintSpeed;
+ }
+ if (Input.GetAxis("Sprint") == 0)
+ {
+
+ if (rb2d.velocity.x > MaxNormalSpeed )
+ {
+ MaxSpeed = Mathf.Lerp(rb2d.velocity.x, MaxNormalSpeed, .1f);
+ }
+ else if (rb2d.velocity.x < -MaxNormalSpeed)
+ {
+ MaxSpeed = Mathf.Lerp(-rb2d.velocity.x, MaxNormalSpeed, .1f);
+ }
+ }
+
+ //Sprint animation
+ if (rb2d.velocity.x == MaxSprintSpeed || rb2d.velocity.x == -MaxSprintSpeed)
+ {
+ PlayerTrail.SetActive(true);
+ }
+ else if (rb2d.velocity.x < 10.1f && rb2d.velocity.x > -10.1f)
+ PlayerTrail.SetActive(false);
+
+
+ //Jump
+
+ if (jump)
+ {
+ rb2d.velocity = new Vector2(rb2d.velocity.x, jumpSpeed);
+ jump = false;
+ }
+ if (jumpCancal)
+ {
+
+ if (rb2d.velocity.y > jumpShortSpeed)
+ rb2d.velocity = new Vector2(rb2d.velocity.x, Mathf.Lerp(rb2d.velocity.y, jumpShortSpeed, .6f));
+ jumpCancal = false;
+ }
+ }
+
+ public void StopPlayer()
+ {
+ rb2d.velocity = new Vector2(0, 0);
+ PlayerTrail.SetActive(false);
+ }
+}
diff --git a/Assets/Scripts/Player/PlayerMovementScript.cs.meta b/Assets/Scripts/Player/PlayerMovementScript.cs.meta
new file mode 100755
index 0000000..fdaa596
--- /dev/null
+++ b/Assets/Scripts/Player/PlayerMovementScript.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: b22f59be8664ecb47a0e2ab5536d50a4
+timeCreated: 1468167320
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Player/PlayerShootingScript.cs b/Assets/Scripts/Player/PlayerShootingScript.cs
new file mode 100755
index 0000000..45c6aca
--- /dev/null
+++ b/Assets/Scripts/Player/PlayerShootingScript.cs
@@ -0,0 +1,33 @@
+using UnityEngine;
+using System.Collections;
+
+public class PlayerShootingScript : MonoBehaviour {
+
+ public bool canShoot;
+ public GameObject Bullet;
+ public float Firerate = 1f;
+ float fireCounter = 0;
+
+ // Use this for initialization
+ void Start () {
+
+ }
+
+ // Update is called once per frame
+ void Update ()
+ {
+ if (canShoot)
+ {
+ if (Input.GetAxis("Fire") == 1)
+ {
+ if (fireCounter > Firerate)
+ {
+ fireCounter = 0;
+ gameObject.GetComponent<AudioSource>().Play();
+ Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
+ }
+ }
+ fireCounter += Time.deltaTime;
+ }
+ }
+}
diff --git a/Assets/Scripts/Player/PlayerShootingScript.cs.meta b/Assets/Scripts/Player/PlayerShootingScript.cs.meta
new file mode 100755
index 0000000..66ecbfa
--- /dev/null
+++ b/Assets/Scripts/Player/PlayerShootingScript.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: e7a6e88305369d54b8295eec8c87001c
+timeCreated: 1468072543
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences:
+ - Bullet: {fileID: 187558, guid: fb9814a46f3507c4e9b08a5fc84f727f, type: 2}
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: