Пример #1
0
        public ReturnChaseEnemy(LevelState parentWorld, float initial_x, float initial_y)
        {
            position              = new Vector2(initial_x, initial_y);
            dimensions            = new Vector2(48.0f, 48.0f);
            original_position     = CenterPoint;
            velocity              = new Vector2(0.0f, 0.0f);
            enemy_damage          = 10;
            enemy_life            = 15;
            distance              = 0.0f;
            angle                 = 0.0f;
            angle1                = 0.0f;
            angle2                = 0.0f;
            knockback_magnitude   = 2.0f;
            disable_movement_time = 0.0f;
            return_timer          = 0.0f;

            direction_facing      = GlobalGameConstants.Direction.Right;
            change_direction_time = 0.0f;
            enemy_found           = false;
            state = EnemyState.Idle;

            component = new IdleSearch();

            this.parentWorld = parentWorld;

            walk_down                       = AnimationLib.getSkeleton("chaseDown");
            walk_right                      = AnimationLib.getSkeleton("chaseRight");
            walk_up                         = AnimationLib.getSkeleton("chaseUp");
            current_skeleton                = walk_right;
            current_skeleton.Animation      = current_skeleton.Skeleton.Data.FindAnimation("idle");
            current_skeleton.Skeleton.FlipX = false;
            chaseAnim                       = AnimationLib.getFrameAnimationSet("chasePic");
            animation_time                  = 0.0f;
        }
Пример #2
0
    private void SpawnRandomEnemy(EnemyComponents spawnPrefab, PlayerComponents player, EnemyComponents[] allEnemies, AISensor[] allSensors)
    {
        EnemyComponents choosePartner;
        Vector2         randomCircle;
        NavMeshHit      hit;

        do
        {
            choosePartner = allEnemies[Random.Range(0, allEnemies.Length - 1)];
            randomCircle  = Random.insideUnitCircle.normalized * Random.Range(randomEnemyRange.x, randomEnemyRange.y);
        }while (NavMesh.SamplePosition(
                    choosePartner.transform.position + new Vector3(randomCircle.x, 0, randomCircle.y),
                    out hit, 20f, NavMesh.AllAreas) == false
                ||
                Vector3.Distance(hit.position, player.transform.position) < minDistanceFromPlayer);

        EnemyComponents newEnemy = Instantiate(spawnPrefab, hit.position, Quaternion.Euler(0, Random.Range(0, 360), 0));

        UpgradeEnemy(newEnemy);

        //hook up sensors
        for (int i = 0; i < allSensors.Length; i++)
        {
            if (allSensors[i].affectedEnemies.Contains(choosePartner.enemyControl))
            {
                allSensors[i].affectedEnemies.Add(newEnemy.enemyControl);
            }
        }
    }
Пример #3
0
        private void Start()
        {
            PlayerComponents = FindObjectsOfType <PlayerComponent>();
            EnemyComponents  = FindObjectsOfType <EnemyComponent>();

            Components = PlayerComponents.Cast <SomeoneComponent>()
                         .Concat(EnemyComponents.Cast <SomeoneComponent>())
                         .ToList();

            Step();
        }
Пример #4
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");
        }
