// Update is called once per frame void Update() { spawnTimer -= Time.deltaTime; if (spawnTimer < 0) { if (sundial.isDayTime()) { Vector3 spawnPosition = new Vector3(Random.Range(-spawnScreenWidth, spawnScreenWidth), Random.Range(-spawnScreenHeight, spawnScreenHeight), 0); Carrot clone; clone = Instantiate(carrot, spawnPosition, Quaternion.identity) as Carrot; clone.sundial = sundial; } spawnTimer = Random.Range(avgSpawnTime * 0.5f, avgSpawnTime * 1.5f); } }
void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Enemy") { if (sundial.isDayTime()) { SF_bunnyDie.Play(); } else { SF_eatHunter.Play(); } if (!gameController.IsReviving()) { if (sundial.isDayTime()) { // kill the player gameObject.SetActive(false); gameController.GameOverDisplay(); } else { // eat the enemy Destroy(other.gameObject); // gain point and update hunger gameController.hunters++; if (playerController.hunger < 70) { playerController.hunger += 30; } else { playerController.hunger = 100; } } } else { StartCoroutine(gameController.Wait()); gameController.Reviving(false); } } else if (other.tag == "Carrot") { SF_eatCarrot.Play(); // eat the carrot Destroy(other.gameObject); // gain point and update hunger gameController.carrots++; if (playerController.hunger < 70) { playerController.hunger += 30; } else { playerController.hunger = 100; } } else if (other.tag == "Spear") { SF_bunnyDie.Play(); if (SF_bunnyHop.isPlaying) { SF_bunnyHop.Stop(); } if (SF_mutatedHop.isPlaying) { SF_mutatedHop.Stop(); } if (!gameController.IsReviving()) { if (sundial.isDayTime()) { // kill the player gameObject.SetActive(false); gameController.GameOverDisplay(); } else { // Destory spear Destroy(other.gameObject); } } else { StartCoroutine(gameController.Wait()); gameController.Reviving(false); } } }
// Update is called once per frame void Update() { if (sundial.getDayCount() > dayCount) { dayCount = sundial.getDayCount(); runSpeed = (maxRunSpeed * levelStartRatio) + ((maxRunSpeed * (1 - levelStartRatio)) / levelScaleToDays) * sundial.getDayCount(); if (runSpeed > maxRunSpeed) { runSpeed = maxRunSpeed; } walkSpeed = (maxWalkSpeed * levelStartRatio) + ((maxWalkSpeed * (1 - levelStartRatio)) / levelScaleToDays) * sundial.getDayCount(); if (walkSpeed > maxWalkSpeed) { walkSpeed = maxWalkSpeed; } } attackTimer += Time.deltaTime; screamTimer += Time.deltaTime; if (!attacking) { alertBox.SetActive(false); ahhhBox.SetActive(false); if (player.activeSelf && Vector3.Distance(player.transform.position, transform.position) < detectionRadius) { alertBox.SetActive(true); ahhhBox.SetActive(false); if (attackTimer >= attackDelay && sundial.isDayTime()) { if ((screamTimer >= screamDelay) && (!SF_hunterChase.isPlaying)) { SF_hunterChase.Play(); screamTimer = 0; } attackTimer = 0.0f; attacking = true; anim.SetBool(attackingHash, attacking); return; } else { if ((screamTimer >= screamDelay) && (!sundial.isDayTime())) { SF_hunterRunaway.Play(); screamTimer = 0; } chaseTimer = maxChaseTime; } } if (player.activeSelf && chaseTimer > 0.0f) { chaseTimer -= Time.deltaTime; if (sundial.isDayTime()) { alertBox.SetActive(true); ahhhBox.SetActive(false); goal = player.transform.position; } else { // get the point on the opposite side of this enemy from the player // TODO: Limit running to within the screen boundary? alertBox.SetActive(false); ahhhBox.SetActive(true); goal = 0.75f * (transform.position - player.transform.position) + transform.position; } currentSpeed = runSpeed; } else if (idleTimer > 0.0f) { alertBox.SetActive(false); ahhhBox.SetActive(false); idleTimer -= Time.deltaTime; if (idleTimer <= 0.0f) { // find a new goal to wander to // find a random point within wander range (higher chance to move toward center of map the further out this is) //float wanderDistance = Random.Range(minWanderRange, maxWanderRange); goal.x = Random.Range(-screenWidth, screenWidth); goal.y = Random.Range(-screenHeight, screenHeight); goal.z = 0; /* * float chanceWest = 0.5f; * float chanceSouth = 0.5f; * * Vector3 temp = transform.position; * if(temp.x > screenWidth * 0.5f) * { * chanceWest = temp.x / screenWidth; * } * else if(temp.x < -screenWidth * 0.5f) * { * chanceWest = 1.0f - (-temp.x / screenWidth); * } * * if(temp.y > screenHeight * 0.5f) * { * chanceSouth = temp.x / screenHeight; * } * else if(temp.x < -screenHeight * 0.5f) * { * chanceSouth = 1.0f - (-temp.x / screenHeight); * } * * int rollX = Random.Range(0, 100); * int rollY = Random.Range(0, 100); * * Vector3 dir = new Vector3(); * * if(rollX < chanceWest * 100.0f) * { * dir.x = -1.0f; * } * else * { * dir.x = 1.0f; * } * if(rollY < chanceSouth * 100.0f) * { * dir.y = -1.0f; * } * else * { * dir.y = 1.0f; * } * * dir.x *= Random.value; * dir.y *= Random.value; * * dir.Normalize(); * * goal = transform.position + dir * wanderDistance; * * if(goal.x > screenWidth) * { * goal.x = screenWidth; * } * else if(goal.x < -screenWidth) * { * goal.x = -screenWidth; * } * * if(goal.y > screenHeight) * { * goal.y = screenHeight; * } * else if(goal.y < -screenHeight) * { * goal.y = -screenHeight; * } */ } currentSpeed = 0.0f; } else // must be walking { currentSpeed = walkSpeed; } if (currentSpeed > 0) { // move the unit according to the goal and speed Vector3 moveDirection = goal - transform.position; if (moveDirection.magnitude < 0.1) { // we've reached our goal idleTimer = Random.Range(minIdleTime, maxIdleTime); } else { moveDirection.Normalize(); transform.position += moveDirection * currentSpeed * Time.deltaTime; } Vector3 scale = new Vector3(Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z); if (moveDirection.x < 0) { scale.x *= -1; } transform.localScale = scale; } anim.SetFloat(speedHash, currentSpeed); } else { if (attackTimer >= attackAnimationLength) { SF_throwSpear.Play(); Quaternion rotation = Quaternion.FromToRotation(new Vector3(1, 0, 0), (player.transform.position - transform.position)); Spear instance; Vector3 startPos = new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z); instance = Instantiate(spearPrefab, startPos, rotation) as Spear; instance.player = player; instance.gameController = gameController; attacking = false; anim.SetBool(attackingHash, attacking); } } alertBox.transform.rotation = Quaternion.Euler(alertBox.transform.rotation.eulerAngles.x, 0, 0); ahhhBox.transform.rotation = Quaternion.Euler(ahhhBox.transform.rotation.eulerAngles.x, 0, 0); }
// Update is called once per physics time unit void FixedUpdate() { //update day count txtDayCount.text = "Day " + sundial.day.ToString(); if (player.activeSelf) { if (dayTime != sundial.isDayTime()) // if daytime has changed, update display msg { dayTime = sundial.isDayTime(); fade = true; displayMsg = true; if (dayTime) { txtDayMsg.text = "Day " + sundial.day + "\n" + "Run!"; } else { txtDayMsg.text = "Night " + sundial.day + "\n" + "Hunt!"; } } if (fade) { Fade(); } } if (preCarrots != carrots) { preCarrots = carrots; carrotsCount.text = carrots.ToString(); if (googlePlayScript != null) { if (googlePlayScript.ReturnSignInStatus() == true) { googlePlayScript.CarrotsAchievement(carrots); } } } if (preHunters != hunters) { preHunters = hunters; huntersCount.text = hunters.ToString(); if (googlePlayScript != null) { if (googlePlayScript.ReturnSignInStatus() == true) { googlePlayScript.HunterAchievement(hunters); } } } if (preDay != sundial.day) { preDay = sundial.day; if (googlePlayScript != null) { if (googlePlayScript.ReturnSignInStatus() == true) { googlePlayScript.DaysAchievement(sundial.day); } } } }
// Update is called once per frame void Update() { if (Time.timeScale > 0) { Vector3 currentPosition = transform.position; if (Input.GetButtonDown("Fire1")) { clickDelay = 0; } else if (Input.GetButtonUp("Fire1")) { jumping = (clickDelay < 0.5f); } if (jumping) { if (sundial.isDayTime()) { if (SF_mutatedHop.isPlaying) { SF_mutatedHop.Stop(); } if (!SF_hop.isPlaying) { SF_hop.Play(); } } else { if (SF_hop.isPlaying) { SF_hop.Stop(); } if (!SF_mutatedHop.isPlaying) { SF_mutatedHop.Play(); } } jumpTimer += Time.deltaTime; if ((moveDirection.x == 0) && (moveDirection.y == 0)) { transform.position += prevMoveDirection * jumpSpeed * Time.deltaTime; } else { anim.SetFloat(speedHash, jumpSpeed); prevMoveDirection = moveDirection; transform.position += moveDirection * jumpSpeed * Time.deltaTime; } float screenWidth, screenHeight; screenHeight = Camera.main.orthographicSize; screenWidth = Camera.main.aspect * screenHeight; Vector3 pos = transform.position; if (pos.x > screenWidth) { pos.x = screenWidth; } else if (pos.x < -screenWidth) { pos.x = -screenWidth; } if (pos.y > screenHeight) { pos.y = screenHeight; } else if (pos.y < -screenHeight) { pos.y = -screenHeight; } transform.position = pos; if (jumpTimer >= jumpDuration) { moveDirection.x = 0; moveDirection.y = 0; moveDirection.z = 0; jumping = false; jumpTimer = 0; } } else { if (Input.GetButton("Fire1")) { clickDelay += Time.deltaTime; targetPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); float screenWidth, screenHeight; screenHeight = Camera.main.orthographicSize; screenWidth = Camera.main.aspect * screenHeight; if (targetPosition.x > screenWidth) { targetPosition.x = screenWidth; } else if (targetPosition.x < -screenWidth) { targetPosition.x = -screenWidth; } if (targetPosition.y > screenHeight) { targetPosition.y = screenHeight; } else if (targetPosition.y < -screenHeight) { targetPosition.y = -screenHeight; } targetPosition.z = 0; if (Vector3.Distance(targetPosition, transform.position) >= 0.1) { moveDirection = targetPosition - currentPosition; moveDirection.z = 0; moveDirection.Normalize(); } } else { moveDirection.x = 0; moveDirection.y = 0; moveDirection.z = 0; jumping = false; } if (moveDirection.magnitude != 0) { Vector3 scale = new Vector3(Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z); if (moveDirection.x < 0) { scale.x *= -1; } transform.localScale = scale; anim.SetFloat(speedHash, moveSpeed); transform.position += moveDirection * moveSpeed * Time.deltaTime; if (Vector3.Distance(targetPosition, transform.position) < 0.1) { moveDirection.x = 0; moveDirection.y = 0; moveDirection.z = 0; jumping = false; } } else { anim.SetFloat(speedHash, 0); } } if (sundial.isDayTime()) { transform.localScale = new Vector3(Mathf.Sign(transform.localScale.x) * 1.5f, 1.5f, 1.0f); if (dayTimeNow != sundial.isDayTime()) { dayTimeNow = sundial.isDayTime(); SF_mutateSmall.Play(); } } else { transform.localScale = new Vector3(Mathf.Sign(transform.localScale.x) * 3.0f, 3.0f, 1.0f); if (dayTimeNow != sundial.isDayTime()) { dayTimeNow = sundial.isDayTime(); SF_mutateBig.Play(); } } anim.SetBool(mutatedHash, !sundial.isDayTime()); if (this.gameObject.activeSelf) { UpdateHunger(); } } }