Exemple #1
0
    private void Start()
    {
        // default player attribute
        player_state                      = States.Idle;
        player_attack_state               = AttackStates.None;
        player_jump_force                 = 20f;
        player_speed                      = 10f;
        player_dash_attack_speed          = 30f;
        player_dash_attack_duration       = 0.15f;
        player_dash_attack_cooldown       = 1f;
        is_player_facing_right            = true;
        can_player_shoot_sfx              = true;
        max_player_distance               = 1.25f;
        projectile_player_speed           = 2.5f;
        bullet_speed                      = 7f;
        player_projectile_attack_cooldown = 1.5f;
        dash_attack_timer                 = player_dash_attack_duration;

        // unity object init
        player            = GameObject.FindWithTag("Player");
        projectile_player = GameObject.FindWithTag("Projectile Player");
        player_rb         = player.GetComponent <Rigidbody2D>();
        player_collider   = player.GetComponent <BoxCollider2D>();
        player_animator   = player.GetComponent <Animator>();
    }
Exemple #2
0
    // Start is called before the first frame update
    void Start()
    {
        fsm = new FSM_System_MonsterS();

        FSM_MonsterS patrol = new PatrolStates(fsm, 1, this.gameObject);

        fsm.AddState(patrol);
        patrol.Addtransition(Transition.Inattackrange, Monster_State.Attack);
        patrol.Addtransition(Transition.Attacked, Monster_State.Hurt);

        FSM_MonsterS attack = new AttackStates(fsm, 1, this.gameObject);

        fsm.AddState(attack);
        attack.Addtransition(Transition.Searchhero, Monster_State.Trace);
        attack.Addtransition(Transition.Attacked, Monster_State.Hurt);

        FSM_MonsterS hurt = new HurtStates(fsm, 1, this.gameObject);

        fsm.AddState(hurt);
        hurt.Addtransition(Transition.Searchhero, Monster_State.Trace);
        hurt.Addtransition(Transition.Outoflife, Monster_State.Die);

        FSM_MonsterS die = new DieStates(fsm, 1, this.gameObject);

        fsm.AddState(die);
    }
Exemple #3
0
    public static void AddState(State state)
    {
        switch (state.Type)
        {
        case States.Idle:
            var idle = state as IdleState;
            IdleStates.Add(idle);
            break;

        case States.Build:
            var build = state as BuildState;
            BuildStates.Add(build);
            break;

        case States.Attack:
            var attack = state as AttackState;
            AttackStates.Add(attack);
            break;

        case States.Conquer:
            var conquer = state as ConquerState;
            ConquerStates.Add(conquer);
            break;

        case States.Move:
            var move = state as MoveState;
            MoveStates.Add(move);
            break;
        }
    }
Exemple #4
0
 private void StopFlip()
 {
     _attackState = AttackStates.None;
     //AttackableExit(ref _hitAttackableCache);
     // _boardAnimator.SetBool( "Flip", false );
     PlayerEvents.Instance.StopKickAttack();
 }
Exemple #5
0
    private IEnumerator attack_cooldown(float time)
    {
        wizard_attack_states = AttackStates.AttackCooldown;
        yield return(new WaitForSeconds(time));

        wizard_attack_states = AttackStates.AttackReady;
    }
Exemple #6
0
 private void StopSlash()
 {
     _attackState = AttackStates.None;
     //AttackableExit(ref _hitAttackableCache);
     // _boardAnimator.SetBool( "Slash", false );
     PlayerEvents.Instance.StopSlashAttack();
     _boardTrail.emitting = false;
 }
Exemple #7
0
 private void StartFlip()
 {
     _attackState   = AttackStates.Flip;
     _flipTimestamp = Time.unscaledTime;
     _attackID++;
     // _boardAnimator.SetBool( "Flip", true );
     PlayerEvents.Instance.StartKickAttack();
 }
Exemple #8
0
    private IEnumerator attack_cooldown(float time)
    {
        player_attack_state = AttackStates.AttackCooldown;
        cooldown_bar.SendMessage("set_max_value", time);
        yield return(new WaitForSeconds(time));

        player_attack_state  = AttackStates.None;
        can_player_shoot_sfx = true;
    }
Exemple #9
0
 private void StartSlash()
 {
     _attackState    = AttackStates.Slash;
     _slashTimestamp = Time.unscaledTime;
     _attackID++;
     // _boardAnimator.SetBool( "Slash", true );
     PlayerEvents.Instance.StartSlashAttack();
     _boardTrail.emitting = true;
 }
Exemple #10
0
    private void Update()
    {
        // wizard finite state machine
        // changing states
        float distance_from_player = Vector2.Distance(player.transform.position, this.transform.position);
        float x_diff = player.transform.position.x - this.transform.position.x;

        if (distance_from_player <= desired_distance && wizard_attack_states != AttackStates.Attacking)
        {
            wizard_states = States.Moving;
        }
        else if (distance_from_player >= desired_distance && wizard_states == States.Moving)
        {
            wizard_states = States.Idle;
        }

        // state function
        if (wizard_states == States.Idle)
        {
            wizard_rb.velocity = new Vector2(0, 0);
            if ((x_diff < 0f && is_facing_right) || (x_diff > 0f && !is_facing_right))
            {
                flip();
            }
        }
        if (wizard_states == States.Moving)
        {
            if (Mathf.Abs(x_diff) >= 0.01f)
            {
                wizard_rb.velocity = new Vector2(move_speed * Mathf.Sign(x_diff), 0);
            }

            if ((x_diff < 0f && is_facing_right) || (x_diff > 0f && !is_facing_right) && Mathf.Abs(x_diff) <= 0.001f)
            {
                flip();
            }
        }

        // wizard attack finite state machine
        // changing states
        if (wizard_attack_states == AttackStates.AttackReady)
        {
            wizard_attack_states = AttackStates.Attacking;
            wizard_states        = States.Idle;
        }

        // state function
        if (wizard_attack_states == AttackStates.Attacking)
        {
            if (shoot_projectile())
            {
                StartCoroutine(attack_cooldown(shoot_cooldown));
            }
        }
    }
 internal void IncreaseAttack()
 {
     if (attackState != AttackStates.MoreBullets)
     {
         Debug.Log("Attack upgrade");
         speedState   = SpeedStates.Normal;
         attackState += 1;
         SetSpeed(SpeedStates.Normal);
         SetAttack(attackState);
     }
 }
