コード例 #1
0
        public override void update(GameTime currentTime)
        {
            animation_time += currentTime.ElapsedGameTime.Milliseconds / 1000f;
            sound_timer    += currentTime.ElapsedGameTime.Milliseconds;

            if (sound_timer > 250f)
            {
                play_sound = true;
            }

            if (sound_alert && state == ChargerState.search && entity_found == null)
            {
                state       = ChargerState.alert;
                alert_timer = 0.0f;
            }

            if (state == ChargerState.dying)
            {
                velocity = Vector2.Zero;

                death = true;

                // may the programming gods have mercy on me hacking over this complicated state machine
                goto DeadSkipStates;
            }

            if (disable_movement == true)
            {
                disable_movement_time += currentTime.ElapsedGameTime.Milliseconds;

                if (disable_movement_time > 300)
                {
                    disable_movement_time = 0.0f;
                    disable_movement      = false;
                    velocity = Vector2.Zero;
                    state    = ChargerState.alert;
                }

                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("hurt");
            }
            else
            {
                switch (state)
                {
                case ChargerState.search:
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("idle");

                    change_direction_time += currentTime.ElapsedGameTime.Milliseconds;
                    //first if state is if enemy was knocked back by a enemy of a different type
                    if (enemy_found == false)
                    {
                        for (int i = 0; i < parentWorld.EntityList.Count; i++)
                        {
                            if (parentWorld.EntityList[i] == this || (GameCampaign.PlayerAllegiance < 0.3 && parentWorld.EntityList[i] is Player))
                            {
                                continue;
                            }
                            else if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false)
                            {
                                component.update(this, parentWorld.EntityList[i], currentTime, parentWorld);
                                if (enemy_found == true)
                                {
                                    entity_found = parentWorld.EntityList[i];
                                    break;
                                }
                            }
                        }
                    }

                    if (enemy_found)
                    {
                        state    = ChargerState.windUp;
                        velocity = Vector2.Zero;
                    }
                    else
                    {
                        if (change_direction_time > 5000)
                        {
                            switch (direction_facing)
                            {
                            case GlobalGameConstants.Direction.Right:
                                direction_facing = GlobalGameConstants.Direction.Down;
                                break;

                            case GlobalGameConstants.Direction.Left:
                                direction_facing = GlobalGameConstants.Direction.Up;
                                break;

                            case GlobalGameConstants.Direction.Up:
                                direction_facing = GlobalGameConstants.Direction.Right;
                                break;

                            default:
                                direction_facing = GlobalGameConstants.Direction.Left;
                                break;
                            }
                            change_direction_time = 0.0f;
                        }
                        entity_found = null;
                        sound_alert  = false;
                    }
                    break;

                case ChargerState.alert:
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("idle");

                    if (sound_alert && entity_found == null)
                    {
                        //if false then sound didn't hit a wall
                        if (!parentWorld.Map.soundInSight(this, sound_position))
                        {
                            directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("run");
                            alert_timer += currentTime.ElapsedGameTime.Milliseconds;
                            for (int i = 0; i < parentWorld.EntityList.Count; i++)
                            {
                                if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false)
                                {
                                    float distance = Vector2.Distance(CenterPoint, parentWorld.EntityList[i].CenterPoint);
                                    if (distance <= range_distance)
                                    {
                                        enemy_found    = true;
                                        entity_found   = parentWorld.EntityList[i];
                                        state          = ChargerState.windUp;
                                        animation_time = 0.0f;
                                        sound_alert    = false;
                                        alert_timer    = 0.0f;
                                        windup_timer   = 0.0f;
                                        animation_time = 0.0f;
                                        velocity       = Vector2.Zero;
                                        charge_timer   = 0.0f;
                                        break;
                                    }
                                }
                            }

                            if (alert_timer > 3000 || ((int)CenterPoint.X == (int)sound_position.X && (int)CenterPoint.Y == (int)sound_position.Y))
                            {
                                entity_found   = null;
                                enemy_found    = false;
                                sound_alert    = false;
                                state          = ChargerState.search;
                                velocity       = Vector2.Zero;
                                animation_time = 0.0f;
                                charge_timer   = 0.0f;
                                windup_timer   = 0.0f;
                                animation_time = 0.0f;
                            }
                        }
                        else
                        {
                            entity_found   = null;
                            enemy_found    = false;
                            sound_alert    = false;
                            state          = ChargerState.search;
                            velocity       = Vector2.Zero;
                            animation_time = 0.0f;
                            charge_timer   = 0.0f;
                            windup_timer   = 0.0f;
                            animation_time = 0.0f;
                        }
                    }
                    else if (entity_found != null)
                    {
                        sound_alert = false;
                        float distance = Vector2.Distance(CenterPoint, entity_found.CenterPoint);
                        if (parentWorld.Map.enemyWithinRange(entity_found, this, range_distance) && distance < range_distance && entity_found.Death == false)
                        {
                            state          = ChargerState.windUp;
                            animation_time = 0.0f;
                        }
                        else
                        {
                            entity_found   = null;
                            enemy_found    = false;
                            state          = ChargerState.search;
                            velocity       = Vector2.Zero;
                            animation_time = 0.0f;
                            charge_timer   = 0.0f;
                            windup_timer   = 0.0f;
                            animation_time = 0.0f;
                        }
                    }
                    break;

                case ChargerState.windUp:
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("windUp");
                    windup_timer += currentTime.ElapsedGameTime.Milliseconds;
                    angle         = (float)Math.Atan2(entity_found.CenterPoint.Y - CenterPoint.Y, entity_found.CenterPoint.X - CenterPoint.X);

                    if (windup_timer > 300)
                    {
                        animation_time = 0.0f;
                        state          = ChargerState.charge;
                        velocity       = new Vector2(8.0f * (float)(Math.Cos(angle)), 8.0f * (float)(Math.Sin(angle)));

                        charge_timer = 0.0f;
                    }
                    break;

                case ChargerState.charge:
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("charge");
                    charge_timer += currentTime.ElapsedGameTime.Milliseconds;
                    for (int i = 0; i < parentWorld.EntityList.Count; i++)
                    {
                        if (parentWorld.EntityList[i] == this)
                        {
                            continue;
                        }
                        if (hitTest(parentWorld.EntityList[i]))
                        {
                            if (play_sound)
                            {
                                AudioLib.playSoundEffect("chargerImpact");
                                sound_timer = 0.0f;
                                play_sound  = false;
                            }

                            Vector2 direction = parentWorld.EntityList[i].CenterPoint - CenterPoint;
                            parentWorld.EntityList[i].knockBack(direction, knockback_magnitude, enemy_damage);
                        }
                    }

                    if (charge_timer > 800)
                    {
                        if (entity_found.Death == true)
                        {
                            entity_found = null;
                        }
                        sound_alert    = false;
                        state          = ChargerState.alert;
                        velocity       = Vector2.Zero;
                        animation_time = 0.0f;
                        charge_timer   = 0.0f;
                        windup_timer   = 0.0f;
                        animation_time = 0.0f;
                        enemy_found    = false;
                    }
                    break;

                default:
                    break;
                }
            }

