Пример #1
0
    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            MechState mechStateHandle = other.transform.parent.GetComponent <MechState>();

            switch (AreaType)
            {
            case DmgAreaType.SingleBurst:
                /* do nothing */
                break;

            case DmgAreaType.Continous:
                if (Dmg_Timer > 0f)
                {
                    Dmg_Timer -= Time.deltaTime;
                }
                else
                {
                    Dmg_Timer = damage_interval;
                    ApplyDamage(mechStateHandle);
                }
                break;

            default:
                Debug.Log(" area type not handled (2)");
                break;
            }
        }
    }
Пример #2
0
        public GuardMech(LevelState parentWorld, float initial_x, float initial_y)
        {
            position       = new Vector2(initial_x, initial_y);
            melee_position = Vector2.Zero;
            dimensions     = new Vector2(96, 120);
            velocity       = new Vector2(0.8f, 0.0f);
            flame_position = Vector2.Zero;

            windup_timer = 0.0f;
            angle        = 0.0f;
            turret_angle = angle;

            enemy_life                      = 75;
            disable_movement                = false;
            disable_movement_time           = 0.0f;
            enemy_found                     = false;
            change_direction_time           = 0.0f;
            this.parentWorld                = parentWorld;
            enemy_type                      = EnemyType.Guard;
            change_direction_time_threshold = 3000.0f;
            direction_facing                = GlobalGameConstants.Direction.Right;

            prob_item_drop    = 0.6;
            number_drop_items = 5;

            component                = new MoveSearch();
            mech_state               = MechState.Moving;
            enemy_type               = EnemyType.Guard;
            velocity_speed           = 3.0f;
            entity_found             = null;
            death                    = false;
            tank_hull_animation_time = 0.0f;
            explode_timer            = 0.0f;
            rocket_angle             = 0.0f;

            grenade = new Grenades(Vector2.Zero, 0.0f);

            walk_down                       = AnimationLib.loadNewAnimationSet("tankTurret");
            current_skeleton                = walk_down;
            current_skeleton.Animation      = current_skeleton.Skeleton.Data.FindAnimation("idle");
            current_skeleton.Skeleton.FlipX = false;
            animation_time                  = 0.0f;
            range_distance                  = 600.0f;

            tankAnim           = AnimationLib.getFrameAnimationSet("tank");
            tankDeadAnim       = AnimationLib.getFrameAnimationSet("tankDead");
            plasmaExplode      = AnimationLib.getFrameAnimationSet("plasmaExplodeLong");
            tankTurretDeadAnim = AnimationLib.getFrameAnimationSet("tankTurretDead");
            rocketProjectile   = AnimationLib.getFrameAnimationSet("rocketProjectile");
        }
Пример #3
0
   void Awake()
   {
      Proto = GetComponent<ProtoMech>();
      Controller = GetComponent<MechController>();
      Weapons = GetComponentsInChildren<Weapon>();
      if (Weapons.Length != 2)
      {
         Debug.LogWarning("Found more or less than 2 weapons on mech.");
      }

      // Assign Each Weapon a unique Index to facility communications between
      // the Mech and its weapons
      for (int weapIdx = 0; weapIdx < Weapons.Length; weapIdx++)
         Weapons[weapIdx].WeaponIndex = weapIdx;

      if (isServer)
      {
         CurrentState = MechState.Inactive;
      }
   }
Пример #4
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            MechState mechStateHandle = other.transform.parent.GetComponent <MechState>();

            switch (AreaType)
            {
            case DmgAreaType.SingleBurst:
            case DmgAreaType.Continous:
                Dmg_Timer = damage_interval;
                ApplyDamage(mechStateHandle);
                break;

            default:
                Debug.Log(" area type not handled (1)");
                break;
            }
        }
    }
Пример #5
0
   public void SetState(MechState newState)
   {
      // If an individual state wants to recursively move to another state, we set tha flag, the next state, and do so.
      MechState nextState = newState;
      bool recurse = false;

      // Any Attempt to set a state that is already active is thrown out
      if (newState == CurrentState)
         return;

      #if DEBUG_MECH
         Debug.LogFormat("Mech {0} setting State: {1}", netId.ToString(), newState);
      #endif
      switch(newState)
      {
         case MechState.Spawning:
            Debug.LogFormat("Mech {0} has Spawned!", netId.ToString());
            recurse = true;
            nextState = MechState.Alive;
            break;
         case MechState.Alive:
            break;
         case MechState.Dying:
            Debug.LogFormat("Mech {0} is Dying!", netId.ToString());
            // And Play Death Effects on the client
            RpcActivateDeathEffect();
            // In 5 seconds, really die
            Invoke("SetDead", 5.0f);
            break;
         case MechState.Dead:
            // Eventually we probably want to destroy this object here. But for now I think it's fun to just leave the mech on the battlefield.
            Respawn();
            break;
         default:
            Debug.LogWarning("Unhandled State: " + newState);
            break;
      }
      // Set Current State
      CurrentState = newState;

      // And if we're setting state again, do so!
      if (recurse)
         SetState(nextState);

   }