Exemple #12
0
    public static IState NewState(this AttackStates stateType)
    {
        switch (stateType)
        {
        case AttackStates.FastSlash:
            return(new FastSlashState(PlayerNiklas.Player));

        default:
            return(null);
        }
    }
 internal void IncreaseSpeed()
 {
     if (speedState != SpeedStates.Flash)
     {
         Debug.Log("Speed upgrade");
         speedState  = speedState + 1;
         attackState = AttackStates.Normal;
         SetSpeed(speedState);
         SetAttack(attackState);
     }
 }
 public override void FParry()
 {
     animator.Play("fParry", 0, 0f);
     if (status.sheathed == false)
     {
         state       = AttackStates.fParry; //set the attack state;
         idleCounter = 60;                  //always remember to reset the idle counter
     }
     stat.MP -= 20;
     StartCoroutine(status.Parry(0.3f, 15, 60, 60));
     movement.motor.InstantBurst(700f, -100f);
 }
Exemple #15
0
        //Contact Damage
        public static void InflictDamage(
            GameObject target,
            int damageToGive,
            bool isPlayer,
            AttackStates inflict  = AttackStates.none,
            decimal inflictChance = 0)
        {
            if (isPlayer) //attack hitting the player
            {
                //check if damage would be zero after defense calculation
                int totalDamage = damageToGive - (target.GetComponent <PlayerMain>().def * 2);
                if (totalDamage >= 0)
                {
                    Mathf.Floor(target.GetComponent <PlayerMain>().curHP -= totalDamage);
                    if (inflict == AttackStates.poison)
                    {
                        if (Random.Range(1, 100) >= 75)
                        {
                            target.GetComponent <PlayerMain>().activeState = AttackStates.poison;
                        }
                    }
                }
                else
                {
                    target.GetComponent <PlayerMain>().curHP -= 1;
                }

                //Debug.Log("gave damage to " + target.name + " for " + (baseDamage / target.GetComponent<PlayerMain>().def) + ". hp of target is now " + target.GetComponent<PlayerMain>().curHP);
            }
            else   //attack hitting an enemy
            {
                if (damageToGive >= 0)
                {
                    Mathf.Floor(target.GetComponent <EnemyMain>().curHP -= damageToGive);
                    if (inflict == AttackStates.poison)
                    {
                        if (Random.Range(1, 100) >= 75)
                        {
                            target.GetComponent <EnemyMain>().activeState = AttackStates.poison;
                        }
                    }
                }
                else
                {
                    target.GetComponent <EnemyMain>().curHP -= 1;
                }

                //Debug.Log("gave damage to " + target.name + " for " + (baseDamage / target.GetComponent<EnemyMain>().def) + ". hp of target is now " + target.GetComponent<EnemyMain>().curHP);
            }
        }
	private void UpdateUnitChargeUp( Vector3 direction )
	{
		if ( State != AttackStates.ChargingUp ) return;

		// Shake violently
		transform.localPosition += new Vector3( Random.Range( -0.01f, 0.01f ), 0, Random.Range( -0.01f, 0.01f ) );

		// Move to attacking
		ChargeTime += Time.deltaTime * ChargeUpSpeed;
        if ( ChargeTime >= 1 )
		{
			State = AttackStates.Attacking;
		}
	}
Exemple #17
0
 // Use this for initialization
 private void Awake()
 {
     rb2d  = GetComponent <Rigidbody2D>();
     anim  = GetComponent <Animator>();
     timer = 0;
     anim.SetBool("rolling", false);
     anim.SetBool("dashing", false);
     dashAmount = totalDashes;
     timer2     = 0;
     attTimer   = 0;
     RollingL   = false;
     RollingR   = false;
     tapped     = false;
     airAttack  = false;
     attst      = AttackStates.rest;
 }
Exemple #18
0
    // Use this for initialization
    void Start()
    {
        _player     = GameObject.Find("Player");
        myRigidbody = GetComponent <Rigidbody>();

        controlPoint = transform.position;
        destination  = transform.position;

        states    = GlobalStates.Roam;
        actStates = AttackStates.Wait;

        isPaused = false;

        animator.SetBool("Move", false);
        animator.SetInteger("Direction", 3);
    }
	private void UpdateUnitRotate( Vector3 direction )
	{
		if ( State != AttackStates.Rotating ) return;

		// Reset on all but yaw axis
		transform.eulerAngles = new Vector3( 0, transform.eulerAngles.y, 0 );

		// Rotate towards the victim player
		Vector3 lookdirection = Vector3.RotateTowards( transform.forward, direction, Time.deltaTime * LerpSpeed / 2.0f, 0.0F );
		transform.rotation = Quaternion.LookRotation( lookdirection );

		float distance = Vector3.Distance( transform.forward, direction );
		if ( distance < 0.1f )
		{
			State = AttackStates.ChargingUp;
        }
	}
 //Every X seconds attempt to change to melee or ranged attacks
 private void FuzzyStateTimer()
 {
     if (fuzzyTimer <= 0)
     {
         fuzzyTimer = UnityEngine.Random.Range(4f, 10f);
         if (UnityEngine.Random.Range(0f, 1f) < fuzzyProb)
         {
             attackState   = AttackStates.DEFAULT;
             chaseDistance = 10f;
         }
         else
         {
             attackState   = AttackStates.RANGED;
             chaseDistance = 15f;
         }
     }
 }