DeadSkipStates:
            Vector2 pos = new Vector2(position.X, position.Y);
            Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y);
            Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions);

            position.X = finalPos.X;
            position.Y = finalPos.Y;

            directionAnims[(int)direction_facing].Animation.Apply(directionAnims[(int)direction_facing].Skeleton, animation_time, state == ChargerState.dying ? false : true);

            if (enemy_life <= 0 && state != ChargerState.dying && death == false)
            {
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation(Game1.rand.Next() % 3 == 0 ? "die" : Game1.rand.Next() % 2 == 0 ? "die2" : "die3");
                death          = true;
                state          = ChargerState.dying;
                animation_time = 0;
                parentWorld.pushCoin(this);
            }
        }
コード例 #2
0
        public override void update(GameTime currentTime)
        {
            if (enemy_life <= 0 && death == false)
            {
                death                      = true;
                state                      = ChaseState.death;
                animation_time             = 0.0f;
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation(death_anim[(int)(Game1.rand.Next()) % 3]);

                parentWorld.pushCoin(this);
            }

            switch (state)
            {
            case ChaseState.search:
                change_direction_time     += currentTime.ElapsedGameTime.Milliseconds;
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("run");
                for (int i = 0; i < parentWorld.EntityList.Count; i++)
                {
                    if (parentWorld.EntityList[i] == this || (parentWorld.EntityList[i] is Player && GameCampaign.PlayerAllegiance < 0.3))
                    {
                        continue;
                    }

                    if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && !parentWorld.EntityList[i].Death)
                    {
                        component.update(this, parentWorld.EntityList[i], currentTime, parentWorld);
                        if (enemy_found)
                        {
                            component      = chaseComponent;
                            state          = ChaseState.chase;
                            animation_time = 0.0f;
                            chase_target   = parentWorld.EntityList[i];
                            break;
                        }
                    }
                }
                break;

            case ChaseState.chase:
                //checks to see if player was hit
                //wind up

                //component won't update when the swing is in effect
                float distance = Vector2.Distance(chase_target.CenterPoint, CenterPoint);
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("chase");
                if (distance > 300.0f || chase_target.Death)
                {
                    state          = ChaseState.search;
                    component      = searchComponent;
                    enemy_found    = false;
                    wind_anim      = 0.0f;
                    animation_time = 0.0f;
                }
                else
                {
                    component.update(this, chase_target, currentTime, parentWorld);
                    if (distance < 64.0f)
                    {
                        current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("windUp");
                        state          = ChaseState.windUp;
                        wind_anim      = 0.0f;
                        animation_time = 0.0f;
                    }
                }
                break;

            case ChaseState.windUp:
                wind_anim += currentTime.ElapsedGameTime.Milliseconds;
                //animation_time = 0.0f;

                velocity = Vector2.Zero;
                switch (direction_facing)
                {
                case GlobalGameConstants.Direction.Right:
                    sword_position.X = position.X + dimensions.X;
                    sword_position.Y = position.Y;
                    break;

                case GlobalGameConstants.Direction.Left:
                    sword_position.X = position.X - sword_hitbox.X;
                    sword_position.Y = position.Y;
                    break;

                case GlobalGameConstants.Direction.Up:
                    sword_position.Y = position.Y - sword_hitbox.Y;
                    sword_position.X = CenterPoint.X - sword_hitbox.X / 2;
                    break;

                default:
                    sword_position.Y = CenterPoint.Y + dimensions.Y / 2;
                    sword_position.X = CenterPoint.X - sword_hitbox.X / 2;
                    break;
                }
                if (wind_anim > 300)
                {
                    state          = ChaseState.attack;
                    wind_anim      = 0.0f;
                    animation_time = 0.0f;
                }
                break;

            case ChaseState.attack:
                wind_anim += currentTime.ElapsedGameTime.Milliseconds;
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("attack");
                if (swordSlashHitTest(chase_target))
                {
                    Vector2 direction = chase_target.CenterPoint - CenterPoint;

                    if (play_sound)
                    {
                        AudioLib.playSoundEffect("swordHit");
                        play_sound = false;
                    }
                    chase_target.knockBack(direction, knockback_magnitude, enemy_damage);
                }
                else
                {
                    if (play_sound)
                    {
                        AudioLib.playSoundEffect("testSword");
                        play_sound = false;
                    }
                }
                if (wind_anim > 500)
                {
                    play_sound                 = true;
                    dimensions                 = new Vector2(48f, 48f);
                    wind_anim                  = 0.0f;
                    animation_time             = 0.0f;
                    state                      = ChaseState.chase;
                    current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("chase");
                }
                break;

            case ChaseState.knockback:
                if (death == false)
                {
                    disable_movement_time     += currentTime.ElapsedGameTime.Milliseconds;
                    current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("hurt");
                    if (disable_movement_time > 300)
                    {
                        state                 = ChaseState.search;
                        velocity              = Vector2.Zero;
                        component             = searchComponent;
                        disable_movement      = false;
                        disable_movement_time = 0;
                        animation_time        = 0.0f;
                    }
                }
                break;

            case ChaseState.death:
                velocity = Vector2.Zero;
                break;

            default:
                break;
            }

            Vector2 pos = new Vector2(position.X, position.Y);

            Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y);
            Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions);

            position.X = finalPos.X;
            position.Y = finalPos.Y;

            animation_time += currentTime.ElapsedGameTime.Milliseconds / 1000f;

            //decides if the animation loops or not
            current_skeleton.Animation.Apply(current_skeleton.Skeleton, animation_time, (wind_anim == 0 && !death) ? true : false);
        }