Пример #6
0
    void ApplyDamage(MechState Target)
    {
        MechDamage temp_BaseDamage = new MechDamage(TypeOfDamage, DamageLevel);

        Target.damage(temp_BaseDamage);
    }
Пример #7
0
        public override void update(GameTime currentTime)
        {
            float distance = float.MaxValue;

            if (disable_movement == true)
            {
                disable_movement_time += currentTime.ElapsedGameTime.Milliseconds;
                if (disable_movement_time > 300)
                {
                    disable_movement      = false;
                    disable_movement_time = 0.0f;
                    velocity = Vector2.Zero;
                }
            }
            else
            {
                switch (mech_state)
                {
                case MechState.Moving:
                    current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                    tank_hull_animation_time  += currentTime.ElapsedGameTime.Milliseconds;
                    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.7))
                            {
                                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)
                                {
                                    entity_found = parentWorld.EntityList[i];
                                    break;
                                }
                            }
                        }
                    }

                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Right:
                        velocity   = new Vector2(0.5f, 0f);
                        dimensions = new Vector2(120, 96);
                        angle      = 0.0f;
                        break;

                    case GlobalGameConstants.Direction.Left:
                        velocity   = new Vector2(-0.5f, 0f);
                        dimensions = new Vector2(120, 96);
                        angle      = (float)(Math.PI);
                        break;

                    case GlobalGameConstants.Direction.Up:
                        velocity   = new Vector2(0f, -0.5f);
                        dimensions = new Vector2(96, 120);
                        angle      = (float)(-1 * Math.PI / 2);
                        break;

                    default:
                        velocity   = new Vector2(0.0f, 0.5f);
                        dimensions = new Vector2(96, 120);
                        angle      = (float)(Math.PI / 2);
                        break;
                    }

                    if (enemy_found)
                    {
                        distance = Vector2.Distance(CenterPoint, entity_found.CenterPoint);

                        tank_hull_animation_time = 0.0f;

                        if (Math.Abs(distance) < range_distance)
                        {
                            if (Math.Abs(distance) > 192 && Math.Abs(distance) < range_distance)
                            {
                                mech_state = MechState.Firing;
                            }
                            else
                            {
                                mech_state = MechState.MeleeWindUp;
                            }
                        }
                    }

                    int  corner_check = 0;
                    bool is_on_wall   = false;

                    while (corner_check != 4)
                    {
                        if (corner_check == 0)
                        {
                            is_on_wall = parentWorld.Map.hitTestWall(position);
                        }
                        else if (corner_check == 1)
                        {
                            is_on_wall = parentWorld.Map.hitTestWall(position + new Vector2(dimensions.X, 0));
                        }
                        else if (corner_check == 2)
                        {
                            is_on_wall = parentWorld.Map.hitTestWall(position + new Vector2(0, dimensions.Y));
                        }
                        else if (corner_check == 3)
                        {
                            is_on_wall = parentWorld.Map.hitTestWall(position + dimensions);
                        }

                        if (is_on_wall)
                        {
                            if (direction_facing == GlobalGameConstants.Direction.Right || direction_facing == GlobalGameConstants.Direction.Left)
                            {
                                dimensions = new Vector2(96, 120);
                                if (Game1.rand.NextDouble() > 0.5)
                                {
                                    direction_facing = GlobalGameConstants.Direction.Up;
                                }
                                else
                                {
                                    direction_facing = GlobalGameConstants.Direction.Down;
                                }
                            }
                            else
                            {
                                dimensions = new Vector2(120, 96);
                                if (Game1.rand.NextDouble() > 0.5)
                                {
                                    direction_facing = GlobalGameConstants.Direction.Right;
                                }
                                else
                                {
                                    direction_facing = GlobalGameConstants.Direction.Left;
                                }
                            }
                            break;
                        }
                        corner_check++;
                    }

                    break;

                case MechState.Firing:
                    windup_timer += currentTime.ElapsedGameTime.Milliseconds;
                    angle         = (float)Math.Atan2(entity_found.CenterPoint.Y - current_skeleton.Skeleton.FindBone("muzzle").WorldY, entity_found.CenterPoint.X - current_skeleton.Skeleton.FindBone("muzzle").WorldX);

                    distance = Vector2.Distance(position, entity_found.Position);

                    velocity = Vector2.Zero;

                    bool enemy_in_sight = parentWorld.Map.playerInSight(angle, distance, this, entity_found);

                    if (Math.Abs(distance) > 600 || entity_found.Remove_From_List == true || enemy_in_sight)
                    {
                        mech_state   = MechState.Moving;
                        windup_timer = 0.0f;
                        enemy_found  = false;
                        return;
                    }
                    else if (Math.Abs(distance) < 192)
                    {
                        windup_timer = 0.0f;
                        mech_state   = MechState.MeleeWindUp;
                    }

                    if (windup_timer > 2000)
                    {
                        if (grenade.active == false)
                        {
                            AudioLib.playSoundEffect("tankFire");
                            rocket_angle = (float)Math.Atan2(entity_found.CenterPoint.Y - current_skeleton.Skeleton.FindBone("muzzle").WorldY, entity_found.CenterPoint.X - current_skeleton.Skeleton.FindBone("muzzle").WorldX);
                            current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("attack");
                            grenade        = new Grenades(new Vector2(current_skeleton.Skeleton.FindBone("muzzle").WorldX, current_skeleton.Skeleton.FindBone("muzzle").WorldY), angle);
                            grenade.active = true;
                        }
                    }

                    if (windup_timer > 2100)
                    {
                        windup_timer = 0.0f;
                        current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                    }

                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Right:
                        if (angle < -1 * Math.PI / 3.27)
                        {
                            direction_facing = GlobalGameConstants.Direction.Up;
                            dimensions       = new Vector2(96, 120);
                        }
                        else if (angle > Math.PI / 3.27)
                        {
                            direction_facing = GlobalGameConstants.Direction.Down;
                            dimensions       = new Vector2(96, 120);
                        }
                        break;

                    case GlobalGameConstants.Direction.Left:
                        if (angle < Math.PI / 1.44 && angle > Math.PI / 1.5)
                        {
                            direction_facing = GlobalGameConstants.Direction.Down;
                            dimensions       = new Vector2(96, 120);
                        }
                        else if (angle > -1 * Math.PI / 1.44 && angle < -1 * Math.PI / 1.5)
                        {
                            direction_facing = GlobalGameConstants.Direction.Up;
                            dimensions       = new Vector2(96, 120);
                        }
                        break;

                    case GlobalGameConstants.Direction.Up:
                        if (angle < -1 * Math.PI / 1.24)
                        {
                            direction_facing = GlobalGameConstants.Direction.Left;
                            dimensions       = new Vector2(120, 96);
                        }
                        else if (angle > -1 * Math.PI / 5.14)
                        {
                            direction_facing = GlobalGameConstants.Direction.Right;
                            dimensions       = new Vector2(120, 96);
                        }
                        break;

                    default:
                        if (angle < Math.PI / 5.14)
                        {
                            direction_facing = GlobalGameConstants.Direction.Right;
                            dimensions       = new Vector2(120, 96);
                            //current_skeleton = walk_right;
                        }
                        else if (angle > Math.PI / 1.24)
                        {
                            direction_facing = GlobalGameConstants.Direction.Left;
                            dimensions       = new Vector2(120, 96);
                            //current_skeleton = walk_right;
                        }
                        break;
                    }

                    break;

                case MechState.MeleeWindUp:
                    windup_timer += currentTime.ElapsedGameTime.Milliseconds;
                    angle         = (float)Math.Atan2(entity_found.CenterPoint.Y - CenterPoint.Y, entity_found.CenterPoint.X - CenterPoint.X);

                    if (windup_timer > 1000)
                    {
                        mech_state   = MechState.Melee;
                        windup_timer = 0.0f;
                        melee_active = true;
                    }

                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Right:
                        if (angle < -1 * Math.PI / 3.27)
                        {
                            direction_facing = GlobalGameConstants.Direction.Up;
                            dimensions       = new Vector2(96, 120);
                            //current_skeleton = walk_up;
                        }
                        else if (angle > Math.PI / 3.27)
                        {
                            direction_facing = GlobalGameConstants.Direction.Down;
                            dimensions       = new Vector2(96, 120);
                            //current_skeleton = walk_down;
                        }
                        break;

                    case GlobalGameConstants.Direction.Left:
                        if (angle < Math.PI / 1.44 && angle > Math.PI / 1.5)
                        {
                            direction_facing = GlobalGameConstants.Direction.Down;
                            dimensions       = new Vector2(96, 120);
                            //current_skeleton = walk_down;
                        }
                        else if (angle > -1 * Math.PI / 1.44 && angle < -1 * Math.PI / 1.5)
                        {
                            direction_facing = GlobalGameConstants.Direction.Up;
                            dimensions       = new Vector2(96, 120);
                            //current_skeleton = walk_up;
                        }
                        break;

                    case GlobalGameConstants.Direction.Up:
                        if (angle < -1 * Math.PI / 1.24)
                        {
                            direction_facing = GlobalGameConstants.Direction.Left;
                            dimensions       = new Vector2(120, 96);
                            //current_skeleton = walk_right;
                        }
                        else if (angle > -1 * Math.PI / 5.14)
                        {
                            direction_facing = GlobalGameConstants.Direction.Right;
                            dimensions       = new Vector2(120, 96);
                            //current_skeleton = walk_right;
                        }
                        break;

                    default:
                        if (angle < Math.PI / 5.14)
                        {
                            direction_facing = GlobalGameConstants.Direction.Right;
                            dimensions       = new Vector2(120, 96);
                            //current_skeleton = walk_right;
                        }
                        else if (angle > Math.PI / 1.24)
                        {
                            direction_facing = GlobalGameConstants.Direction.Left;
                            dimensions       = new Vector2(120, 96);
                            //current_skeleton = walk_right;
                        }
                        break;
                    }
                    break;

                case MechState.Melee:
                    //current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                    windup_timer += currentTime.ElapsedGameTime.Milliseconds;

                    AudioLib.playTankFlameSoundEffect(true);

                    Vector2 flame_displacement = Vector2.Zero;

                    if (direction_facing == GlobalGameConstants.Direction.Left || direction_facing == GlobalGameConstants.Direction.Right)
                    {
                        flame_displacement = new Vector2(tankAnim.FrameDimensions.X / 2, 0);
                    }
                    else
                    {
                        flame_displacement = new Vector2(0, tankAnim.FrameDimensions.X / 2);
                    }

                    parentWorld.Particles.pushFlame(CenterPoint + ((direction_facing == GlobalGameConstants.Direction.Left || direction_facing == GlobalGameConstants.Direction.Up)?-1 * flame_displacement : flame_displacement), (float)((int)direction_facing * Math.PI / 2));
                    parentWorld.Particles.pushFlame(CenterPoint + ((direction_facing == GlobalGameConstants.Direction.Left || direction_facing == GlobalGameConstants.Direction.Up) ? -1 * flame_displacement : flame_displacement), (float)((int)direction_facing * Math.PI / 2));

                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Right:
                        melee_position = position + new Vector2(dimensions.X, melee_hitbox.Y / 4);
                        break;

                    case GlobalGameConstants.Direction.Left:
                        melee_position = position + new Vector2(-1 * melee_hitbox.X, dimensions.Y / 4);
                        break;

                    case GlobalGameConstants.Direction.Up:
                        melee_position = position + new Vector2(dimensions.X / 4, -1 * melee_hitbox.Y);
                        break;

                    default:
                        melee_position = position + new Vector2(dimensions.X / 4, dimensions.Y);
                        break;
                    }

                    foreach (Entity en in parentWorld.EntityList)
                    {
                        if (en == this)
                        {
                            continue;
                        }
                        else if (meleeHitTest(en))
                        {
                            Vector2 direction = en.CenterPoint - CenterPoint;
                            en.knockBack(direction, 3.5f, 10, this);
                        }
                    }

                    velocity = Vector2.Zero;
                    if (windup_timer > 1500)
                    {
                        windup_timer = 0.0f;
                        melee_active = false;
                        if (Math.Abs(distance) > 300 || entity_found.Remove_From_List)
                        {
                            enemy_found = false;
                            mech_state  = MechState.Moving;
                        }
                        else if (Math.Abs(distance) > 192 && Math.Abs(distance) < 300)
                        {
                            mech_state = MechState.Firing;
                        }
                        else
                        {
                            mech_state = MechState.MeleeWindUp;
                        }
                        AudioLib.stopTankFlameSoundEffect();
                    }
                    break;

                case MechState.Reset:
                    windup_timer = 0.0f;
                    enemy_found  = false;
                    mech_state   = MechState.Moving;
                    break;

                case MechState.Death:
                    death          = true;
                    explode_timer += currentTime.ElapsedGameTime.Milliseconds;
                    velocity       = Vector2.Zero;
                    break;

                default:
                    break;
                }
            }

            if (grenade.active)
            {
                grenade.update(parentWorld, currentTime, this);
            }

            if (enemy_life <= 0 && death == false)
            {
                AudioLib.stopFlameSoundEffect();
                explode_timer += currentTime.ElapsedGameTime.Milliseconds;
                animation_time = 0.0f;
                death          = true;
                mech_state     = MechState.Death;
                velocity       = Vector2.Zero;
                parentWorld.pushCoin(this);
            }

            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);
        }