Exemple #21
0
    private void Start()
    {
        // default wizard attribute
        wizard_states        = States.Idle;
        wizard_attack_states = AttackStates.AttackReady;
        move_speed           = 4f;
        desired_distance     = 4f;
        bullet_speed         = 3f;
        is_facing_right      = false;
        shoot_cooldown       = 5f;
        shoot_duration       = 1f;
        shoot_timer          = shoot_duration;

        // unity object init
        player          = GameObject.FindWithTag("Player");
        wizard_rb       = GetComponent <Rigidbody2D>();
        wizard_animator = GetComponent <Animator>();
    }
    private void FixedUpdate()
    {
        //if death
        if (curHP <= 0)
        {
            PlayerMain.Exp  += Exp;
            PlayerMain.gold += gold;
            Destroy(this.gameObject);
        }

        //Ability bar/timer
        if (curAPTime >= 0)
        { //timer step
            curAPTime -= 0.1f;
        }
        else
        { //perform ability
          //Debug.Log(this.gameObject.name + " Attacked.");

            if (maxAttack != 0)
            {
                Instantiate(attacks[Random.Range(0, maxAttack)], projSpawn.transform);
            }

            curAPTime = apTime;
        }

        if (activeState != AttackStates.none)
        {
            StateTimerStep();
        }
        //player states
        //..poison
        if (activeState == AttackStates.poison && startState)
        {
            States.PoisionDamage(gameObject, maxHP);
            startState  = false;
            statesTimer = statesTimerMax;
        }
        if (curHP <= maxHP / 4)
        {
            activeState = AttackStates.none;
        }
    }
    public override void ReturnToIdle()
    {
        //manage returning to idle
        if (state != AttackStates.idle)
        {
            if (state != AttackStates.guarding)
            {
                status.toIdleLock = true;
            }
            idleCounter--;
        }

        if (idleCounter <= 0)
        {
            idleCounter       = 0;
            state             = AttackStates.idle;
            status.toIdleLock = false;
        }
    }
Exemple #24
0
    // Fonction qui gere le roaming de l'ennemi
    void Roam()
    {
        if ((Vector3.Distance(transform.position, destination) < 0.7f))
        {
            isPaused = true;
            if (timerRoam > timeBetweenRoam)
            {
                Vector3 point = Random.insideUnitSphere;
                point.y = 0;
                if (IsFree(controlPoint + (point.normalized * RoamRadius)))
                {
                    destination = controlPoint + (point.normalized * RoamRadius);
                    timerRoam   = 0;
                    isPaused    = false;
                    dontLook    = false;
                }
            }
            timerRoam += Time.deltaTime;
        }


        Collider[] targets = Physics.OverlapSphere(this.transform.position, distanceVision);

        foreach (Collider target in targets)
        {
            if (target.name == "Player")
            {
                Vector3 direction = _player.transform.position - transform.position;

                RaycastHit hit;
                if (Physics.Raycast(transform.position, direction.normalized, out hit, distanceVision))
                {
                    if (hit.collider.gameObject == _player)
                    {
                        states     = GlobalStates.Attack;
                        actStates  = AttackStates.Wait;
                        nextStates = AttackStates.GetCloser;
                    }
                }
            }
        }
    }
Exemple #25
0
    public static void RemoveState(State state)
    {
        switch (state.Type)
        {
        case States.Idle:
            if (IdleStates.Contains(state))
            {
                IdleStates.Remove(state);
            }
            break;

        case States.Build:
            if (BuildStates.Contains(state))
            {
                BuildStates.Remove(state);
            }
            break;

        case States.Attack:
            if (AttackStates.Contains(state))
            {
                AttackStates.Remove(state);
            }
            break;

        case States.Conquer:
            if (ConquerStates.Contains(state))
            {
                ConquerStates.Remove(state);
            }
            break;

        case States.Move:
            if (MoveStates.Contains(state))
            {
                MoveStates.Remove(state);
            }
            break;
        }
    }
Exemple #26
0
    void Charging(int nbCharge)
    {
        if (!isCharging)
        {
            chargeDone = 0;
            isCharging = true;
        }

        if (chargeDone < nbCharge)
        {
            if (timer > chargeInterval && isCharging)
            {
                dirJoueurEnemy = _player.transform.position - transform.position;
                chargeDir      = dirJoueurEnemy.normalized;
                destination    = _player.transform.position;
                goingToCharge  = true;
                timerCharge    = 0;
                chargeDone++;
                timer = 0;
                transform.GetComponent <Collider>().isTrigger = true;
            }
            timer += Time.deltaTime;
        }

        if (timerCharge > chargeTime)
        {
            transform.GetComponent <Collider>().isTrigger = false;
            goingToCharge = false;
        }

        if (isCharging && chargeDone == nbCharge && !goingToCharge)
        {
            isCharging = false;
            nextStates = AttackStates.Move;
            actStates  = AttackStates.Wait;
        }

        timerCharge += Time.deltaTime;
    }
    /// <summary>
    /// Assumes that target unit is player.
    /// </summary>
    /// <param name="attackState"></param>
    void SetAttack(AttackStates attackState)
    {
        switch (attackState)
        {
        case AttackStates.Normal:
            ((PlayerInput)(targetUnit.input)).guns.SmallerBullets();
            ((PlayerInput)(targetUnit.input)).guns.SupportFire(false);
            break;

        case AttackStates.BiggerBullets:
            ((PlayerInput)(targetUnit.input)).guns.BiggerBullets();
            ((PlayerInput)(targetUnit.input)).guns.SupportFire(false);
            break;

        case AttackStates.MoreBullets:
            ((PlayerInput)(targetUnit.input)).guns.BiggerBullets();
            ((PlayerInput)(targetUnit.input)).guns.SupportFire(true);
            break;

        default:
            break;
        }
    }
Exemple #28
0
    void Tir(int nbTir)
    {
        if (!shooting)
        {
            shotDone       = 0;
            shooting       = true;
            dirJoueurEnemy = _player.transform.position - transform.position;
            shotDir        = dirJoueurEnemy.normalized;
        }

        if (shotDone < nbTir)
        {
            if (timer > shotInterval && shooting)
            {
                //Debug.Log("bang!");
                //GameObject clone = Instantiate(shot, transform.position, transform.rotation) as GameObject;
                // clone.GetComponent<Rigidbody>().AddForce(shotDir * shotSpeed);

                GameObject clone = ObjectPooler.current.GetObject(shot);
                clone.SetActive(true);
                clone.transform.position = transform.position;
                clone.transform.rotation = transform.rotation;
                clone.GetComponent <Rigidbody>().velocity = (shotDir * shotSpeed);

                shotDone++;
                timer = 0;
            }
            timer += Time.deltaTime;
        }

        if (shooting && shotDone == nbTir)
        {
            shooting   = false;
            nextStates = AttackStates.Move;
            actStates  = AttackStates.Wait;
        }
    }