コード例 #3
0
        public override void update(GameTime currentTime)
        {
            change_direction_time += currentTime.ElapsedGameTime.Milliseconds;

            if (disable_movement == true)
            {
                disable_movement_time     += currentTime.ElapsedGameTime.Milliseconds;
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                if (disable_movement_time > 300)
                {
                    velocity              = Vector2.Zero;
                    disable_movement      = false;
                    disable_movement_time = 0;
                }
            }
            else
            {
                switch (state)
                {
                case EnemyState.Idle:
                    current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                    velocity = Vector2.Zero;
                    foreach (Entity en in parentWorld.EntityList)
                    {
                        if (en == this)
                        {
                            continue;
                        }
                        else if (en is Player)
                        {
                            component.update(this, en, currentTime, parentWorld);
                            break;
                        }
                    }
                    if (enemy_found)
                    {
                        component             = new Chase();
                        state                 = EnemyState.Chase;
                        change_direction_time = 0.0f;
                        animation_time        = 0.0f;
                    }
                    else
                    {
                        if (change_direction_time > 5000)
                        {
                            switch (direction_facing)
                            {
                            case GlobalGameConstants.Direction.Right:
                                direction_facing = GlobalGameConstants.Direction.Down;
                                break;

                            case GlobalGameConstants.Direction.Left:
                                direction_facing = GlobalGameConstants.Direction.Up;
                                break;

                            case GlobalGameConstants.Direction.Up:
                                direction_facing = GlobalGameConstants.Direction.Right;
                                break;

                            default:
                                direction_facing = GlobalGameConstants.Direction.Left;
                                break;
                            }
                            change_direction_time = 0.0f;
                        }
                    }
                    break;

                case EnemyState.Chase:
                    current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("run");
                    distance_from_origin       = Vector2.Distance(CenterPoint, original_position);
                    return_timer += currentTime.ElapsedGameTime.Milliseconds;
                    foreach (Entity en in parentWorld.EntityList)
                    {
                        if (en == this)
                        {
                            continue;
                        }
                        else if (en is Player)
                        {
                            distance = (float)Math.Sqrt(Math.Pow((double)(en.Position.X - position.X), 2.0) + Math.Pow((double)(en.Position.Y - position.Y), 2.0));
                            if (hitTest(en))
                            {
                                Vector2 direction = en.CenterPoint - CenterPoint;
                                en.knockBack(direction, knockback_magnitude, enemy_damage);
                            }
                            else if (distance > 300 || Math.Abs(distance_from_origin) > 1500)
                            {
                                //returns to original location
                                state = EnemyState.Moving;
                            }
                            else
                            {
                                Vector2 old_velocity = velocity;
                                component.update(this, en, currentTime, parentWorld);
                                if (old_velocity != velocity)
                                {
                                }
                            }
                        }
                    }
                    break;

                default:
                    return_timer += currentTime.ElapsedGameTime.Milliseconds;
                    if (return_timer > 2500)
                    {
                        position     = original_position;
                        velocity     = Vector2.Zero;
                        state        = EnemyState.Idle;
                        component    = new IdleSearch();
                        return_timer = 0.0f;
                    }
                    else
                    {
                        Vector2 direction = original_position - CenterPoint;
                        velocity = new Vector2(direction.X / 100, direction.Y / 100);
                    }
                    break;
                }
            }

            if (enemy_life <= 0)
            {
                remove_from_list = true;
            }

            Vector2 pos      = new Vector2(position.X, position.Y);
            Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y);
            Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions);

            position.X      = finalPos.X;
            position.Y      = finalPos.Y;
            animation_time += currentTime.ElapsedGameTime.Milliseconds / 1000f;
            current_skeleton.Animation.Apply(current_skeleton.Skeleton, animation_time, true);
        }
