Beispiel #1
0
 private void Awake()
 {
     alertState   = new alertState(this);
     attackState  = new attackState(this);
     patrolState  = new patrolState(this);
     chaseState   = new chaseState(this);
     navMeshAgent = GetComponent <NavMeshAgent>();
 }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        Debug.Log(currState);


        // NOT ATTACKING STATE
        if (currState == attackState.notAttacking)
        {
            Weapon.position = WeaponPointerIdle.position;
            if (hasWeapon && Input.GetMouseButtonDown(0))
            {
                currState = attackState.beginSwing;
                timer     = 0.0f;
            }
        }

        // BEGIN SWING STATE
        else if (currState == attackState.beginSwing)
        {
            timer          += Time.deltaTime * swingSpeed;
            Weapon.position = Vector3.Lerp(WeaponPointerIdle.position, WeaponPointerSwing.position, timer);
            ///Weapon.rotation = Quaternion.Lerp(WeaponPointer.rotation, AnglePointer.rotation, timer);
            if (timer >= 1)
            {
                Weapon.position = WeaponPointerSwing.position;
                ///Weapon.rotation = AnglePointer.rotation;
                currState = attackState.midSwing;
                timer     = 0.0f;
            }
        }

        // MID SWING STATE
        else if (currState == attackState.midSwing)
        {
            timer          += Time.deltaTime * attackTime;
            Weapon.position = WeaponPointerSwing.position;
            if (timer >= 1)
            {
                currState = attackState.endSwing;
                timer     = 0.0f;
            }
        }

        // END SWING STATE
        else if (currState == attackState.endSwing)
        {
            timer          += Time.deltaTime * swingSpeed;
            Weapon.position = Vector3.Lerp(WeaponPointerSwing.position, WeaponPointerIdle.position, timer);
            ///Weapon.rotation = Quaternion.Lerp(AnglePointer.rotation, WeaponPointer.rotation, timer);
            if (timer >= 1)
            {
                Weapon.position = WeaponPointerIdle.position;
                ///Weapon.rotation = WeaponPointer.rotation;
                currState = attackState.notAttacking;
                timer     = 0.0f;
            }
        }
    }
Beispiel #3
0
    // Use this for initialization
    void Start()
    {
        hasWeapon = false;
        currState = attackState.notAttacking;
        timer     = 0.0f;

        Weapon.position = WeaponPointerIdle.position;
        ///Weapon.rotation = WeaponPointer.rotation;
    }
Beispiel #4
0
    private attackState()
    {
        if (_instance != null)
        {
            return; //Simply return if there is already an instance of attack
        }

        _instance = this; //set instance to this instance if there isn't already an instance
    }
Beispiel #5
0
        public Player(Dictionary <string, Animation> animations) : base(animations)
        {
            _animations       = animations;
            _animationManager = new AnimationManager(_animations.First().Value);
            speed             = 3f;
            health            = 4;
            _fireballs        = new List <Fireball>();

            myAttackState = attackState.NotAttacking;
        }
Beispiel #6
0
 // Update is called once per frame
 void Update()
 {
     if (AttackState == attackState.chase)
     {
         Chase(GameManager.Instance.Players[0]);
         if (health.CurrentHealth <= 3)
         {
             AttackState = attackState.flee;
         }
     }
     else if (AttackState == attackState.flee)
     {
         Flee(GameManager.Instance.Players[0]);
         if (health.CurrentHealth > 3)
         {
             AttackState = attackState.flee;
         }
     }
     else
     {
         Debug.LogWarning("[AIChaseAndFleeController] unhandled state in Update method");
     }
 }