Exemple #29
0
    void StateMachine()
    {
        gameTime += Time.deltaTime;
        if (numberOfTimesHit == 3)
        {
            lerpTimer += Time.deltaTime;
            Color newCol = (Color.Lerp(originalColor, redColor, lerpTimer));
            BossRenderer.material.SetColor("_Color", newCol);
            if (lerpTimer > 1)
            {
                lerpTimer = 1;
            }
        }
        switch (BeetleLogic)
        {
        case BossStates.INGROUND:
            //???? just incase the beetle needs to do some logic here

            if (bNotInGround)
            {
                ChangeState(0f, BossStates.IDLE);
            }
            break;

        case BossStates.IDLE:
            attackInt = Random.value;     //sets the attack int
            _neptoScript.shootCount = 0;  //resets the shot count back to zero
            ResetAnim();
            //BossAnim.SetBool("bIsWalking", false);
            ChangeState(5f, BossStates.WALKING);      //after 10 seconds of idling, move to next state
            break;

        case BossStates.WALKING:
            //beetle walks until in range of player then it shoots
            MoveToPlayer(transform.position, player.position, 2f);
            BossAnim.SetBool("bIsWalking", true);

            break;

        case BossStates.ATTACK:
            BossAnim.SetBool("bIsWalking", false); //sets walking anim to OFF
            switch (numberOfTimesHit)              //checks how many times the beetle has been hit
            {
            case 0:
                AttackLogic = AttackStates.AIMING;
                break;

            case 1:
                if (attackInt <= 0.5f)
                {
                    AttackLogic = AttackStates.AIMING;
                }
                else
                {
                    AttackLogic = AttackStates.DASH;
                }
                break;

            case 2:
                if (attackInt <= 0.5f)
                {
                    AttackLogic = AttackStates.AIMING;
                }
                else
                {
                    AttackLogic = AttackStates.DASH;
                }
                break;

            case 3:
                //     BossRenderer.material.SetColor("_Color", new Color(0.84f, 0, 0));
                if (attackInt <= 0.3f)
                {
                    AttackLogic = AttackStates.AIMING;
                }
                else
                {
                    AttackLogic = AttackStates.DASH;
                }
                break;

            case 4:
                //   BossRenderer.material.SetColor("_Color", new Color(0.84f, 0, 0));
                if (attackInt <= 0.3f)
                {
                    AttackLogic = AttackStates.AIMING;
                }
                else
                {
                    AttackLogic = AttackStates.DASH;
                }
                break;

            case 5:
                //dead
                BossAnim.Play("Boss_ESCAPE");
                ResetAnim();
                _neptoScript.enabled = false;

                break;
            }
            AttackStateMachine();
            break;

        case BossStates.STUNNED:
            hasDeflected = false;
            stunTimer   += Time.deltaTime;
            if (!isWingOpen)
            {
                beetleCollider.isTrigger = true;     //you can't hit it if the wings are closed
                BossAnim.SetBool("bWingsClose", true);
                //check if has tongued
                if (hasTongued)
                {
                    BossAnim.SetBool("bWingsClose", false);
                    BossAnim.SetBool("bHasTongued", true);
                    BeetleLogic = BossStates.PRYING;
                }
                else if (stunTimer > 10f)
                {
                    BossAnim.SetTrigger("tStunEnd");   //stun ends
                    BeetleLogic = BossStates.IDLE;     //back to idle
                    gameTime    = 0;
                    stunTimer   = 0;
                    BossAnim.SetBool("bHasTongued", false);
                }
            }
            if (isWingOpen)     //if the wings are open while its stunned
            {
                beetleCollider.isTrigger = false;
                BossAnim.SetBool("bWingsClose", false); //set the correct boolean to play the correct animation
                if (hasHit)                             //if the player hits the beetle
                {
                    BossAnim.SetBool("bWingsClose", true);
                    beetleCollider.isTrigger = true;
                    BossAnim.SetBool("bHasDeflected", false);
                    stunTimer = 0;
                    ChangeState(1f, BossStates.IDLE);
                    hasHit     = false;
                    isWingOpen = false;
                }
                else if (stunTimer > 10f)            //but if the timer exceeds
                {
                    BossAnim.SetTrigger("tStunEnd"); //stun ends
                    BeetleLogic = BossStates.IDLE;   //back to idle
                    gameTime    = 0;
                    stunTimer   = 0;
                    BossAnim.SetBool("bHasDeflected", false);
                }
            }

            break;

        case BossStates.PRYING:
            BossAnim.SetBool("bHasTongued", false);
            hasTongued = false;
            pryTimer  += Time.deltaTime;
            if (GamepadManager.buttonBDown)
            {
                BossAnim.SetTrigger("tPry");
                isWingOpen  = true;
                BeetleLogic = BossStates.STUNNED;
                gameTime    = 0;
                pryTimer    = 0;
                stunTimer   = 0;
            }
            else if (pryTimer > 10f)
            {
                BossAnim.SetTrigger("tPryEnd");
                BeetleLogic = BossStates.IDLE;
                gameTime    = 0;
                pryTimer    = 0;
            }
            break;

        case BossStates.HIT:
            break;

        case BossStates.DEATH:
            break;
        }
    }
Exemple #30
0
    public void ToggleAttack(int onNum)
    {
        bool on = (onNum == 1);

        //SwordWeapon.damage = currentDamage;
        //SwordCollider.enabled = on;

        if (on)
        {
            attackState = AttackStates.Attacking;
        }
        else
        {
            myAnimator.SetInteger("attackNum", 0);
            //attackState = AttackStates.Finishing;
        }
    }
Exemple #31
0
 /// <summary>
 /// Ends the current combo and resets the values.
 /// </summary>
 void EndCombo()
 {
     attackState = AttackStates.None;
     myAnimator.SetBool("attacking", false);
     nextAttack = null;
     currentComboString = "";
 }
