private void UpdateDrugTimer(float time) { if (DrugTimer > 0) { DrugTimer -= time * moveSpeed; } else { DrugTimer = 0; if (CurrentActiveDrug != null) { CurrentActiveDrug.EndEffect(); CurrentActiveDrug = null; } } }
private void UseDrug() { if (Drug1 != DrugType.None) { if (CurrentActiveDrug != null) { CurrentActiveDrug.EndEffect(); } switch (Drug1) { case DrugType.WhiteEye: DrugLevel += 6; DrugTimer = 4; CurrentActiveDrug = new WhiteEyeEffect(); break; case DrugType.Thorn: DrugLevel += 10; DrugTimer = 6; CurrentActiveDrug = new ThornEffect(); break; case DrugType.Knight: DrugLevel += 18; DrugTimer = 10; CurrentActiveDrug = new KnightEffect(); break; default: break; } audioSource.PlayOneShot((AudioClip)Resources.Load("sfx/SFX_POWERUP")); CurrentActiveDrug.StartEffect(); Drug1 = Drug2; Drug2 = DrugType.None; } }
// Update is called once per frame void Update() { if (!dead) { var knight = false; if (moveTimer > 0) { moveTimer -= Time.deltaTime; } else { if (moveTimer < 0) { moveReminder = -moveTimer; } else { moveReminder = 0; } moveTimer = 0; if (oldPositionX != currentPositionX || oldPositionY != currentPositionY) { gameObject.transform.localPosition = new Vector3(currentPositionX, currentPositionY, -1); previousPositionX = oldPositionX; previousPositionY = oldPositionY; oldPositionX = currentPositionX; oldPositionY = currentPositionY; } //drug var drug = CheckDrug(currentPositionX, currentPositionY); if (drug != DrugType.None) { audioSource.PlayOneShot((AudioClip)Resources.Load("sfx/SFX_PICKUP")); if (Drug1 == DrugType.None) { Drug1 = drug; } else if (Drug2 == DrugType.None) { Drug2 = drug; } else { //on gache pas la drogue UseDrug(); Drug2 = drug; } level.GetComponent <Level>().RemoveDrug(currentPositionX, currentPositionY); } //kill var kill = CheckKill(currentPositionX, currentPositionY); if (kill) { soundManager.stopLoop("Walk"); audioSource.PlayOneShot((AudioClip)Resources.Load("sfx/SFX_ANXIETY")); dead = true; animator.Play("player-m-cry"); Global.tryNumber++; StartCoroutine(ReLoadLevelAfterDelay(3)); } //knight if (CurrentActiveDrug != null && CurrentActiveDrug.Type == DrugType.Knight && knightAttackTimer <= 0) { var skeleton = CheckSkeleton(currentPositionX, currentPositionY); if (skeleton != null) { SkeletonKill(skeleton); } knight = true; } //guard if (!knight) { var guard = CheckGuard(currentPositionX, currentPositionY); if (guard) { var guards = GameObject.FindGameObjectsWithTag("Guard"); foreach (GameObject obj in guards) { obj.transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>().enabled = true; } dead = true; soundManager.stopLoop("Walk"); StartCoroutine(ReLoadLevelAfterDelay(3)); animator.Play(direction + "Idle"); Global.tryNumber++; audioSource.PlayOneShot((AudioClip)Resources.Load("sfx/SFX_BUSTED")); } } //stairs var levelIncrement = CheckStairs(currentPositionX, currentPositionY); if (levelIncrement > 0) { Global.CurrentLevel += levelIncrement; SceneManager.LoadScene(Global.CurrentLevel); } } //move knightAttackTimer -= Time.deltaTime; if (moveTimer == 0) { var position = gameObject.transform.localPosition; var x = 0; var y = 0; bool move = false; if (Input.GetAxis("Horizontal") > 0) { x = 1; move = true; direction = "Right"; } else if (Input.GetAxis("Horizontal") < 0) { x = -1; move = true; direction = "Left"; } else if (Input.GetAxis("Vertical") > 0) { y = 1; move = true; direction = "Back"; } else if (Input.GetAxis("Vertical") < 0) { y = -1; move = true; direction = "Face"; } if (knightAttackTimer > 0) { move = false; } if (move) { var fall = CheckFall(oldPositionX + x, oldPositionY + y); if (fall && !knight) { animator.Play("player-m-fall"); dead = true; move = false; soundManager.stopLoop("Walk"); audioSource.PlayOneShot((AudioClip)Resources.Load("sfx/SFX_FALL")); Global.tryNumber++; StartCoroutine(ReLoadLevelAfterDelay(3)); } } var solid = CheckSolid(oldPositionX + x, oldPositionY + y); if (move && !solid) { soundManager.playLoop("Walk"); moveTimer = -moveReminder + (1 / moveSpeed); UpdateDrugLevel(moveReminder); UpdateDrugTimer(moveReminder); currentPositionX = oldPositionX + x; currentPositionY = oldPositionY + y; animator.Play(direction + "Walk"); } else { soundManager.stopLoop("Walk"); if (knightAttackTimer < 0) { if (!dead) { animator.Play(direction + "Idle"); } DrugLevel = Mathf.Round(DrugLevel); DrugTimer = Mathf.Round(DrugTimer); UpdateDrugLevel(0); UpdateDrugTimer(0); } } } if (moveTimer > 0) { gameObject.transform.localPosition = Vector3.Lerp(new Vector3(oldPositionX, oldPositionY, -1), new Vector3(currentPositionX, currentPositionY, -1), moveSpeed * ((1 / moveSpeed) - moveTimer)); var time = Time.deltaTime; if (moveTimer - Time.deltaTime < 0) { time = moveTimer; } UpdateDrugLevel(time); UpdateDrugTimer(time); } //actions if (Input.GetButtonDown("Fire2")) { var tmp = Drug2; Drug2 = Drug1; Drug1 = tmp; } if (Input.GetButtonDown("Fire1")) { UseDrug(); } } else { //CurrentActiveDrug.EndEffect(); } //drugs if (CurrentActiveDrug != null) { CurrentActiveDrug.UpdateEffect(); } if (Input.GetKeyDown(KeyCode.Escape)) { Destroy(GameObject.Find("MusicDrogue")); Global.CurrentLevel = 1; Global.tryNumber = 1; SceneManager.LoadScene(0); } }