コード例 #4
0
        public override void update(GameTime currentTime)
        {
            if (sound_alert && state == mutantBallState.Search && entity_found == null && !death)
            {
                state       = mutantBallState.Alert;
                alert_timer = 0.0f;
            }

            if (enemy_life <= 0 && !death)
            {
                velocity = Vector2.Zero;
                death    = true;
                AudioLib.playSoundEffect("alienChaserDie");
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation(deathAnim[Game1.rand.Next() % 3]);
                state          = mutantBallState.Death;
                animation_time = 0.0f;
                parentWorld.pushCoin(this);
            }
            switch (state)
            {
            case mutantBallState.Search:
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                change_direction_time     += currentTime.ElapsedGameTime.Milliseconds;
                if (!enemy_found)
                {
                    for (int i = 0; i < parentWorld.EntityList.Count; i++)
                    {
                        if (parentWorld.EntityList[i] == this)
                        {
                            continue;
                        }
                        else if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType)
                        {
                            component.update(this, parentWorld.EntityList[i], currentTime, parentWorld);
                            if (enemy_found)
                            {
                                entity_found = parentWorld.EntityList[i];
                                break;
                            }
                        }
                    }
                }
                if (enemy_found)
                {
                    state          = mutantBallState.Agressive;
                    velocity       = Vector2.Zero;
                    animation_time = 0.0f;
                }
                else
                {
                    if (change_direction_time > 5000)
                    {
                        switch (direction_facing)
                        {
                        case GlobalGameConstants.Direction.Right:
                            direction_facing = GlobalGameConstants.Direction.Down;
                            break;

                        case GlobalGameConstants.Direction.Left:
                            direction_facing = GlobalGameConstants.Direction.Up;
                            break;

                        case GlobalGameConstants.Direction.Up:
                            direction_facing = GlobalGameConstants.Direction.Right;
                            break;

                        default:
                            direction_facing = GlobalGameConstants.Direction.Left;
                            break;
                        }
                        change_direction_time = 0.0f;
                    }
                }

                switch (direction_facing)
                {
                case GlobalGameConstants.Direction.Right:
                    current_skeleton = walk_right;
                    break;

                case GlobalGameConstants.Direction.Left:
                    current_skeleton = walk_right;
                    break;

                case GlobalGameConstants.Direction.Up:
                    current_skeleton = walk_up;
                    break;

                default:
                    current_skeleton = walk_down;
                    break;
                }
                break;

            /*case mutantBallState.Alert:
             *  if (sound_alert && entity_found == null)
             *  {
             *      //if false then sound didn't hit a wall
             *      if (!parentWorld.Map.soundInSight(this, sound_position))
             *      {
             *          current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("run");
             *          alert_timer += currentTime.ElapsedGameTime.Milliseconds;
             *          for (int i = 0; i < parentWorld.EntityList.Count; i++)
             *          {
             *              if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false)
             *              {
             *                  float distance = Vector2.Distance(CenterPoint, parentWorld.EntityList[i].CenterPoint);
             *                  if (distance <= range_distance)
             *                  {
             *                      enemy_found = true;
             *                      entity_found = parentWorld.EntityList[i];
             *                      state = mutantBallState.Search;
             *                      animation_time = 0.0f;
             *                      sound_alert = false;
             *                      animation_time = 0.0f;
             *                      velocity = Vector2.Zero;
             *                      agressive_timer = 0.0f;
             *                      break;
             *                  }
             *              }
             *          }
             *
             *          if (alert_timer > 3000 || ((int)CenterPoint.X == (int)sound_position.X && (int)CenterPoint.Y == (int)sound_position.Y))
             *          {
             *              entity_found = null;
             *              enemy_found = false;
             *              sound_alert = false;
             *              state = mutantBallState.Search;
             *              velocity = Vector2.Zero;
             *              animation_time = 0.0f;
             *              agressive_timer = 0.0f;
             *              animation_time = 0.0f;
             *          }
             *      }
             *      else
             *      {
             *          entity_found = null;
             *          enemy_found = false;
             *          sound_alert = false;
             *          state = mutantBallState.Search;
             *          velocity = Vector2.Zero;
             *          animation_time = 0.0f;
             *          agressive_timer = 0.0f;
             *          animation_time = 0.0f;
             *      }
             *  }
             *  else if (entity_found != null)
             *  {
             *      sound_alert = false;
             *      float distance = Vector2.Distance(CenterPoint, entity_found.CenterPoint);
             *      if (parentWorld.Map.enemyWithinRange(entity_found, this, range_distance) && distance < range_distance)
             *      {
             *          state = mutantBallState.Search;
             *          animation_time = 0.0f;
             *      }
             *      else
             *      {
             *          entity_found = null;
             *          enemy_found = false;
             *          state = mutantBallState.Search;
             *          velocity = Vector2.Zero;
             *          animation_time = 0.0f;
             *          agressive_timer = 0.0f;
             *          animation_time = 0.0f;
             *      }
             *  }
             *  break;*/
            case mutantBallState.Agressive:
                agressive_timer           += currentTime.ElapsedGameTime.Milliseconds;
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("attack");
                sound_timer += currentTime.ElapsedGameTime.Milliseconds;

                if (sound_timer > 30)
                {
                    play_sound = true;
                }

                float angle_from_entity = (float)Math.Atan2(entity_found.CenterPoint.Y - CenterPoint.Y, entity_found.CenterPoint.X - CenterPoint.X);

                switch (direction_facing)
                {
                case GlobalGameConstants.Direction.Right:
                    if (angle_from_entity > Math.PI / 4)
                    {
                        direction_facing = GlobalGameConstants.Direction.Down;
                        current_skeleton = walk_down;
                    }
                    else if (angle_from_entity < -1 * Math.PI / 4)
                    {
                        direction_facing = GlobalGameConstants.Direction.Up;
                        current_skeleton = walk_up;
                    }
                    break;

                case GlobalGameConstants.Direction.Left:
                    if (angle_from_entity > -3 * Math.PI / 4 && angle_from_entity < 0)
                    {
                        direction_facing = GlobalGameConstants.Direction.Up;
                        current_skeleton = walk_up;
                    }
                    else if (angle_from_entity < 3 * Math.PI / 4 && angle_from_entity > 0)
                    {
                        direction_facing = GlobalGameConstants.Direction.Down;
                        current_skeleton = walk_down;
                    }
                    break;

                case GlobalGameConstants.Direction.Up:
                    if (angle_from_entity > -1 * Math.PI / 4)
                    {
                        direction_facing = GlobalGameConstants.Direction.Right;
                        current_skeleton = walk_right;
                    }
                    else if (angle_from_entity < -3 * Math.PI / 4)
                    {
                        direction_facing = GlobalGameConstants.Direction.Left;
                        current_skeleton = walk_right;
                    }
                    break;

                default:
                    if (angle_from_entity > 3 * Math.PI / 4)
                    {
                        direction_facing = GlobalGameConstants.Direction.Left;
                        current_skeleton = walk_right;
                    }
                    else if (angle_from_entity < Math.PI / 4)
                    {
                        direction_facing = GlobalGameConstants.Direction.Right;
                        current_skeleton = walk_right;
                    }
                    break;
                }

                velocity = new Vector2((float)Math.Cos(angle_from_entity), (float)Math.Sin(angle_from_entity));

                angle += 0.1f;
                if (angle >= (float)(2 * Math.PI))
                {
                    angle = 0;
                }

                float temp_radius = 0.0f;

                while (temp_radius <= radius)
                {
                    ball_coordinate.X = CenterPoint.X + temp_radius * (float)(Math.Cos(angle));
                    ball_coordinate.Y = CenterPoint.Y + temp_radius * (float)(Math.Sin(angle));

                    for (int i = 0; i < parentWorld.EntityList.Count; i++)
                    {
                        if (parentWorld.EntityList[i] == this)
                        {
                            continue;
                        }
                        else if (parentWorld.EntityList[i].Death == false && hitTestBall(parentWorld.EntityList[i], ball_coordinate.X, ball_coordinate.Y))
                        {
                            if (play_sound)
                            {
                                AudioLib.playSoundEffect("chargerImpact");
                                play_sound  = false;
                                sound_timer = 0.0f;
                            }
                            float   distance  = Vector2.Distance(ball_coordinate, CenterPoint);
                            Vector2 direction = new Vector2(distance * (float)(Math.Cos(angle)), distance * (float)(Math.Sin(angle)));

                            float temp_knockback_magnitude = knockback_magnitude / (radius / temp_radius);
                            parentWorld.EntityList[i].knockBack(direction, temp_knockback_magnitude, enemy_damage, this);
                        }
                    }
                    temp_radius++;
                }

                if (agressive_timer > 4000)
                {
                    state           = mutantBallState.Search;
                    velocity        = Vector2.Zero;
                    agressive_timer = 0.0f;
                    enemy_found     = false;
                    entity_found    = null;
                    animation_time  = 0.0f;
                }
                break;

            case mutantBallState.KnockBack:
                disable_movement_time     += currentTime.ElapsedGameTime.Milliseconds;
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("hurt");
                if (disable_movement_time > 300)
                {
                    state = mutantBallState.Search;
                    disable_movement_time = 0.0f;
                    velocity       = Vector2.Zero;
                    animation_time = 0.0f;
                }
                break;

            case mutantBallState.Death:
                velocity = Vector2.Zero;
                break;

            default:
                break;
            }
            Vector2 pos      = new Vector2(position.X, position.Y);
            Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y);
            Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions);

            position.X = finalPos.X;
            position.Y = finalPos.Y;

            animation_time += currentTime.ElapsedGameTime.Milliseconds / 1000f;
            current_skeleton.Animation.Apply(current_skeleton.Skeleton, animation_time, (state == mutantBallState.Death)? false:true);
        }