Exemple #32
0
    // Use this for initialization
    void Start()
    {
        _player = GameObject.Find("Player");
        myRigidbody = GetComponent<Rigidbody>();

        controlPoint = transform.position;
        destination = transform.position;

        states = GlobalStates.Roam;
        actStates = AttackStates.Wait;

        isPaused = false;

        normalColor = skin.GetComponent<Renderer>().material.color;

        animator.SetBool("Move", false);
        animator.SetInteger("Direction", 3);
    }
Exemple #33
0
    /// <summary>
    /// Ends the current attack animation.
    /// </summary>
    void EndAttack(string weapon)
    {
        myAnimator.SetInteger("attackNum", 0);
        currentDamage = 0;

        if (weapon == "sword")
        {
            SwordWeapon.Toggle(false);
        }
        else
        {
            GunWeapon.Toggle(false);
        }

        if (String.IsNullOrEmpty(nextAttack))
        {
            attackState = AttackStates.OpenLocked;
            StartCoroutine("ComboCoolDown");
            state = States.Idle;
        }
        else
        {
            attackState = AttackStates.None;
            CalculateAttack(nextAttack[0]);
            nextAttack = "";
        }
    }
Exemple #34
0
 /// <summary>
 /// Combo window after the attack stops dealing damage to advance the combo.
 /// </summary>
 IEnumerator ComboCoolDown()
 {
     yield return new WaitForSeconds(comboLocked);
     attackState = AttackStates.OpenFree;
     yield return new WaitForSeconds(comboFree);
     EndCombo();
 }
Exemple #35
0
    // Fonction qui gere le roaming de l'ennemi
    void Roam()
    {
        if ((Vector3.Distance(transform.position, destination) < 1.5f))
        {
            isPaused = true;
            if (timerRoam > timeBetweenRoam)
            {
                Vector3 point = Random.insideUnitSphere;
                point.y = 0;
                if (IsFree(controlPoint + (point.normalized * RoamRadius)))
                {
                    destination = controlPoint + (point.normalized * RoamRadius);
                    timerRoam = 0;
                    isPaused = false;
                    dontLook = false;
                }
            }
            timerRoam += Time.deltaTime;
        }

        Collider[] targets = Physics.OverlapSphere(this.transform.position, distanceVision);

        foreach (Collider target in targets)
        {
            if (target.name == "Player")
            {
                Vector3 direction = _player.transform.position - transform.position;

                RaycastHit hit;
                if (Physics.Raycast(transform.position, direction.normalized, out hit, distanceVision, visionMask))
                {
                    if (hit.collider.gameObject == _player)
                    {
                        states = GlobalStates.Attack;
                        actStates = AttackStates.Wait;
                        nextStates = AttackStates.GetCloser;
                    }
                }

            }
        }
    }
	private void UpdateUnitAttacking( Vector3 direction )
	{
		if ( State != AttackStates.Attacking ) return;

		GameObject projectile = (GameObject) Instantiate( ProjectilePrefab, transform.position, transform.rotation );
		projectile.transform.LookAt( transform.position + ( direction * 10 ) );
		projectile.GetComponentInChildren<Rigidbody>().velocity = direction * ProjectileSpeed;
		projectile.transform.SetParent( GameObject.Find( "GameObjectContainer" ).transform );
		projectile.transform.GetChild( 0 ).GetChild( 0 ).GetComponent<AudioSource>().pitch = Random.Range( 0.9f, 1.1f );

		State = AttackStates.ChargingDown;
	}
Exemple #37
0
    void Tir(int nbTir)
    {
        if (!shooting)
        {
            shotDone = 0;
            shooting = true;
            dirJoueurEnemy = _player.transform.position - transform.position;
            shotDir = dirJoueurEnemy.normalized;
        }

           if (shotDone < nbTir)
        {
            if (timer > shotInterval && shooting)
            {
                //Debug.Log("bang!");
                //GameObject clone = Instantiate(shot, transform.position, transform.rotation) as GameObject;
               // clone.GetComponent<Rigidbody>().AddForce(shotDir * shotSpeed);

                GameObject clone = ObjectPooler.current.GetObject(shot);
                clone.SetActive(true);
                clone.transform.position = transform.position;
                clone.transform.rotation = transform.rotation;
                clone.GetComponent<Rigidbody>().velocity = (shotDir * shotSpeed);

                shotDone++;
                timer = 0;
            }
            timer += Time.deltaTime;
        }

        if (shooting && shotDone == nbTir)
        {
            shooting = false;
            nextStates = AttackStates.Move;
            actStates = AttackStates.Wait;
        }
    }
Exemple #38
0
 public virtual void onEndAttack()
 {
     currentState            = Attack.AttackStates.IDLE;
     character.currentAttack = null;
     rechargeTimer           = rechargeTime;///character.stats.agility;
 }
	private void UpdateUnitAttacking( Vector3 direction )
	{
		if ( State != AttackStates.Attacking ) return;

		Quaternion lookattarget = Quaternion.LookRotation( direction );

		GameObject projectile = (GameObject) Instantiate( ProjectilePrefab, transform.position, lookattarget );
		projectile.transform.LookAt( transform.position + ( direction * 10 ) );
		projectile.transform.SetParent( GameObject.Find( "GameObjectContainer" ).transform );
		projectile.transform.GetChild( 0 ).GetChild( 0 ).GetComponent<AudioSource>().pitch = Random.Range( 0.9f, 1.1f );

		// Return to moving
		HasControl = false;
		UnitMovement.HasControl = true;
		State = AttackStates.ChargingUp;
		ChargeTime = 0;
    }
Exemple #40
0
 protected IEnumerator AttackCoolDown(float time)
 {
     attackState = AttackStates.Waiting;
     yield return new WaitForSeconds(time);
     attackState = AttackStates.Ready;
 }
