void Start() { IDLE_TARGET_LOC = new Vector3(-7.0f, 0.0f); TOP_SCREEN_LOC = new Vector3(-7.0f, 3.5f); boulderPooler = ObjectPooler.instance; sporePooler = ObjectPooler.instance; timer = IDLE_TIME; attacked = true; right = true; animator = GetComponent <Animator>(); boulderIndex = boulderPooler.GetIndex(boulderPrefab); sporeIndex = sporePooler.GetIndex(sporePrefab); if (boulderIndex == -1) { Debug.LogError("Boulder not found in object pooler"); boulderIndex = 0; } if (sporeIndex == -1) { Debug.LogError("Spore not found in object pooler"); sporeIndex = 0; } behaviorState = BehaviorState.Idle; direction = -1; attackTimer = DROP_ROCK_INTERVAL; corners = new Vector3[4]; corners[TOP_LEFT_IND] = new Vector3(-8.0f, 3.0f); corners[TOP_RIGHT_IND] = new Vector3(8.0f, 3.0f); corners[BOTTOM_RIGHT_IND] = new Vector3(8.0f, -3.0f); corners[BOTTOM_LEFT_IND] = new Vector3(-8.0f, -3.0f); currCornerInd = 0; cornersLen = corners.Length; lastAtk = LastAttack.None; }
public void Kick() { Stop(); FlipSprite(body.position.x > playerPosition.x); baseAnim.SetTrigger("Kick"); lastAttack = LastAttack.kick; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// Action Methods //////////////////////////////////////////////////////////////////////////////////////////////////// public void Punch() { //seperate methods for each possible attack and select randomly? How many attacks will grunts have? Stop(); //face the player FlipSprite(body.position.x > playerPosition.x); baseAnim.SetTrigger("Punch"); if (lastAttack == LastAttack.punch1) { lastAttack = LastAttack.punch2; } else { lastAttack = LastAttack.punch1; } }
// Update is called once per frame void Update() { timer -= Time.deltaTime; switch (behaviorState) { case BehaviorState.Idle: if (timer <= 0.0f) { if (lastAtk == LastAttack.None || lastAtk == LastAttack.SporeAttack) { // todo: calculate timer based on hp timer = 10.0f; target = TOP_SCREEN_LOC; behaviorState = BehaviorState.DropRocksAttack; } else { timer = 10.0f; currCornerInd = TOP_LEFT_IND; target = corners[currCornerInd]; behaviorState = BehaviorState.SporeAttack; } } break; case BehaviorState.GoToIdlePos: if (closeEnoughToTarget()) { timer = IDLE_TIME; behaviorState = BehaviorState.Idle; } else { target = IDLE_TARGET_LOC; move(); } break; case BehaviorState.DropRocksAttack: lastAtk = LastAttack.DropsRocksAttack; attackTimer -= Time.deltaTime; if (timer <= 0.0f) { target = IDLE_TARGET_LOC; behaviorState = BehaviorState.GoToIdlePos; } else { if (!closeEnoughToTarget()) { // move to top of screen move(); } else { // oscillate between left and right of screen // todo: have it check if collided instead target = new Vector3(9 * direction, 3.5f); if (transform.position.x <= -8.0f) { direction = 1; } if (transform.position.x >= 8.0f) { direction = -1; } } if (attackTimer <= 0.0f) { GameObject aBoulder = boulderPooler.GetDanmaku(boulderIndex); aBoulder.SetActive(true); if (aBoulder != null) { Boulder boulderScript = aBoulder.GetComponent <Boulder>(); aBoulder.transform.position = gameObject.transform.position; } // reset the timer attackTimer = DROP_ROCK_INTERVAL; } } break; case BehaviorState.SporeAttack: lastAtk = LastAttack.SporeAttack; attackTimer -= Time.deltaTime; if (!closeEnoughToTarget()) { // move to corner of screen move(); } else { // switch to next target if (currCornerInd < cornersLen - 1) { currCornerInd += 1; target = corners[currCornerInd]; } else { target = IDLE_TARGET_LOC; behaviorState = BehaviorState.GoToIdlePos; } } if (attackTimer <= 0.0f) { // let a spore loose GameObject aSpore = boulderPooler.GetDanmaku(sporeIndex); aSpore.SetActive(true); if (aSpore != null) { Spore boulderScript = aSpore.GetComponent <Spore>(); aSpore.transform.position = gameObject.transform.position; } // reset the timer attackTimer = EXCRETE_SPORE; } break; } }
public virtual void Update() { FreezeEnemy(); // camera bounds camera = Camera.main.transform.position; leftCamBound = camera.x - cameraHalfWidth; rightCamBound = camera.x + cameraHalfWidth; if (GameManager.enemiesOn && enemyPaused) //unpause { enemyPaused = false; //body.Sleep(); baseAnim.enabled = true; } if (!GameManager.enemiesOn && !enemyPaused) //disable animator on first pass after pause { enemyPaused = true; baseAnim.enabled = false; //body.WakeUp(); return; } else if (enemyPaused) //just skip update { return; } base.Update(); CheckAnims(); playerPosition = playerReference.transform.position; float currentDistance = Vector3.Distance(body.position, playerPosition); float currentXDistance = Mathf.Abs(body.position.x - playerPosition.x); //need this for preDialogue checks playerEngagements = playerReference.GetComponent <Hero>().engaged; //remains fully idle until player reaches a certain point (should be equivalent to a dialogue point) if (currentState == EnemyState.preDialogueIdle) { Stop(); Debug.Log("in predialogue"); if (currentXDistance < preDialogueBufferDist) { currentState = EnemyState.idle; Debug.Log("breaking out of predialogue"); } return; } if (isWaiting && !isFleeing) { isWaiting = !playerReference.GetComponent <Hero>().Engage(this); } if (paused >= 0) { paused--; } else if (isWaiting) { currentState = EnemyState.waiting; } //Universal state change logic else if (!(isLaunching || isHurting || isAttacking || isWaiting || isGrounded || isStanding || isTeleporting)) { DetermineState(currentDistance); } else { currentState = EnemyState.idle; } //reset the combo indicator if we interrupted attacking, unless player is launched from a heavy attack. if (currentState != EnemyState.attacking) { lastAttack = LastAttack.none; } //Act on the current state ChangeState(currentState); lastDistance = currentDistance; lastPosition = transform.position; }