コード例 #5
0
        public override void update(GameTime currentTime)
        {
            if ((!death && enemy_life <= 0))
            {
                death = true;
                state = ChainState.Death;
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation(die_animations[Game1.rand.Next() % 3]);
                animation_time = 0.0f;
                parentWorld.pushCoin(this);
            }

            switch (state)
            {
            case ChainState.Moving:
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("run");
                change_direction_time += currentTime.ElapsedGameTime.Milliseconds;
                if (enemy_found == false)
                {
                    for (int i = 0; i < parentWorld.EntityList.Count(); i++)
                    {
                        if (parentWorld.EntityList[i] == this || (parentWorld.EntityList[i] is Player && GameCampaign.PlayerAllegiance < 0.3))
                        {
                            continue;
                        }
                        else if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false)
                        {
                            component.update(this, parentWorld.EntityList[i], currentTime, parentWorld);
                            if (enemy_found)
                            {
                                target = parentWorld.EntityList[i];
                                break;
                            }
                        }
                    }
                }

                if (enemy_found)
                {
                    state          = ChainState.WindUp;
                    windup_timer   = 0.0f;
                    velocity       = Vector2.Zero;
                    animation_time = 0.0f;
                }

                Vector2 pos      = new Vector2(position.X, position.Y);
                Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y);
                Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions);
                position.X = finalPos.X;
                position.Y = finalPos.Y;
                break;

            case ChainState.WindUp:
                windup_timer += currentTime.ElapsedGameTime.Milliseconds;
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("windUp");
                if (windup_timer > 670)
                {
                    state    = ChainState.Throw;
                    angle    = (float)Math.Atan2(target.CenterPoint.Y - directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldY, target.CenterPoint.X - directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldX);
                    distance = Vector2.Distance(new Vector2(directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldX, directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldY), target.CenterPoint);

                    chain_position_start = new Vector2(directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldX, directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldY);

                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Right:
                        chain_velocity = new Vector2((float)(distance * Math.Cos(angle) * 0.08f), (float)(distance * Math.Sin(angle)) * 0.08f);
                        chain_position = new Vector2(directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldX, directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldY);
                        chain_speed    = chain_velocity.X;
                        break;

                    case GlobalGameConstants.Direction.Left:
                        chain_velocity = new Vector2((float)(distance * Math.Cos(angle)) * 0.08f, (float)(distance * Math.Sin(angle)) * 0.08f);
                        chain_position = new Vector2(directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldX, directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldY);
                        chain_speed    = Math.Abs(chain_velocity.X);
                        break;

                    case GlobalGameConstants.Direction.Up:
                        chain_velocity = new Vector2((float)(distance * Math.Cos(angle) * 0.08f), (float)(distance * Math.Sin(angle)) * 0.08f);
                        chain_position = new Vector2(directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldX, directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldY);
                        chain_speed    = Math.Abs(chain_velocity.Y);
                        break;

                    default:
                        chain_velocity = new Vector2((float)(distance * Math.Cos(angle) * 0.08f), (float)(distance * Math.Sin(angle)) * 0.08f);
                        chain_position = new Vector2(directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldX, directionAnims[(int)direction_facing].Skeleton.FindBone("rHand").WorldY);
                        chain_speed    = Math.Abs(chain_velocity.Y);
                        break;
                    }
                    windup_timer   = 0.0f;
                    animation_time = 0.0f;
                }
                break;

            case ChainState.Throw:
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("throw");
                chain_distance += chain_speed;
                chain_position += chain_velocity;
                if (chain_distance >= max_chain_distance || parentWorld.Map.hitTestWall(chain_position))
                {
                    state          = ChainState.Pull;
                    chain_velocity = -1 * chain_velocity;
                }

                //checks to see if chain hits the player
                if (hitTestChain(target, chain_position.X, chain_position.Y))
                {
                    en_chained = target;
                    target.Disable_Movement      = true;
                    target.Disable_Movement_Time = 0.0f;
                    target.Velocity = Vector2.Zero;
                    state           = ChainState.Pull;
                    chain_velocity  = -1 * chain_velocity;
                    animation_time  = 0.0f;
                }
                break;

            //need to work on pull
            case ChainState.Pull:
                if (chain_distance > 5)
                {
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("pull");
                    chain_position += chain_velocity;
                    chain_distance -= chain_speed;
                    if (en_chained != null)
                    {
                        en_chained.Position        += chain_velocity;
                        en_chained.Disable_Movement = true;
                    }
                }
                else
                {
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("attack");
                    if (en_chained != null)
                    {
                        AudioLib.playSoundEffect("chargerImpact");
                        Vector2 direction = en_chained.CenterPoint - CenterPoint;
                        en_chained.Disable_Movement_Time = 0.0f;
                        en_chained.Disable_Movement      = false;
                        en_chained.knockBack(direction, knockback_magnitude, enemy_damage, this);
                    }
                    state       = ChainState.Neutral;
                    en_chained  = null;
                    enemy_found = false;
                }
                break;

            case ChainState.knockBack:
                disable_movement_time += currentTime.ElapsedGameTime.Milliseconds;
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("hurt");
                if (disable_movement_time > 300)
                {
                    disable_movement = false;
                    state            = ChainState.Moving;
                    chain_distance   = 0.0f;
                }
                break;

            case ChainState.Death:
                dimensions = new Vector2(10, 10);
                velocity   = Vector2.Zero;
                break;

            default:
                state = ChainState.Moving;
                break;
            }
            animation_time += currentTime.ElapsedGameTime.Milliseconds / 1000f;
            directionAnims[(int)direction_facing].Animation.Apply(directionAnims[(int)direction_facing].Skeleton, animation_time, (state == ChainState.Moving || state == ChainState.Pull || state == ChainState.knockBack)?true:false);
        }