Exemple #41
0
    public virtual void Spawn(Vector3 position)
    {
        myTransform.position = position;
        myAlign.Align();

        myRenderer.enabled = true;
        state = States.Spawning;
        attackState = AttackStates.Ready;
        health = maxHealth;
        myNavAgent.FindPath(PlayerTransform.position);
        state = States.Idle; // no spawning animation yet
    }
	private void UpdateUnitChargeUp( Vector3 direction )
	{
		if ( State != AttackStates.ChargingUp ) return;

		// Mouth widen
		{
			Hat.transform.rotation = Quaternion.Lerp(
				Hat.transform.rotation,
				Jaw_Open.rotation,
				Time.deltaTime * ChargeUpSpeed
			);
		}
		// Shake violently
		transform.localPosition += new Vector3( Random.Range( -0.01f, 0.01f ), 0, Random.Range( -0.01f, 0.01f ) );

		// Move to attacking
		if ( Quaternion.Angle( Hat.transform.rotation, Jaw_Open.rotation ) < 1 )
		{
			State = AttackStates.Attacking;
		}
	}
Exemple #43
0
    void StateMachine()
    {
        gameTime += Time.deltaTime;
        if(numberOfTimesHit == 3)
        {
            lerpTimer += Time.deltaTime;
            Color newCol = (Color.Lerp(originalColor, redColor, lerpTimer));
            BossRenderer.material.SetColor("_Color", newCol);
            if(lerpTimer >1)
            {
                lerpTimer = 1;
            }
        }
        switch (BeetleLogic)
        {
            case BossStates.INGROUND:
                //???? just incase the beetle needs to do some logic here

                if(bNotInGround)
                {
                    ChangeState(0f, BossStates.IDLE);
                }
                break;
            case BossStates.IDLE:
                attackInt = Random.value; //sets the attack int
                _neptoScript.shootCount = 0; //resets the shot count back to zero
                ResetAnim();
                //BossAnim.SetBool("bIsWalking", false);
                ChangeState(5f, BossStates.WALKING);  //after 10 seconds of idling, move to next state
                break;
            case BossStates.WALKING:
                //beetle walks until in range of player then it shoots
                MoveToPlayer(transform.position, player.position, 2f);
                BossAnim.SetBool("bIsWalking", true);
                
                break;
            case BossStates.ATTACK:
                BossAnim.SetBool("bIsWalking", false); //sets walking anim to OFF
                switch (numberOfTimesHit) //checks how many times the beetle has been hit
                {
                    case 0:
                        AttackLogic = AttackStates.AIMING;
                        break;
                    case 1:
                        if(attackInt <= 0.5f)
                        {
                            AttackLogic = AttackStates.AIMING;
                        }
                        else
                        {
                            AttackLogic = AttackStates.DASH;
                        }
                        break;
                    case 2:
                        if (attackInt <= 0.5f)
                        {
                            AttackLogic = AttackStates.AIMING;
                        }
                        else
                        {
                            AttackLogic = AttackStates.DASH;
                        }
                        break;
                    case 3:
                   //     BossRenderer.material.SetColor("_Color", new Color(0.84f, 0, 0));
                        if (attackInt <= 0.3f)
                        {
                            AttackLogic = AttackStates.AIMING;
                        }
                        else
                        {
                            AttackLogic = AttackStates.DASH;
                        }
                        break;
                    case 4:
                     //   BossRenderer.material.SetColor("_Color", new Color(0.84f, 0, 0));
                        if (attackInt <= 0.3f)
                        {
                            AttackLogic = AttackStates.AIMING;
                        }
                        else
                        {
                            AttackLogic = AttackStates.DASH;
                        }
                        break;
                    case 5:
                        //dead
                        BossAnim.Play("Boss_ESCAPE");
                        ResetAnim();
                        _neptoScript.enabled = false;
                   
                        break;
                }
                AttackStateMachine();
                break;
            case BossStates.STUNNED:
                hasDeflected = false;
                stunTimer += Time.deltaTime;
                if (!isWingOpen)
                {
                    beetleCollider.isTrigger = true; //you can't hit it if the wings are closed
                    BossAnim.SetBool("bWingsClose", true);
                    //check if has tongued
                    if(hasTongued)
                    {
                        BossAnim.SetBool("bWingsClose", false);
                        BossAnim.SetBool("bHasTongued", true);
                        BeetleLogic = BossStates.PRYING;
                    }
                    else if(stunTimer > 10f)
                    {
                        BossAnim.SetTrigger("tStunEnd"); //stun ends
                        BeetleLogic = BossStates.IDLE; //back to idle
                        gameTime = 0;
                        stunTimer = 0;
                        BossAnim.SetBool("bHasTongued", false);
                    }
                }
                if (isWingOpen) //if the wings are open while its stunned
                {
                    beetleCollider.isTrigger = false;
                    BossAnim.SetBool("bWingsClose", false); //set the correct boolean to play the correct animation
                    if (hasHit) //if the player hits the beetle
                    {
                        BossAnim.SetBool("bWingsClose", true);
                        beetleCollider.isTrigger = true;
                        BossAnim.SetBool("bHasDeflected", false);
                        stunTimer = 0;
                        ChangeState(1f, BossStates.IDLE);
                        hasHit = false;
                        isWingOpen = false;
                    }
                    else if (stunTimer > 10f) //but if the timer exceeds 
                    {
                        BossAnim.SetTrigger("tStunEnd"); //stun ends
                        BeetleLogic = BossStates.IDLE; //back to idle
                        gameTime = 0;
                        stunTimer = 0;
                        BossAnim.SetBool("bHasDeflected", false);
                    }
                }
               
                break;
            case BossStates.PRYING:
                BossAnim.SetBool("bHasTongued", false);
                hasTongued = false;
                pryTimer += Time.deltaTime;
                if (GamepadManager.buttonBDown)
                {
                    BossAnim.SetTrigger("tPry");
                    isWingOpen = true;
                    BeetleLogic = BossStates.STUNNED;
                    gameTime = 0;
                    pryTimer = 0;
                    stunTimer = 0;
                }
                else if (pryTimer > 10f)
                {
                    BossAnim.SetTrigger("tPryEnd");
                    BeetleLogic = BossStates.IDLE;
                    gameTime = 0;
                    pryTimer = 0;
                }                
                break;
            case BossStates.HIT:
                break;
            case BossStates.DEATH:
                break;
        }
    }
