Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class Person : MonoBehaviour
- {
- public float speed = 5.0f;
- public int hp;
- public int maxHp = 100;
- public float mana;
- public float maxMana = 200;
- public int dmg = 10;
- public bool shield;
- public float attackRangeXPunch = 3;
- public float attackRangeYPunch = 3;
- public float attackRangeXStun = 3;
- public float attackRangeYStun= 3;
- private Animator anim;
- public Vector3 targetPosition;
- public Image hpBar;
- public Image manaBar;
- public int level = 1;
- public int bossSave;
- public bool isPaused;
- public bool isPausedSt;
- public Image heathIcon;
- public Sprite[] heathIconS;
- Vector3 movement;
- bool inverControls;
- public GameObject panelPause;
- public GameObject panelGameOver;
- public GameObject panelDecisão;
- public GameObject panelSkillTree;
- //public Transform attackPosDef;
- //times cogumelo
- private float TimeDecreaseHp;
- private float TimeDecreaseSpeed;
- private float TimeStun;
- private float TimeInverControl;
- private float TimeDmg;
- private float TimeDef;
- public LayerMask whatIsEnemies;
- public PlayerSkills skiltree;
- public int skillPoints;
- private static Person playerInstance;
- Rigidbody2D rigidbody;
- // Start is called before the first frame update
- private void Awake()
- {
- if (playerInstance == null)
- {
- playerInstance = this;
- }
- else
- {
- Destroy(gameObject);
- }
- }
- void Start()
- {
- anim = GetComponent<Animator>();
- speed = 5.0f;
- hp = maxHp;
- mana = maxMana;
- rigidbody = GetComponent<Rigidbody2D>();
- rigidbody.velocity = Vector3.zero;
- skiltree = new PlayerSkills();
- LoadPlayer();
- }
- // Update is called once per frame
- void Update()
- {
- hpBar.fillAmount = (float) hp / (float) maxHp;
- manaBar.fillAmount = mana / maxMana;
- if (hp > 85)
- {
- heathIcon.sprite = heathIconS[0];
- }
- else if(hp > 70)
- {
- heathIcon.sprite = heathIconS[1];
- }
- else if(hp > 55)
- {
- heathIcon.sprite = heathIconS[2];
- }
- else if(hp > 40)
- {
- heathIcon.sprite = heathIconS[3];
- }
- else if(hp > 25)
- {
- heathIcon.sprite = heathIconS[4];
- }
- else if(hp > 15)
- {
- heathIcon.sprite = heathIconS[5];
- }
- else if(hp > 10)
- {
- heathIcon.sprite = heathIconS[6];
- }
- if (FindObjectOfType<SkillThree>().CanUseFireball())
- {
- dmg = 20;
- }
- if (FindObjectOfType<SkillThree>().CanUseFireballNC())
- {
- dmg = 30;
- }
- if (FindObjectOfType<SkillThree>().CanUseFireballC())
- {
- dmg = 1;
- }
- if (isPaused == true)
- {
- Time.timeScale = 0;
- panelPause.SetActive(true);
- }
- if(Time.timeScale > 0)
- {
- Time.timeScale = 1;
- panelPause.SetActive(false);
- movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0f);
- targetPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
- //seta animação do personagem para lado em que ele esta olhando
- Vector3 deltaPosition = targetPosition - transform.position;
- anim.SetFloat("Magnitude", deltaPosition.magnitude);
- Vector3 targetDirection = deltaPosition.normalized;
- if (hp > 0)
- {
- anim.SetFloat("HorizontalIdle", targetDirection.x);
- anim.SetFloat("VerticalIdle", targetDirection.y);
- anim.SetFloat("Horizontal", targetDirection.x);
- anim.SetFloat("Vertical", targetDirection.y);
- anim.SetFloat("Speed", movement.magnitude);
- if (inverControls == false)
- {
- transform.position = transform.position + movement * speed * Time.deltaTime;
- }
- else
- {
- transform.position = transform.position + -movement * speed * Time.deltaTime;
- }
- }
- }
- if (Input.GetKeyDown(KeyCode.Escape) && isPausedSt == false)
- {
- PauseGame();
- }
- if (Input.GetKeyDown(KeyCode.K) && isPaused == false)
- {
- OpenSkillTree();
- }
- if (isPausedSt)
- {
- panelSkillTree.SetActive(true);
- Time.timeScale = 0;
- }
- else
- {
- panelSkillTree.SetActive(false);
- Time.timeScale = 1;
- }
- if (hp <= 0)
- {
- anim.SetBool("Death", true);
- panelGameOver.SetActive(true);
- }
- else if (hp >= maxHp)
- {
- hp = maxHp;
- }
- else
- {
- panelGameOver.SetActive(false);
- }
- if (mana < maxMana)
- {
- mana += Time.deltaTime * 1;
- }
- else if (mana >= maxMana)
- {
- mana = maxMana;
- }
- if (mana <= 0)
- {
- mana = 0;
- }
- if(speed > 5)
- {
- speed -= Time.deltaTime;
- }
- //DMG COGUMELOS
- if (TimeDecreaseHp > 0)
- {
- hp --;
- TimeDecreaseHp -= Time.deltaTime;
- }
- else if(TimeDecreaseHp < 0)
- {
- TimeDecreaseHp = 0;
- }
- if(TimeDef > 0)
- {
- shield = true;
- TimeDef -= Time.deltaTime;
- }
- else
- {
- shield = false;
- TimeDef = 0;
- }
- if (TimeStun > 0)
- {
- speed = 0;
- TimeStun -= Time.deltaTime;
- }
- else if (TimeStun < 0)
- {
- TimeStun = 0;
- }
- else if (TimeDecreaseSpeed > 0)
- {
- speed = 2;
- TimeDecreaseSpeed -= Time.deltaTime;
- }
- else if (TimeDecreaseSpeed < 0)
- {
- TimeDecreaseSpeed = 0;
- }
- else
- {
- speed = 5.0f;
- }
- if (TimeInverControl > 0)
- {
- inverControls = true;
- TimeInverControl -= Time.deltaTime;
- }
- else if (TimeInverControl < 0)
- {
- TimeInverControl = 0;
- }
- else
- {
- inverControls = false;
- }
- if(TimeDmg > 0)
- {
- TimeDmg -= Time.deltaTime;
- }
- else
- {
- GetComponent<SpriteRenderer>().color = Color.white;
- }
- if(FindObjectOfType<CutscenePass>().isPaused == true)
- {
- Time.timeScale = 0;
- }
- else
- {
- Time.timeScale = 1;
- }
- }
- public void TakeHeal(int amount) {
- hp += amount;
- }
- public void DecreaseHp()
- {
- TimeDecreaseHp = 0.4f;
- GetComponent<SpriteRenderer>().color = Color.red;
- TimeDmg = 0.4f;
- }
- public void Stun()
- {
- TimeStun = 2.0f;
- GetComponent<SpriteRenderer>().color = Color.magenta;
- TimeDmg = 2.0f;
- }
- public void DecraseSpeed()
- {
- GetComponent<SpriteRenderer>().color = Color.yellow;
- TimeDmg = 3.0f;
- TimeDecreaseSpeed = 3.0f;
- }
- public void InvertControls()
- {
- GetComponent<SpriteRenderer>().color = Color.blue;
- TimeInverControl = 3.0f;
- TimeDmg = 3.0f;
- }
- public void ActiveShield()
- {
- TimeDef = 0.3f;
- }
- public void PauseGame()
- {
- isPaused = !isPaused;
- }
- public void OpenSkillTree()
- {
- isPausedSt = !isPausedSt;
- }
- public void TakeDamage(int amount)
- {
- if (shield)
- {
- shield = false;
- }
- else
- {
- hp -= amount;
- }
- GetComponent<SpriteRenderer>().color = Color.red;
- TimeDmg = 1.0f;
- }
- public void SavePlayer()
- {
- SaveSystem.SavePlayer(this);
- CaptureState();
- }
- public void LoadPlayer()
- {
- PlayerData data = SaveSystem.LoadPlayer();
- level = data.level;
- hp = data.health;
- maxHp = data.Maxhealth;
- maxMana = data.MaxMana;
- mana = data.Mana;
- bossSave = data.SaveBoss;
- dmg = data.Dmg;
- RestoreState(skiltree);
- }
- public object CaptureState()
- {
- return skiltree.CaptureState();
- }
- public void RestoreState(object state)
- {
- skiltree.RestoreState(state);
- }
- public void Load()
- {
- LoadPlayer();
- switch (level)
- {
- case 1:
- SceneManager.LoadScene("Level1");
- break;
- case 2:
- SceneManager.LoadScene("Level2");
- break;
- }
- }
- public void NewGame()
- {
- SceneManager.LoadScene("Level1");
- level = 1;
- hp = 100;
- maxHp = 100;
- maxMana = 200;
- mana = 200;
- bossSave = 0;
- dmg = 10;
- SavePlayer();
- }
- public void HelpFade()
- {
- hp += 50;
- mana += 50;
- if (FindObjectOfType<SkillThree>().CanUsePleh())
- {
- hp += 70;
- mana += 70;
- }
- if (FindObjectOfType<SkillThree>().CanUsePlehUp())
- {
- hp += 90;
- mana += 90;
- }
- }
- public void TrocaCena()
- {
- SavePlayer();
- SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
- }
- private void OnTriggerEnter2D(Collider2D collision)
- {
- if (collision.gameObject.tag == "Final")
- {
- level += 1;
- TrocaCena();
- }
- if(collision.gameObject.tag == "DecisionBoss")
- {
- panelDecisão.SetActive(true);
- }
- if(collision.gameObject.tag == "Boss3")
- {
- if (!shield)
- {
- hp = 0;
- }
- else
- {
- FindObjectOfType<BossRun>().DazedTime();
- }
- }
- }
- private void OnTriggerExit2D(Collider2D collision)
- {
- if (collision.gameObject.tag == "DecisionBoss")
- {
- panelDecisão.SetActive(false);
- }
- }
- }
Add Comment
Please, Sign In to add comment