using UnityEngine;
using CnControls;
using UnityEngine.UI;
using System.Collections;
public class Player : MonoBehaviour
{
//Float Values
public float maxSpeed = 50;
public float speed = 500f;
public float jumppower = 150f;
//Booleans Values
public bool grounded;
public static bool attack;
public static bool face;
public static bool snake = false;
public static bool superpower;
public static bool fireballspower;
// Player Healthbool Value
private bool Shield = false;
//References
private Rigidbody2D rb2d;
private Animator animations;
//GameObjects
public GameObject StartGame;
public GameObject PauseGame;
public GameObject GameOver;
public GameObject GameWin;
public GameObject DeadParticalss;
//Player Health
public GameObject ShieldCover;
public GameObject Blood25Partical;
public GameObject Blood50Partical;
public GameObject SuperpowersPartical;
public GameObject ShieldPartical;
public GameObject DeadPartical;
public GameObject FruitPartical;
public GameObject RocketPartical;
//audios
AudioSource audio;
public AudioClip JumpAudio;
public AudioClip FruitCollect;
public AudioClip HealthDownAudio;
public AudioClip GameOverAudio;
public AudioClip Pup;
public AudioClip WinAudio;
// next level lock
public int levellock;
//spring jump
public static float bounceForce = 230f;
public static bool springs, won;
void Awake ()
{
//PlayerPrefs.DeleteAll ();
Debug.Log (MyPoz.playerX + " " + MyPoz.playerY + " " + MyPoz.playerZ);
if (MyPoz.playerX != 0 && MyPoz.playerY != 0 && MyPoz.playerZ != 0 && MyPoz.respawn == true) {
transform.position = new Vector3 (MyPoz.playerX, MyPoz.playerY, MyPoz.playerZ);
MyPoz.respawn = false;
}
}
void Start ()
{
superpower = false;
won = false;
attack = false;
fireballspower = true;
Time.timeScale = 1;
rb2d = gameObject.GetComponent<Rigidbody2D> ();
animations = gameObject.GetComponent<Animator> ();
audio = GameObject.Find ("SoundSettings").GetComponent<AudioSource> ();
//OnetimeAnimation.SetActive (false);
GoogleManager.sendScreen = true;
GoogleManager.loadAd = true;
}
void LateUpdate ()
{
animations.SetBool ("Grounded", grounded);
animations.SetBool ("Attack", attack);
animations.SetFloat ("Speed", Mathf.Abs (rb2d.velocity.x));
if (CnInputManager.GetAxis ("Horizontal") < -0.2f) {
face = true;
transform.localScale = new Vector3 (-1, 1, 1);
}
if (CnInputManager.GetAxis ("Horizontal") > 0.2f) {
face = false;
transform.localScale = new Vector3 (1, 1, 1);
}
if (CnInputManager.GetButtonDown ("Jump")) {
if (grounded) {
rb2d.AddForce (Vector2.up * jumppower);
audio.PlayOneShot (JumpAudio, 0.5f);
}
}
}
void FixedUpdate ()
{
Vector3 easeVelocity = rb2d.velocity;
easeVelocity.y = rb2d.velocity.y;
easeVelocity.z = 0.0f;
easeVelocity.x *= 0.75f;
float h = CnInputManager.GetAxis ("Horizontal");
//fake friction
if (grounded) {
rb2d.velocity = easeVelocity;
}
//Moving the Player
rb2d.AddForce ((Vector2.right * speed) * h);
//Limiting the speed of the player
if (rb2d.velocity.x > maxSpeed) {
rb2d.velocity = new Vector2 (maxSpeed, rb2d.velocity.y);
}
if (rb2d.velocity.x < -maxSpeed) {
rb2d.velocity = new Vector2 (-maxSpeed, rb2d.velocity.y);
}
//Health is 0 than player dead
if (GameManager.Health < 1 || GameManager.Dietime < 0) {
//Player_Manager.SetActive(true);
GameManager.hasOver = true;
Instantiate (DeadPartical, transform.position, Quaternion.identity);
audio.PlayOneShot (GameOverAudio, 1f);
Destroy (gameObject);
}
if (PlayerAttack.stoprunning == true) {
maxSpeed = 0;
speed = 0;
} else {
maxSpeed = 2;
speed = 50;
}
}
void OnTriggerStay2D (Collider2D col)
{
if (col.gameObject.tag == "Spring") {
rb2d.AddForce (Vector2.up * bounceForce);
}
}
void OnTriggerExit2D (Collider2D col)
{
if (col.gameObject.tag == "Spring") {
rb2d.AddForce (Vector2.up * bounceForce);
}
}
void OnTriggerEnter2D (Collider2D col)
{
//For checkpoz
if (col.gameObject.tag == "checkPoz") {
MyPoz.playerX = gameObject.transform.position.x;
MyPoz.playerY = gameObject.transform.position.y;
MyPoz.playerZ = gameObject.transform.position.z;
}
//Spring jump
if (col.gameObject.tag == "Spring") {
rb2d.AddForce (Vector2.up * bounceForce);
}
//Snowball collider destroy
if (col.gameObject.tag == "Snowball") {
Destroy (col.gameObject);
}
//Game Win Time
if (col.gameObject.tag == "GameWin") {
if (!won) {
won = true;
audio.PlayOneShot (WinAudio, 0.8f);
RocketPartical.SetActive (true);
StartCoroutine (winMenu ());
// level lock
//if below 30
if (PlayerPrefs.GetInt ("myWorld") == 0) {
if (PlayerPrefs.GetInt ("levellock") < levellock) {
//ad display
if (PlayerPrefs.GetInt ("levellock") == 2) {
PlayerPrefs.SetInt ("myAds", 1);
}
PlayerPrefs.SetInt ("levellock", levellock);
PlayerPrefs.SetInt ("myLife", PlayerPrefs.GetInt ("myLife") + 1);
}
}
// if over 30 level
//else if(AudioSetting.myWorld == 1){
else if (PlayerPrefs.GetInt ("myWorld") == 1) {
if (PlayerPrefs.GetInt ("levellock2") < levellock) {
PlayerPrefs.SetInt ("levellock2", levellock);
PlayerPrefs.SetInt ("myLife", PlayerPrefs.GetInt ("myLife") + 1);
}
}
// if over 50 level
//else if(AudioSetting.myWorld == 1){
else if (PlayerPrefs.GetInt ("myWorld") == 2) {
if (PlayerPrefs.GetInt ("levellock3") < levellock) {
PlayerPrefs.SetInt ("levellock3", levellock);
PlayerPrefs.SetInt ("myLife", PlayerPrefs.GetInt ("myLife") + 1);
}
}
MyPoz.playerX = 0;
MyPoz.playerY = 0;
MyPoz.playerZ = 0;
MyPoz.respawn = false;
PlayerPrefs.SetInt ("OneTime", 1);
//StartCoroutine (saveItems ());
}
}
//For get One Time Animation
if (col.gameObject.tag == "OneTimeAnimation") {
//rb2d.isKinematic = false;
StartCoroutine (OneTA ());
Destroy (col.gameObject);
}
//Fruit OnTriggerEnter Function
if (superpower == false || fireballspower == true)
if (col.gameObject.tag == "Fruit") {
GameManager.FireTimer += 10;
Instantiate (FruitPartical, transform.position, Quaternion.identity);
Destroy (col.gameObject);
audio.PlayOneShot (FruitCollect, 0.7f);
}
if (superpower == true || fireballspower == false) {
if (col.gameObject.tag == "Fruit") {
Instantiate (FruitPartical, transform.position, Quaternion.identity);
Destroy (col.gameObject);
}
}
if (Shield == false) {
if (col.gameObject.tag == "Enemy") {
GameManager.Health -= 10;
snake = true;
//audio.PlayOneShot(HealthDownAudio,0.8f);
}
if (col.gameObject.tag == "Fireball") {
GameManager.Health -= 10;
audio.PlayOneShot (HealthDownAudio, 0.8f);
snake = true;
Destroy (col.gameObject);
//audio.PlayOneShot(HealthDownAudio,0.8f);
}
if (col.gameObject.tag == "Damage") {
GameManager.Health -= 5;
snake = true;
audio.PlayOneShot (HealthDownAudio, 0.8f);
Destroy (col.gameObject);
// audio.PlayOneShot(HealthDownAudio,0.8f);
}
if (col.gameObject.tag == "Boss") {
GameManager.Health -= 5;
audio.PlayOneShot (HealthDownAudio, 0.8f);
snake = true;
// audio.PlayOneShot(HealthDownAudio,0.8f);
}
}
//Shiel is off than processing this
if (Shield == true) {
if (col.gameObject.tag == "Enemy") {
}
if (col.gameObject.tag == "Fireball") {
Destroy (col.gameObject);
}
}
//If player touch water than he is dead.
if (col.gameObject.tag == "Water") {
GameManager.Health = -1;
//audio.PlayOneShot(GameOverAudio,1f);
//GameManager.hasOver = true;
//Player_Manager.SetActive(true);
//Instantiate(DeadPartical,new Vector3(transform.position.x,transform.position.y,transform.position.z-23),Quaternion.identity);
//Destroy (gameObject);
}
}
//save game
private IEnumerator saveItems ()
{
yield return new WaitForSeconds (1f);
}
void OnCollisionEnter2D (Collision2D coll)
{
//Shield get time
if (coll.gameObject.tag == "Shield") {
ShieldCover.SetActive (true);
Shield = true;
Instantiate (ShieldPartical, transform.position, Quaternion.identity);
StartCoroutine (Shields ());
audio.PlayOneShot (Pup, 0.8f);
Destroy (coll.gameObject);
}
if (Shield == true) {
if (coll.gameObject.tag == "Enemy" || coll.gameObject.tag == "Stone") {
}
}
if (Shield == false) {
if (coll.gameObject.tag == "Enemy" || coll.gameObject.tag == "Stone") {
GameManager.Health -= 10;
audio.PlayOneShot (HealthDownAudio, 0.8f);
snake = true;
}
}
//Half Health Power get
if (coll.gameObject.tag == "HalfHealth") {
GameManager.Health += 25;
Instantiate (Blood25Partical, transform.position, Quaternion.identity);
audio.PlayOneShot (Pup, 0.8f);
Destroy (coll.gameObject);
}
//Super power Get Time
if (coll.gameObject.tag == "SuperPower") {
superpower = true;
GameManager.SuperFireTimer = 100;
Instantiate (SuperpowersPartical, transform.position, Quaternion.identity);
audio.PlayOneShot (Pup, 0.8f);
Destroy (coll.gameObject);
}
//Half Power increase get time
if (coll.gameObject.tag == "HalfPower") {
GameManager.FireTimer += 50;
Instantiate (Blood50Partical, transform.position, Quaternion.identity);
audio.PlayOneShot (Pup, 0.8f);
Destroy (coll.gameObject);
}
}
IEnumerator Shields ()
{
yield return new WaitForSeconds (15);
ShieldCover.SetActive (false);
Shield = false;
bounceForce = 230;
}
IEnumerator OneTA ()
{
yield return new WaitForSeconds (5);
//rb2d.isKinematic = true;
}
IEnumerator winMenu ()
{
yield return new WaitForSeconds (3);
Time.timeScale = 0;
StartGame.SetActive (false);
GameOver.SetActive (false);
GameWin.SetActive (true);
PauseGame.SetActive (false);
if (Application.loadedLevelName == "Level_1" && PlayerPrefs.GetInt ("WizardUnlock") == 0) {
Time.timeScale = 1;
Application.LoadLevel ("W_Unlock");
}
if (Application.loadedLevelName == "Level_5" && PlayerPrefs.GetInt ("ArcherUnlock") == 0) {
Time.timeScale = 1;
Application.LoadLevel ("A_Unlock");
}
GoogleManager.showAds = true;
}
}
using CnControls;
using UnityEngine.UI;
using System.Collections;
public class Player : MonoBehaviour
{
//Float Values
public float maxSpeed = 50;
public float speed = 500f;
public float jumppower = 150f;
//Booleans Values
public bool grounded;
public static bool attack;
public static bool face;
public static bool snake = false;
public static bool superpower;
public static bool fireballspower;
// Player Healthbool Value
private bool Shield = false;
//References
private Rigidbody2D rb2d;
private Animator animations;
//GameObjects
public GameObject StartGame;
public GameObject PauseGame;
public GameObject GameOver;
public GameObject GameWin;
public GameObject DeadParticalss;
//Player Health
public GameObject ShieldCover;
public GameObject Blood25Partical;
public GameObject Blood50Partical;
public GameObject SuperpowersPartical;
public GameObject ShieldPartical;
public GameObject DeadPartical;
public GameObject FruitPartical;
public GameObject RocketPartical;
//audios
AudioSource audio;
public AudioClip JumpAudio;
public AudioClip FruitCollect;
public AudioClip HealthDownAudio;
public AudioClip GameOverAudio;
public AudioClip Pup;
public AudioClip WinAudio;
// next level lock
public int levellock;
//spring jump
public static float bounceForce = 230f;
public static bool springs, won;
void Awake ()
{
//PlayerPrefs.DeleteAll ();
Debug.Log (MyPoz.playerX + " " + MyPoz.playerY + " " + MyPoz.playerZ);
if (MyPoz.playerX != 0 && MyPoz.playerY != 0 && MyPoz.playerZ != 0 && MyPoz.respawn == true) {
transform.position = new Vector3 (MyPoz.playerX, MyPoz.playerY, MyPoz.playerZ);
MyPoz.respawn = false;
}
}
void Start ()
{
superpower = false;
won = false;
attack = false;
fireballspower = true;
Time.timeScale = 1;
rb2d = gameObject.GetComponent<Rigidbody2D> ();
animations = gameObject.GetComponent<Animator> ();
audio = GameObject.Find ("SoundSettings").GetComponent<AudioSource> ();
//OnetimeAnimation.SetActive (false);
GoogleManager.sendScreen = true;
GoogleManager.loadAd = true;
}
void LateUpdate ()
{
animations.SetBool ("Grounded", grounded);
animations.SetBool ("Attack", attack);
animations.SetFloat ("Speed", Mathf.Abs (rb2d.velocity.x));
if (CnInputManager.GetAxis ("Horizontal") < -0.2f) {
face = true;
transform.localScale = new Vector3 (-1, 1, 1);
}
if (CnInputManager.GetAxis ("Horizontal") > 0.2f) {
face = false;
transform.localScale = new Vector3 (1, 1, 1);
}
if (CnInputManager.GetButtonDown ("Jump")) {
if (grounded) {
rb2d.AddForce (Vector2.up * jumppower);
audio.PlayOneShot (JumpAudio, 0.5f);
}
}
}
void FixedUpdate ()
{
Vector3 easeVelocity = rb2d.velocity;
easeVelocity.y = rb2d.velocity.y;
easeVelocity.z = 0.0f;
easeVelocity.x *= 0.75f;
float h = CnInputManager.GetAxis ("Horizontal");
//fake friction
if (grounded) {
rb2d.velocity = easeVelocity;
}
//Moving the Player
rb2d.AddForce ((Vector2.right * speed) * h);
//Limiting the speed of the player
if (rb2d.velocity.x > maxSpeed) {
rb2d.velocity = new Vector2 (maxSpeed, rb2d.velocity.y);
}
if (rb2d.velocity.x < -maxSpeed) {
rb2d.velocity = new Vector2 (-maxSpeed, rb2d.velocity.y);
}
//Health is 0 than player dead
if (GameManager.Health < 1 || GameManager.Dietime < 0) {
//Player_Manager.SetActive(true);
GameManager.hasOver = true;
Instantiate (DeadPartical, transform.position, Quaternion.identity);
audio.PlayOneShot (GameOverAudio, 1f);
Destroy (gameObject);
}
if (PlayerAttack.stoprunning == true) {
maxSpeed = 0;
speed = 0;
} else {
maxSpeed = 2;
speed = 50;
}
}
void OnTriggerStay2D (Collider2D col)
{
if (col.gameObject.tag == "Spring") {
rb2d.AddForce (Vector2.up * bounceForce);
}
}
void OnTriggerExit2D (Collider2D col)
{
if (col.gameObject.tag == "Spring") {
rb2d.AddForce (Vector2.up * bounceForce);
}
}
void OnTriggerEnter2D (Collider2D col)
{
//For checkpoz
if (col.gameObject.tag == "checkPoz") {
MyPoz.playerX = gameObject.transform.position.x;
MyPoz.playerY = gameObject.transform.position.y;
MyPoz.playerZ = gameObject.transform.position.z;
}
//Spring jump
if (col.gameObject.tag == "Spring") {
rb2d.AddForce (Vector2.up * bounceForce);
}
//Snowball collider destroy
if (col.gameObject.tag == "Snowball") {
Destroy (col.gameObject);
}
//Game Win Time
if (col.gameObject.tag == "GameWin") {
if (!won) {
won = true;
audio.PlayOneShot (WinAudio, 0.8f);
RocketPartical.SetActive (true);
StartCoroutine (winMenu ());
// level lock
//if below 30
if (PlayerPrefs.GetInt ("myWorld") == 0) {
if (PlayerPrefs.GetInt ("levellock") < levellock) {
//ad display
if (PlayerPrefs.GetInt ("levellock") == 2) {
PlayerPrefs.SetInt ("myAds", 1);
}
PlayerPrefs.SetInt ("levellock", levellock);
PlayerPrefs.SetInt ("myLife", PlayerPrefs.GetInt ("myLife") + 1);
}
}
// if over 30 level
//else if(AudioSetting.myWorld == 1){
else if (PlayerPrefs.GetInt ("myWorld") == 1) {
if (PlayerPrefs.GetInt ("levellock2") < levellock) {
PlayerPrefs.SetInt ("levellock2", levellock);
PlayerPrefs.SetInt ("myLife", PlayerPrefs.GetInt ("myLife") + 1);
}
}
// if over 50 level
//else if(AudioSetting.myWorld == 1){
else if (PlayerPrefs.GetInt ("myWorld") == 2) {
if (PlayerPrefs.GetInt ("levellock3") < levellock) {
PlayerPrefs.SetInt ("levellock3", levellock);
PlayerPrefs.SetInt ("myLife", PlayerPrefs.GetInt ("myLife") + 1);
}
}
MyPoz.playerX = 0;
MyPoz.playerY = 0;
MyPoz.playerZ = 0;
MyPoz.respawn = false;
PlayerPrefs.SetInt ("OneTime", 1);
//StartCoroutine (saveItems ());
}
}
//For get One Time Animation
if (col.gameObject.tag == "OneTimeAnimation") {
//rb2d.isKinematic = false;
StartCoroutine (OneTA ());
Destroy (col.gameObject);
}
//Fruit OnTriggerEnter Function
if (superpower == false || fireballspower == true)
if (col.gameObject.tag == "Fruit") {
GameManager.FireTimer += 10;
Instantiate (FruitPartical, transform.position, Quaternion.identity);
Destroy (col.gameObject);
audio.PlayOneShot (FruitCollect, 0.7f);
}
if (superpower == true || fireballspower == false) {
if (col.gameObject.tag == "Fruit") {
Instantiate (FruitPartical, transform.position, Quaternion.identity);
Destroy (col.gameObject);
}
}
if (Shield == false) {
if (col.gameObject.tag == "Enemy") {
GameManager.Health -= 10;
snake = true;
//audio.PlayOneShot(HealthDownAudio,0.8f);
}
if (col.gameObject.tag == "Fireball") {
GameManager.Health -= 10;
audio.PlayOneShot (HealthDownAudio, 0.8f);
snake = true;
Destroy (col.gameObject);
//audio.PlayOneShot(HealthDownAudio,0.8f);
}
if (col.gameObject.tag == "Damage") {
GameManager.Health -= 5;
snake = true;
audio.PlayOneShot (HealthDownAudio, 0.8f);
Destroy (col.gameObject);
// audio.PlayOneShot(HealthDownAudio,0.8f);
}
if (col.gameObject.tag == "Boss") {
GameManager.Health -= 5;
audio.PlayOneShot (HealthDownAudio, 0.8f);
snake = true;
// audio.PlayOneShot(HealthDownAudio,0.8f);
}
}
//Shiel is off than processing this
if (Shield == true) {
if (col.gameObject.tag == "Enemy") {
}
if (col.gameObject.tag == "Fireball") {
Destroy (col.gameObject);
}
}
//If player touch water than he is dead.
if (col.gameObject.tag == "Water") {
GameManager.Health = -1;
//audio.PlayOneShot(GameOverAudio,1f);
//GameManager.hasOver = true;
//Player_Manager.SetActive(true);
//Instantiate(DeadPartical,new Vector3(transform.position.x,transform.position.y,transform.position.z-23),Quaternion.identity);
//Destroy (gameObject);
}
}
//save game
private IEnumerator saveItems ()
{
yield return new WaitForSeconds (1f);
}
void OnCollisionEnter2D (Collision2D coll)
{
//Shield get time
if (coll.gameObject.tag == "Shield") {
ShieldCover.SetActive (true);
Shield = true;
Instantiate (ShieldPartical, transform.position, Quaternion.identity);
StartCoroutine (Shields ());
audio.PlayOneShot (Pup, 0.8f);
Destroy (coll.gameObject);
}
if (Shield == true) {
if (coll.gameObject.tag == "Enemy" || coll.gameObject.tag == "Stone") {
}
}
if (Shield == false) {
if (coll.gameObject.tag == "Enemy" || coll.gameObject.tag == "Stone") {
GameManager.Health -= 10;
audio.PlayOneShot (HealthDownAudio, 0.8f);
snake = true;
}
}
//Half Health Power get
if (coll.gameObject.tag == "HalfHealth") {
GameManager.Health += 25;
Instantiate (Blood25Partical, transform.position, Quaternion.identity);
audio.PlayOneShot (Pup, 0.8f);
Destroy (coll.gameObject);
}
//Super power Get Time
if (coll.gameObject.tag == "SuperPower") {
superpower = true;
GameManager.SuperFireTimer = 100;
Instantiate (SuperpowersPartical, transform.position, Quaternion.identity);
audio.PlayOneShot (Pup, 0.8f);
Destroy (coll.gameObject);
}
//Half Power increase get time
if (coll.gameObject.tag == "HalfPower") {
GameManager.FireTimer += 50;
Instantiate (Blood50Partical, transform.position, Quaternion.identity);
audio.PlayOneShot (Pup, 0.8f);
Destroy (coll.gameObject);
}
}
IEnumerator Shields ()
{
yield return new WaitForSeconds (15);
ShieldCover.SetActive (false);
Shield = false;
bounceForce = 230;
}
IEnumerator OneTA ()
{
yield return new WaitForSeconds (5);
//rb2d.isKinematic = true;
}
IEnumerator winMenu ()
{
yield return new WaitForSeconds (3);
Time.timeScale = 0;
StartGame.SetActive (false);
GameOver.SetActive (false);
GameWin.SetActive (true);
PauseGame.SetActive (false);
if (Application.loadedLevelName == "Level_1" && PlayerPrefs.GetInt ("WizardUnlock") == 0) {
Time.timeScale = 1;
Application.LoadLevel ("W_Unlock");
}
if (Application.loadedLevelName == "Level_5" && PlayerPrefs.GetInt ("ArcherUnlock") == 0) {
Time.timeScale = 1;
Application.LoadLevel ("A_Unlock");
}
GoogleManager.showAds = true;
}
}
No comments:
Post a Comment