Exemple #44
0
    void Charging(int nbCharge)
    {
        if (!isCharging)
        {
            chargeDone = 0;
            isCharging = true;
        }

        if (chargeDone < nbCharge)
        {
            if (timer > chargeInterval && isCharging)
            {
                dirJoueurEnemy = _player.transform.position - transform.position;
                chargeDir = dirJoueurEnemy.normalized;
                destination = _player.transform.position;
                goingToCharge = true;
                timerCharge = 0;
                chargeDone++;
                timer = 0;
                transform.GetComponent<Collider>().isTrigger = true;
            }
            timer += Time.deltaTime;
        }

        if (timerCharge > chargeTime)
        {
            transform.GetComponent<Collider>().isTrigger = false;
            goingToCharge = false;
        }

        if (isCharging && chargeDone == nbCharge && !goingToCharge)
        {
            isCharging = false;
            nextStates = AttackStates.Move;
            actStates = AttackStates.Wait;
        }

        timerCharge += Time.deltaTime;
    }
Exemple #45
0
	public override bool Attacking(){
		Vector2 distFromTarget = target.rigidbody2D.position - rigidbody2D.position;
		switch (attackState) {
		case AttackStates.Positioning:
			//try to get to attack range
			bool swoopTime = true;
			if(Mathf.Abs(distFromTarget.x) < minSwoop.x){
				swoopTime = false;
				Vector2 t = rigidbody2D.velocity;
				t.x *= .99f;
				rigidbody2D.velocity = t;

			}
			else if(Mathf.Abs(distFromTarget.x) > maxSwoop.x ){
				swoopTime = false;
				rigidbody2D.AddForce(Vector2.right * ((swoopHorF/2) * distFromTarget.x * Time.deltaTime));
			}
			if(Mathf.Abs(distFromTarget.y) < minSwoop.y){
				swoopTime = false;
				Vector2 t = rigidbody2D.velocity;
				t.y *= .95f;
				rigidbody2D.velocity = t;
			}
			else if(Mathf.Abs(distFromTarget.y) > maxSwoop.y){
				swoopTime = false;
				rigidbody2D.AddForce(Vector2.up * ((swoopVerF/2) * distFromTarget.y * Time.deltaTime));
			}
			//GET EM
			RaycastHit2D rh2;
			if(rh2 = Physics2D.Raycast(rigidbody2D.position, distFromTarget, distFromTarget.magnitude)){
				if(rh2 != target) swoopTime = false;
			}
			if(swoopTime){
				attackState = AttackStates.SwoopAttack;
				swoopTarget = target.rigidbody2D.position;
				rigidbody2D.velocity *= .75f;
			}

			RaycastHit2D rh;
			//Debug.DrawRay(rigidbody2D.position, Vector2.right * (distFromTarget.x>0? 2:-2), Color.red);
			//object in the way, avoid it
			if(Physics2D.Raycast(rigidbody2D.position, Vector2.right * (distFromTarget.x>0? 1f:-1f), 2f) != target){
					rigidbody2D.AddForce(Vector2.up * -3 * Time.deltaTime);
			}
			break;
		case AttackStates.SwoopAttack:
			Vector2 distFromSwoopTarget = swoopTarget - rigidbody2D.position;
			if((distFromSwoopTarget.magnitude) < .05f ){
				attackState = AttackStates.SwoopRecover;
				break;
			}
			Vector2 sV = distFromSwoopTarget;
			sV.y *= swoopVerF;
			sV.x = swoopHorF * 3;
			rigidbody2D.AddForce(sV * Time.deltaTime);
			break;
		case AttackStates.SwoopRecover:
			if(timer > recoverTime){
				attackState = AttackStates.Positioning;
			}
			else{
				timer += Time.deltaTime;
				Vector2 t = rigidbody2D.velocity;
				t.x *= .95f;
				rigidbody2D.velocity = t;
				rigidbody2D.AddForce(Vector2.up * swoopVerF * 5 * Time.deltaTime);
			}
			break;
		}
		return true;
	}
	private void UpdateUnitChargeDown( Vector3 direction )
	{
		if ( State != AttackStates.ChargingDown ) return;

		// Mouth widen
		{
			Hat.transform.rotation = Quaternion.Lerp(
				Hat.transform.rotation,
				Jaw_Close.rotation,
				Time.deltaTime * ChargeUpSpeed
			);
		}
		// Shake violently
		transform.localPosition += new Vector3( Random.Range( -0.01f, 0.01f ), 0, Random.Range( -0.01f, 0.01f ) );

		// Return control to movement
		if ( Quaternion.Angle( Hat.transform.rotation, Jaw_Close.rotation ) < 1 )
		{
			HasControl = false;
			UnitMovement.HasControl = true;
			State = AttackStates.Rotating;
		}
	}
Exemple #47
0
    private void FixedUpdate()
    {
        // player movement finite state machine
        // changing state
        //Debug.Log(player_state);
        if (player_state == States.Idle && Input.GetAxis("Horizontal") != 0)
        {
            player_state = States.Walking;
        }
        else if ((player_state == States.Idle || player_state == States.Walking || player_state == States.InAir))
        {
            if (Input.GetKeyDown(KeyCode.Space) && player_state != States.InAir)
            {
                player_state = States.Jumping;
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow) && is_player_on_platform())
            {
                StartCoroutine(fall_down());
                player_state = States.Falling;
            }
            else if (player_rb.velocity.y < -0.1f)
            {
                player_state = States.Falling;
            } // else if (player_rb.velocity.y > 0.1f) {
              //     player_state = States.InAir;
              // }
        }
        else if (player_state == States.Falling && (is_player_on_platform() || is_player_on_ground()))
        {
            player_state = States.Idle;
        }

        // state function
        if (player_state != States.Idle)
        {
            move_player(Input.GetAxis("Horizontal"));
            move_projectile_player();
        }
        if (player_state == States.Jumping)
        {
            player_rb.velocity = new Vector2(player_rb.velocity.x, player_jump_force);
            player_animator.SetTrigger("jump");
            player_state = States.InAir;
        }
        if (player_state == States.Idle)
        {
            move_projectile_player();
        }


        // player attack finite state machine
        // changing state
        //Debug.Log(player_attack_state);
        if (player_attack_state == AttackStates.None && Input.GetKeyDown(KeyCode.Z) &&
            player_state != States.Jumping && player_state != States.Falling)
        {
            player_attack_state = AttackStates.DashAttack;
        }
        else if (player_attack_state == AttackStates.None && Input.GetKeyDown(KeyCode.X))
        {
            player_attack_state = AttackStates.ProjectileAttack;
        }

        // state function
        if (player_attack_state == AttackStates.DashAttack)
        {
            if (can_player_shoot_sfx)
            {
                SFXController.Instance.play("player_dash");
                can_player_shoot_sfx = false;
            }
            if (dash_attack())
            {
                StartCoroutine(attack_cooldown(player_dash_attack_cooldown));
            }
        }
        if (player_attack_state == AttackStates.ProjectileAttack)
        {
            shoot_projectile();
            StartCoroutine(attack_cooldown(player_projectile_attack_cooldown));
        }
    }
