diff --git a/Assets/Script/BadGuy.cs b/Assets/Script/Enemy Scripts/BadGuy.cs similarity index 100% rename from Assets/Script/BadGuy.cs rename to Assets/Script/Enemy Scripts/BadGuy.cs diff --git a/Assets/Script/CameraControl.cs b/Assets/Script/HUD Scripts/CameraControl.cs similarity index 100% rename from Assets/Script/CameraControl.cs rename to Assets/Script/HUD Scripts/CameraControl.cs diff --git a/Assets/Menu.cs b/Assets/Script/HUD Scripts/Menu.cs similarity index 100% rename from Assets/Menu.cs rename to Assets/Script/HUD Scripts/Menu.cs diff --git a/Assets/Script/Pickup Scripts/HealthPickup.cs b/Assets/Script/Pickup Scripts/HealthPickup.cs new file mode 100644 index 0000000..4edee22 --- /dev/null +++ b/Assets/Script/Pickup Scripts/HealthPickup.cs @@ -0,0 +1,9 @@ +using UnityEngine; +using UnityEngine.UI; +using System.Collections; + +public class HealthPickup : MonoBehaviour +{ + + +} \ No newline at end of file diff --git a/Assets/Script/BallShoot.cs b/Assets/Script/Player Scripts/BallShoot.cs similarity index 96% rename from Assets/Script/BallShoot.cs rename to Assets/Script/Player Scripts/BallShoot.cs index 5adac2d..d952cf6 100644 --- a/Assets/Script/BallShoot.cs +++ b/Assets/Script/Player Scripts/BallShoot.cs @@ -1,8 +1,8 @@ using UnityEngine; using System.Collections; -public class BallShoot : MonoBehaviour { - +public class BallShoot: MonoBehaviour { + public float speed; public float distanceShoot=15; public GameObject theParent; @@ -13,12 +13,12 @@ public class BallShoot : MonoBehaviour { transform.rotation = new Quaternion (theParent.transform.rotation.x, theParent.transform.rotation.y, -90.0f, theParent.transform.rotation.w); } else transform.rotation = new Quaternion (theParent.transform.rotation.x, theParent.transform.rotation.y,90.0f, theParent.transform.rotation.w); - + } // Update is called once per frame void Update () { - + } void FixedUpdate () { diff --git a/Assets/Script/Player Scripts/PlayerControl.cs b/Assets/Script/Player Scripts/PlayerControl.cs new file mode 100644 index 0000000..acca846 --- /dev/null +++ b/Assets/Script/Player Scripts/PlayerControl.cs @@ -0,0 +1,151 @@ +using UnityEngine; +using System.Collections; + +public class PlayerControl : MonoBehaviour +{ + [HideInInspector] + public bool facingRight = true; + [HideInInspector] + public bool jump = false; + [HideInInspector] + public bool fire = false; + [HideInInspector] + public bool power = false; + [HideInInspector] + public bool watch = false; + + + public float moveForce = 365f; + public float maxSpeed = 5f; + public float vie = 100; + public AudioClip[] jumpClips; + public float jumpForce = 1000f; + public BallShoot ballPrefab; + private Transform groundCheck; + private Transform gunCheck; + private bool grounded = false; + private Animator anim; + + private float canShoot = 0; + private float invulnerable = 0; + + void Awake() + { + groundCheck = transform.Find("groundCheck"); + gunCheck = transform.Find("gunCheck"); + anim = GetComponent(); + } + + + void Update() + { + grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground")); + if (Input.GetButtonDown("Jump") && grounded) + jump = true; + + if (Input.GetButtonDown("Fire1")) + fire = true; + else if (Input.GetButtonUp("Fire1")) + fire = false; + if (Input.GetButtonDown("Fire2")) + power = true; + else if (Input.GetButtonUp("Fire2")) + power = false; + if (Input.GetButtonDown("Fire3")) + watch = true; + else if (Input.GetButtonUp("Fire3")) + watch = false; + } + + + void FixedUpdate() + { + float h = Input.GetAxis("Horizontal"); + if (h != 0) + anim.SetBool("Run", true); + else + anim.SetBool("Run", false); + if (h * GetComponent().velocity.x < maxSpeed) + GetComponent().AddForce(Vector2.right * h * moveForce); + if (Mathf.Abs(GetComponent().velocity.x) > maxSpeed) + GetComponent().velocity = new Vector2(Mathf.Sign(GetComponent().velocity.x) * maxSpeed, GetComponent().velocity.y); + if (h > 0 && !facingRight) + Flip(); + else if (h < 0 && facingRight) + Flip(); + if (jump) + { + GetComponent().AddForce(new Vector2(0f, jumpForce)); + jump = false; + } + if (!grounded) + { + anim.SetBool("Jump", true); + } + else + anim.SetBool("Jump", false); + + if (watch) + { + anim.SetBool("Watch", true); + Time.timeScale = 0.0f; + vie = 100; + } + else + anim.SetBool("Watch", false); + if (power) + { + anim.SetBool("Power", true); + } + else + anim.SetBool("Power", false); + + if (fire) + { + anim.SetBool("Shoot", true); + if (canShoot <= 0) + { + Instantiate(ballPrefab, gunCheck.position, Quaternion.identity); + GameObject[] ball = GameObject.FindGameObjectsWithTag("ball"); + BallShoot ballR = ball[ball.Length - 1].GetComponent(); + ballR.theParent = this.gameObject; + canShoot = 0.3f; + } + } + else + anim.SetBool("Shoot", false); + + canShoot -= Time.deltaTime; + invulnerable -= Time.deltaTime; + } + public void getHurt(float lessLife) + { + if (invulnerable <= 0) + { + vie -= lessLife; + invulnerable = 0.5f; + if (vie <= 0) + Time.timeScale = 0.0f; + } + } + void OnTriggerEnter2D(Collider2D col) + { + if (col.tag == "mechant") + { + print("mechant"); + if (invulnerable <= 0) + { + jump = true; + getHurt(25); + } + } + } + void Flip() + { + facingRight = !facingRight; + + Vector3 theScale = transform.localScale; + theScale.x *= -1; + transform.localScale = theScale; + } +} \ No newline at end of file diff --git a/Assets/Script/PlayerControl.cs b/Assets/Script/Player Scripts/PlayerController.cs similarity index 98% rename from Assets/Script/PlayerControl.cs rename to Assets/Script/Player Scripts/PlayerController.cs index 1dc80b4..7e83aae 100644 --- a/Assets/Script/PlayerControl.cs +++ b/Assets/Script/Player Scripts/PlayerController.cs @@ -1,7 +1,7 @@ using UnityEngine; using System.Collections; -public class PlayerControl : MonoBehaviour +public class PlayerController : MonoBehaviour { [HideInInspector] public bool facingRight = true; diff --git a/Assets/Script/Player Scripts/PlayerHealth.cs b/Assets/Script/Player Scripts/PlayerHealth.cs new file mode 100644 index 0000000..7a57d61 --- /dev/null +++ b/Assets/Script/Player Scripts/PlayerHealth.cs @@ -0,0 +1,56 @@ +using UnityEngine; +using UnityEngine.UI; +using System.Collections; + +public class PlayerHealth : MonoBehaviour +{ + + public int startingHealth = 100; // The amount of health the player starts the game with. + public int currentHealth; // The current health the player has. + public int healthToRecoverOnPickup; + public Slider healthSlider; // Reference to the UI's health bar. + public AudioClip deathClip; // The audio clip to play when the player dies. + public float flashSpeed = 5f; // The speed the damageImage will fade at. + public Color flashColour = new Color(1f, 0f, 0f, 0.1f); // The colour the damageImage is set to, to flash. + + + Animator anim; // Reference to the Animator component. + AudioSource playerAudio; // Reference to the AudioSource component. + PlayerController playerController; // Reference to the player's movement. + //PlayerShoot playerShoot; // Reference to the PlayerShooting script. + bool isDead; // Whether the player is dead. + bool damaged; // True when the player gets damaged. + + + void Awake () + { + // Setting up the references. + anim = GetComponent (); + playerAudio = GetComponent (); + playerController = GetComponent (); + //playerShooting = GetComponentInChildren (); + + // Set the initial health of the player. + currentHealth = startingHealth; + } + + + void Update () + { + // Reset the damaged flag. + damaged = false; + } + + + void OnTriggerEnter(Collider other) + { + if (other.gameObject.CompareTag("HealthPickup")) + { + Debug.Log("Health Pickup"); + currentHealth = currentHealth + healthToRecoverOnPickup; + healthSlider.value = currentHealth; + Destroy(other); + } + } + +} diff --git a/Assets/Script/Player Scripts/PlayerShoot.cs b/Assets/Script/Player Scripts/PlayerShoot.cs new file mode 100644 index 0000000..b2f6bc9 --- /dev/null +++ b/Assets/Script/Player Scripts/PlayerShoot.cs @@ -0,0 +1,44 @@ +using UnityEngine; +using System.Collections; + +public class PlayerShoot: MonoBehaviour { + + public float speed; + public float distanceShoot=15; + public GameObject theParent; + // Use this for initialization + void Start () { + if (theParent.transform.localScale.x<=0) { + speed *= -1; + transform.rotation = new Quaternion (theParent.transform.rotation.x, theParent.transform.rotation.y, -90.0f, theParent.transform.rotation.w); + } else + transform.rotation = new Quaternion (theParent.transform.rotation.x, theParent.transform.rotation.y,90.0f, theParent.transform.rotation.w); + + } + + // Update is called once per frame + void Update () { + + } + void FixedUpdate () + { + transform.position = new Vector3 (transform.position.x + speed,transform.position.y,transform.position.z); + if (transform.position.x > theParent.transform.position.x + distanceShoot || transform.position.x < theParent.transform.position.x - distanceShoot) + DestroyObject(gameObject); + } + void OnTriggerEnter2D (Collider2D col) + { + if(col.tag == "mechant" && theParent.tag !="mechant") + { + print("Yeah"); + col.gameObject.GetComponent().getShot(); + Destroy (gameObject); + } + if(col.tag == "player" && theParent.tag !="player") + { + print("Yeah"); + col.gameObject.GetComponent().getHurt(25); + Destroy (gameObject); + } + } +}