Пример #5
0
        public GuardSquadLeader(LevelState parentWorld, float initial_x, float initial_y)
        {
            position   = new Vector2(initial_x, initial_y);
            dimensions = new Vector2(48.0f, 48.0f);
            velocity   = new Vector2(1.0f, 0f);

            component        = new MoveSearch();
            this.parentWorld = parentWorld;

            populateSquadMates();

            direction_facing = GlobalGameConstants.Direction.Right;
            state            = SquadLeaderState.Patrol;

            follow_point_1 = new Vector2((float)(CenterPoint.X + 64 * Math.Cos(-3 * Math.PI / 4)), (float)(CenterPoint.Y + 64 * Math.Sin(-3 * Math.PI / 4)));
            if (squad_mates[0] != null)
            {
                squad_mates[0].Follow_Point = follow_point_1;
            }
            if (squad_mates[1] != null)
            {
                squad_mates[1].Follow_Point = follow_point_2;
            }

            enemy_life                      = 30;
            enemy_damage                    = 5;
            disable_movement                = false;
            disable_movement_time           = 0.0f;
            enemy_found                     = false;
            change_direction_time           = 0.0f;
            range_distance                  = 400.0f;
            change_direction_time_threshold = 5000.0f;
            enemy_type                      = EnemyType.Guard;
            death        = false;
            windup_timer = 0.0f;

            prob_item_drop    = 0.4;
            number_drop_items = 4;

            walk_down                       = AnimationLib.loadNewAnimationSet("squadLeaderDown");
            walk_right                      = AnimationLib.loadNewAnimationSet("squadLeaderRight");
            walk_up                         = AnimationLib.loadNewAnimationSet("squadLeaderUp");
            current_skeleton                = walk_right;
            current_skeleton.Animation      = current_skeleton.Skeleton.Data.FindAnimation("run");
            current_skeleton.Skeleton.FlipX = false;
            animation_time                  = 0.0f;
        }
        public ChargerMutantEnemy(LevelState parentWorld, Vector2 position)
        {
            this.position = position;
            dimensions    = new Vector2(32f, 96.0f);
            velocity      = Vector2.Zero;

            disable_movement      = false;
            disable_movement_time = 0.0f;
            windup_timer          = 0.0f;
            knockback_magnitude   = 8.0f;
            enemy_damage          = 15;
            enemy_life            = 20;
            enemy_found           = false;
            change_direction_time = 0.0f;
            range_distance        = 300.0f;
            charge_timer          = 0.0f;
            alert_timer           = 0.0f;
            range_distance        = 600f;
            sound_timer           = 0.0f;
            play_sound            = true;

            prob_item_drop    = 0.6;
            number_drop_items = 5;

            entity_found = null;
            state        = ChargerState.search;
            enemy_type   = EnemyType.Prisoner;
            component    = new IdleSearch();

            sound_alert = false;

            direction_facing = (GlobalGameConstants.Direction)(Game1.rand.Next() % 4);

            this.parentWorld = parentWorld;

            directionAnims = new AnimationLib.SpineAnimationSet[4];
            directionAnims[(int)GlobalGameConstants.Direction.Up]   = AnimationLib.loadNewAnimationSet("chargerUp");
            directionAnims[(int)GlobalGameConstants.Direction.Down] = AnimationLib.loadNewAnimationSet("chargerDown");
            directionAnims[(int)GlobalGameConstants.Direction.Left] = AnimationLib.loadNewAnimationSet("chargerRight");
            directionAnims[(int)GlobalGameConstants.Direction.Left].Skeleton.FlipX = true;
            directionAnims[(int)GlobalGameConstants.Direction.Right] = AnimationLib.loadNewAnimationSet("chargerRight");
            for (int i = 0; i < 4; i++)
            {
                directionAnims[i].Animation = directionAnims[i].Skeleton.Data.FindAnimation("idle");
            }
        }
        public BallMutant(LevelState parentWorld, float initial_x, float initial_y)
        {
            position        = new Vector2(initial_x, initial_y);
            dimensions      = new Vector2(48f, 48f);
            velocity        = Vector2.Zero;
            ball_coordinate = Vector2.Zero;

            state            = mutantBallState.Search;
            component        = new IdleSearch();
            direction_facing = GlobalGameConstants.Direction.Right;

            radius = 0.0f;
            angle  = 0.0f;
            change_direction_time = 0.0f;
            agressive_timer       = 0.0f;
            distance            = 0.0f;
            alert_timer         = 0.0f;
            knockback_magnitude = 5.0f;
            range_distance      = 250.0f;

            this.parentWorld = parentWorld;

            death = false;

            enemy_damage = 5;
            enemy_life   = 5;
            enemy_type   = EnemyType.Alien;

            prob_item_drop    = 0.4;
            number_drop_items = 4;

            walk_down                       = AnimationLib.loadNewAnimationSet("ballMutantUp");
            walk_right                      = AnimationLib.loadNewAnimationSet("ballMutantRight");
            walk_up                         = AnimationLib.loadNewAnimationSet("ballMutantUp");
            current_skeleton                = walk_right;
            current_skeleton.Animation      = current_skeleton.Skeleton.Data.FindAnimation("run");
            current_skeleton.Skeleton.FlipX = false;
            //chaseAnim = AnimationLib.getFrameAnimationSet("chasePic");
            animation_time = 0.0f;

            entity_found = null;

            chain_ball = AnimationLib.getFrameAnimationSet("snakeB");
        }
        public HookPrisonerEnemy(LevelState parentWorld, float initial_x, float initial_y)
        {
            position         = new Vector2(initial_x, initial_y);
            dimensions       = new Vector2(32f, 90.0f);
            velocity         = Vector2.Zero;
            chain_velocity   = Vector2.Zero;
            chain_dimensions = new Vector2(10.0f, 10.0f);
            chain_position   = position;

            disable_movement      = false;
            disable_movement_time = 0.0f;
            knockback_magnitude   = 10.0f;
            enemy_damage          = 20;
            enemy_life            = 25;
            enemy_found           = false;
            change_direction_time = 0.0f;
            range_distance        = 300.0f;
            angle          = 0.0f;
            animation_time = 0.0f;

            prob_item_drop    = 0.5;
            number_drop_items = 5;

            state      = ChainState.Moving;
            enemy_type = EnemyType.Prisoner;
            component  = new MoveSearch();
            en_chained = null;
            death      = false;

            directionAnims = new AnimationLib.SpineAnimationSet[4];
            directionAnims[(int)GlobalGameConstants.Direction.Up]   = AnimationLib.loadNewAnimationSet("hookUp");
            directionAnims[(int)GlobalGameConstants.Direction.Down] = AnimationLib.loadNewAnimationSet("hookDown");
            directionAnims[(int)GlobalGameConstants.Direction.Left] = AnimationLib.loadNewAnimationSet("hookRight");
            directionAnims[(int)GlobalGameConstants.Direction.Left].Skeleton.FlipX = true;
            directionAnims[(int)GlobalGameConstants.Direction.Right] = AnimationLib.loadNewAnimationSet("hookRight");

            hook = AnimationLib.getFrameAnimationSet("hook");

            this.parentWorld = parentWorld;
        }
        public ChaseEnemy(LevelState parentWorld, float initial_x, float initial_y)
        {
            this.position  = new Vector2(initial_x, initial_y);
            enemy_speed    = 2.0f;
            velocity       = new Vector2(0.0f, -1.0f * enemy_speed);
            dimensions     = new Vector2(48f, 48f);
            sword_hitbox   = new Vector2(48f, 48f);
            sword_position = position;

            state                 = ChaseState.search;
            chaseComponent        = new Chase();
            searchComponent       = new MoveSearch();
            component             = searchComponent;
            direction_facing      = GlobalGameConstants.Direction.Up;
            change_direction_time = 0.0f;
            this.parentWorld      = parentWorld;
            enemy_found           = false;
            player_in_range       = false;
            chase_target          = null;
            play_sound            = true;

            enemy_type          = EnemyType.Prisoner;
            enemy_damage        = 1;
            enemy_life          = 15;
            knockback_magnitude = 5.0f;
            wind_anim           = 0.0f;
            number_drop_items   = 3;
            prob_item_drop      = 0.3;

            walk_down                       = AnimationLib.loadNewAnimationSet("chaseDown");
            walk_right                      = AnimationLib.loadNewAnimationSet("chaseRight");
            walk_up                         = AnimationLib.loadNewAnimationSet("chaseUp");
            current_skeleton                = walk_up;
            current_skeleton.Animation      = current_skeleton.Skeleton.Data.FindAnimation("run");
            current_skeleton.Skeleton.FlipX = false;
            chaseAnim                       = AnimationLib.getFrameAnimationSet("chasePic");
            animation_time                  = 0.0f;
        }
        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);
        }
Пример #11
0
 public void RegisterEnemy(EnemyComponents enemy) =>
 enemies.Add(enemy);
Пример #12
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);
        }
Пример #13
0
 private void UpgradeEnemy(EnemyComponents enemy)
 {
     //increase movement speed
     enemy.characterSheet.IncreaseAttribute(CharacterSheet.Attribute.moveSpeed, newGameCount * enemySpeedIncrease);
 }