Exemple #48
0
    /// <summary>
    /// Execute an attack.
    /// </summary>
    /// <param name="attack">What combo to execute.</param>
    void Attack(Combo attack, bool gun)
    {
        attackState = AttackStates.Attacking;
        myAnimator.SetBool("attacking", true);
        myAnimator.SetInteger("attackNum", attack.number);
        currentDamage = attack.damage;

        if (gun)
        {
            GunWeapon.Toggle(true, currentDamage);
            AudioSource.PlayClipAtPoint(shootSE, myTransform.position, __Game_Settings.main.seVolume);
        }
        else
        {
            SwordWeapon.Toggle(true, currentDamage);
            AudioSource.PlayClipAtPoint(slashLeftSE, myTransform.position, __Game_Settings.main.seVolume);
        }

        if (attack.isFinishingMove)
        {
            ComboExecuted(attack.name);
        }
    }
Exemple #49
0
    void Update()
    {
        //print("projectile Distance : " + projectileDistance);
        baseDistance = Vector2.Distance(transform.position, theBase.position);
        //projectileDistance = Vector2.Distance(transform.position, projectile.position);
        if (baseDistance > 500)
        {
            distanceSpeed = 1;
        }
        else if (baseDistance <= 500 && baseDistance > 300)
        {
            distanceSpeed = 1.5f;
        }
        else if (baseDistance <= 300 && baseDistance > 150)
        {
            distanceSpeed = 2f;
        }
        else if (baseDistance <= 150)
        {
            distanceSpeed = 2.5f;
        }

        switch (CurrentES)
        {
        case AttackStates.attackBase:
            //if (projectileDistance < 200) {
            //    CurrentES = AttackStates.evade;
            //}
            if (health > 1 || player.points >= 20)
            {
                AttackBase();
            }
            else
            {
                CurrentES = AttackStates.attackPlayer;
            }

            break;

        case AttackStates.attackPlayer:
            //if (projectileDistance < 200) {
            //    CurrentES = AttackStates.evade;
            //}
            if (health > 1 || player.points >= 20)
            {
                CurrentES = AttackStates.attackBase;
            }
            else
            {
                AttackPlayer();
            }
            break;
            //case AttackStates.evade:
            //    Evade();
            //    if (projectileDistance > 200 && health >= 1 || player.points >= 20) {
            //        CurrentES = AttackStates.attackBase;
            //    } else if (player.points < 20) {
            //        AttackPlayer();
            //    }
            //    break;
        }

        //if (player.health <= 2 || player.points >= 20) {
        //    transform.position = Vector2.MoveTowards(transform.position, theBase.position, speed * Time.deltaTime * endSpeed);
        //} else if (player.health <= 5 || player.points >= 10) {
        //    transform.position = Vector2.MoveTowards(transform.position, playerPos.position, speed * Time.deltaTime);
        //} else {
        //    transform.position = Vector2.MoveTowards(transform.position, theBase.position, speed * Time.deltaTime * startspeed);
        //}
    }
Exemple #50
0
    // Fonction qui gere l'attaque de l'ennemi
    void Attack()
    {
        switch (actStates)
        {
            case AttackStates.Wait:     /* L'ennemi est en etat d'attente */
                //Debug.Log("wait");
                destination = transform.position;
                isPaused = true;

                if (nextStates == AttackStates.Charge)
                {
                    StartCoroutine(ReadyToJump());
                }
                //transform.LookAt(_player.transform.position);
                timer += Time.deltaTime;
                if (timer > timeToAction)
                {
                    timer = 0;
                    isPaused = false;
                    actStates = nextStates;
                }
                break;

            case AttackStates.GetCloser:    /* L'ennemi se rapproche */
                //Debug.Log("get closer");
                destination = _player.transform.position;

                Collider[] targets = Physics.OverlapSphere(this.transform.position, distanceAttaque + Random.Range(-fourchette, fourchette));
                foreach (Collider target in targets)
                {
                    if (target.name == "Player")
                    {
                        nextStates = AttackStates.Charge;
                        actStates = AttackStates.Wait;
                    }
                }
                break;

            case AttackStates.Charge:    /* L'ennemi attaque si il peut */
                //Debug.Log("shoot");
                if (VisionOk())
                {
                    Charging(nbCharges);
                }

                if (!isCharging)
                {
                    nextStates = AttackStates.Move;
                    actStates = AttackStates.Wait;
                }
                break;

            case AttackStates.Move:
                //Debug.Log("Move");
                //Debug.Log(moving);

                if (!moving)
                {
                    Vector3 dir = _player.transform.position - transform.position;
                    float tmp = dir.z;
                    dir.z = -dir.x;
                    dir.x = tmp;

                    float halfchoice = Random.Range(0.0f, 1.0f);
                    if (halfchoice < 0.5f)
                    {
                        dir = -dir;
                    }

                    if (IsFree(transform.position + (dir.normalized * distMove)))
                    {
                        destination = transform.position + (dir.normalized * distMove);
                        moving = true;
                    }

                }

                if (Vector3.Distance(transform.position, destination) < 1.5f && moving)
                {
                    moving = false;
                    actStates = AttackStates.GetCloser;
                    dontLook = false;
                }
                break;

        }

        Dodge();
    }