Beispiel #7
0
        public void SetAttackStatus()
        {
            switch (myAttackState)
            {
            case attackState.NotAttacking:
                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    myAttackState = attackState.Attacking;
                    if (poweredUp)
                    {
                        switch (Direction)
                        {
                        case "N":
                            _fireballs.Add(new Fireball(_fireballTextures[2], "N", new Vector2(Position.X + 15, Position.Y - 30)));
                            break;

                        case "S":
                            _fireballs.Add(new Fireball(_fireballTextures[3], "S", new Vector2(Position.X + 15, Position.Y + 50)));
                            break;

                        case "W":
                            _fireballs.Add(new Fireball(_fireballTextures[0], "W", new Vector2(Position.X - 10, Position.Y + 15)));
                            break;

                        case "E":
                            _fireballs.Add(new Fireball(_fireballTextures[1], "E", new Vector2(Position.X + 50, Position.Y + 15)));
                            break;
                        }
                    }
                }
                break;

            case attackState.Attacking:
                if (_animationManager.getCurrentFrame() == 3)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.Space))
                    {
                        myAttackState = attackState.AttackHeldDown;
                    }
                    if (Keyboard.GetState().IsKeyUp(Keys.Space))
                    {
                        myAttackState = attackState.NotAttacking;
                        switch (Direction)
                        {
                        case "N":
                            _animationManager.Play(_animations["WalkUp"]);
                            break;

                        case "S":
                            _animationManager.Play(_animations["WalkDown"]);
                            break;

                        case "W":
                            _animationManager.Play(_animations["WalkLeft"]);
                            break;

                        case "E":
                            _animationManager.Play(_animations["WalkRight"]);
                            break;
                        }
                    }
                }
                break;

            case attackState.AttackHeldDown:
                if (Keyboard.GetState().IsKeyUp(Keys.Space))
                {
                    myAttackState = attackState.AttackReleased;
                }
                break;

            case attackState.AttackReleased:
                if (Keyboard.GetState().IsKeyUp(Keys.Space))
                {
                    myAttackState = attackState.NotAttacking;
                }
                break;
            }
        }
Beispiel #8
0
    public void RunMain(ref Snake snake, ref Bird firebire, ref Venom venom, ref Fire fire, ref Image venomimg, ref Image fireimg)
    {
        switch (currentState)
        {
        case attackState.attackState_bird:
        {
            currentTime += Time.deltaTime;
            if (currentTime <= 3.0f)
            {
                fire.image.color  = new Color(1, 1, 1, 1.0f);                                              //火出现
                venom.image.color = new Color(1, 1, 1, 0.0f);                                              //毒液开始不存在
                harmsnake.color   = new Color(1, 1, 1, 0.0f);                                              //开始蛇没有受伤,所以不显示
                fire.image.rectTransform.position -= new Vector3(Time.deltaTime * fire.speed, 0.0f, 0.0f); //火移动
            }
            if (currentTime > 3.0f)
            {
                fire.image.color = new Color(1, 1, 1, 0.0f); //火消失
                if (Random.Range(0, 100) <= 30)              //机率为30%
                {
                    snake.blood     = snake.blood - firebird.burst;
                    harmsnake.text  = "-" + firebird.burst;
                    harmsnake.color = new Color(1, 1, 1, 1.0f);
                }
                else
                {
                    snake.blood     = snake.blood - firebird.attack;
                    harmsnake.text  = "-" + firebird.attack;
                    harmsnake.color = new Color(1, 1, 1, 1.0f);
                }
                numText1.text = snake.blood.ToString();
                currentState  = attackState.attackState_snake;
                currentTime   = 0.0f;
                fire.image.rectTransform.localPosition = new Vector3(128.0f, 33.0f, 0.0f);       //火回到原来的地方
                Debug.Log("换蛇进行攻击" + snake.blood);
            }
        }
        break;

        case attackState.attackState_snake:
        {
            currentTime += Time.deltaTime;
            if (currentTime <= 3.0f)
            {
                venom.image.color = new Color(1, 1, 1, 1.0f);                                                //毒液出现
                venom.image.rectTransform.position += new Vector3(Time.deltaTime * venom.speed, 0.0f, 0.0f); //毒液移动
                harmbird.color = new Color(1, 1, 1, 0.0f);                                                   //开始鸟没有受伤,所以不显示
            }
            if (currentTime > 3.0f)
            {
                venom.image.color = new Color(1, 1, 1, 0.0f); //毒液消失
                if (Random.Range(0, 100) <= 50)               //机率为50%
                {
                    firebird.blood = firebird.blood - snake.burst;
                    harmbird.text  = "-" + snake.burst;
                    harmbird.color = new Color(1, 1, 1, 1.0f);
                }
                else
                {
                    firebird.blood = firebird.blood - snake.attack;
                    harmbird.text  = "-" + snake.attack;
                    harmbird.color = new Color(1, 1, 1, 1.0f);
                }
                numText2.text = firebird.blood.ToString();
                currentState  = attackState.attackState_bird;
                currentTime   = 0.0f;
                venom.image.rectTransform.localPosition = new Vector3(29.0f, -12.0f, 0.0f);         //毒液回到原来的地方
                Debug.Log("换火鸟进行攻击" + firebird.blood);
            }
        }
        break;
        }
    }