Ejemplo n.º 1
0
        private static void LightningTrap(MineShaft shaft, Vector2 position)
        {
            Microsoft.Xna.Framework.Rectangle lightningSourceRect = new Rectangle(0, 0, 16, 16);
            float   markerScale  = 8f;
            Vector2 drawPosition = position + new Vector2(-16 * markerScale / 2 + 32f, -16 * markerScale / 2 + 32f);

            shaft.temporarySprites.Add(new TemporaryAnimatedSprite("TileSheets\\Projectiles", lightningSourceRect, 9999f, 1, 999, drawPosition, false, Game1.random.NextDouble() < 0.5, (position.Y + 32f) / 10000f + 0.001f, 0.025f, Color.White, markerScale, 0f, 0f, 0f, false)
            {
                light       = true,
                lightRadius = 2f,
                delayBeforeAnimationStart = 0,
                lightcolor = Color.Black
            });
            shaft.playSound("thunder");
            Utility.drawLightningBolt(position + new Vector2(32f, 32f), shaft);

            FarmerCollection.Enumerator enumerator = shaft.farmers.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (enumerator.Current.currentLocation == shaft && enumerator.Current.GetBoundingBox().Intersects(new Rectangle((int)Math.Round(position.X - 32), (int)Math.Round(position.Y - 32), 64, 64)))
                {
                    enumerator.Current.takeDamage((int)Math.Ceiling(Math.Sqrt(shaft.mineLevel * config.TrapDamageMult)), true, null);
                }
            }
        }
Ejemplo n.º 2
0
        private void lightningStrike(Vector2 playerLocation)
        {
            Farm.LightningStrikeEvent lightningEvent = new Farm.LightningStrikeEvent();
            lightningEvent.bigFlash     = true;
            lightningEvent.createBolt   = true;
            lightningEvent.boltPosition = playerLocation + new Vector2(32f, 32f);
            Game1.flashAlpha            = (float)(0.5 + Game1.random.NextDouble());
            Game1.playSound("thunder");
            Utility.drawLightningBolt(lightningEvent.boltPosition, currentLocation);

            List <Farmer> farmers = new List <Farmer>();

            FarmerCollection.Enumerator enumerator = currentLocation.farmers.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (enumerator.Current.currentLocation == currentLocation && enumerator.Current.GetBoundingBox().Intersects(new Rectangle((int)Math.Round(playerLocation.X - 32), (int)Math.Round(playerLocation.Y - 32), 64, 64)))
                {
                    enumerator.Current.takeDamage((int)Math.Round(20 * difficulty), true, null);
                }
            }
        }
Ejemplo n.º 3
0
        public override void behaviorAtGameTick(GameTime time)
        {
            typeof(SquidKidBoss).BaseType.GetField("lastFireball", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(this as SquidKid, 1000f);
            base.behaviorAtGameTick(time);
            if (Health <= 0)
            {
                return;
            }

            if (this.withinPlayerThreshold(20))
            {
                this.lastIceBall   = Math.Max(0f, this.lastIceBall - (float)time.ElapsedGameTime.Milliseconds);
                this.lastLightning = Math.Max(0f, this.lastLightning - (float)time.ElapsedGameTime.Milliseconds);

                if (!startedLightning && lastLightning < (ModEntry.IsLessThanHalfHealth(this) ? 500f : 1000f))
                {
                    startedLightning = true;

                    List <Farmer> farmers = new List <Farmer>();
                    FarmerCollection.Enumerator enumerator = currentLocation.farmers.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        farmers.Add(enumerator.Current);
                    }
                    playerPosition = farmers[Game1.random.Next(0, farmers.Count)].position;

                    Microsoft.Xna.Framework.Rectangle lightningSourceRect = new Rectangle(0, 0, 16, 16);
                    float   markerScale  = 8f;
                    Vector2 drawPosition = playerPosition + new Vector2(-16 * markerScale / 2 + 32f, -16 * markerScale / 2 + 32f);

                    Game1.currentLocation.temporarySprites.Add(new TemporaryAnimatedSprite("TileSheets\\Projectiles", lightningSourceRect, 9999f, 1, 999, drawPosition, false, Game1.random.NextDouble() < 0.5, (playerPosition.Y + 32f) / 10000f + 0.001f, 0.025f, Color.White, markerScale, 0f, 0f, 0f, false)
                    {
                        light       = true,
                        lightRadius = 2f,
                        delayBeforeAnimationStart = 200,
                        lightcolor = Color.Black
                    });
                }

                if (lastLightning == 0f)
                {
                    startedLightning = false;
                    lightningStrike(playerPosition);
                    lastLightning = Game1.random.Next(1000, 2000) * (ModEntry.IsLessThanHalfHealth(this) ? 1 : 2);
                }
                if (lastIceBall == 0f)
                {
                    Vector2 trajectory = ModEntry.VectorFromDegree(Game1.random.Next(0, 360)) * 10f;
                    currentLocation.projectiles.Add(new BossProjectile((int)Math.Round(20 * difficulty), 9, 3, 4, 0f, trajectory.X, trajectory.Y, getStandingPosition(), "", "", true, false, currentLocation, this, false, null, 19));

                    projectileCount++;

                    if (projectileCount >= (ModEntry.IsLessThanHalfHealth(this) ? 8 : 4))
                    {
                        projectileCount = 0;
                        lastIceBall     = Game1.random.Next(1200, 3500);
                    }
                    else
                    {
                        lastIceBall = 100;
                    }
                    if (lastIceBall != 0f && Game1.random.NextDouble() < 0.05)
                    {
                        Halt();
                        setTrajectory((int)Utility.getVelocityTowardPlayer(Utility.Vector2ToPoint(base.getStandingPosition()), 8f, base.Player).X, (int)(-(int)Utility.getVelocityTowardPlayer(Utility.Vector2ToPoint(base.getStandingPosition()), 8f, base.Player).Y));
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public void Update(GameTime time)
 {
     if (peckFrames > 0)
     {
         peckFrames--;
     }
     else
     {
         nextPeck--;
         if (nextPeck <= 0)
         {
             if (context.ShouldBirdsRoost())
             {
                 peckFrames = 50;
             }
             else
             {
                 peckFrames = context.peckDuration;
             }
             nextPeck = Game1.random.Next(10, 30);
             if (Game1.random.NextDouble() <= 0.75)
             {
                 nextPeck += Game1.random.Next(50, 100);
                 if (!context.ShouldBirdsRoost())
                 {
                     peckDirection = Game1.random.Next(0, 2);
                 }
             }
         }
     }
     if (birdState == BirdState.Idle)
     {
         if (!context.ShouldBirdsRoost())
         {
             using (FarmerCollection.Enumerator enumerator = Game1.currentLocation.farmers.GetEnumerator())
             {
                 if (enumerator.MoveNext())
                 {
                     Farmer farmer = enumerator.Current;
                     float  num    = Utility.distance(farmer.position.X, position.X, farmer.position.Y, position.Y);
                     framesUntilNextMove--;
                     if (num < 200f || framesUntilNextMove <= 0)
                     {
                         FlyToNewPoint();
                     }
                 }
             }
         }
     }
     else
     {
         if (birdState != BirdState.Flying)
         {
             return;
         }
         float distance             = Utility.distance((float)(endPosition.X * 64) + 32f, position.X, (float)(endPosition.Y * 64) + 32f, position.Y);
         float max_velocity         = context.birdSpeed;
         float slow_down_multiplier = 0.25f;
         if (distance > max_velocity / slow_down_multiplier)
         {
             velocity = Utility.MoveTowards(velocity, max_velocity, 0.5f);
         }
         else
         {
             velocity = Math.Max(Math.Min(distance * slow_down_multiplier, velocity), 1f);
         }
         float path_distance = Utility.distance((float)endPosition.X + 32f, (float)startPosition.X + 32f, (float)endPosition.Y + 32f, (float)startPosition.Y + 32f) * 64f;
         if (path_distance <= 0.0001f)
         {
             path_distance = 0.0001f;
         }
         float delta = velocity / path_distance;
         pathPosition += delta;
         position      = new Vector2(Utility.Lerp((float)(startPosition.X * 64) + 32f, (float)(endPosition.X * 64) + 32f, pathPosition), Utility.Lerp((float)(startPosition.Y * 64) + 32f, (float)(endPosition.Y * 64) + 32f, pathPosition));
         if (pathPosition >= 1f)
         {
             position            = new Vector2((float)(endPosition.X * 64) + 32f, (float)(endPosition.Y * 64) + 32f);
             birdState           = BirdState.Idle;
             velocity            = 0f;
             framesUntilNextMove = Game1.random.Next(350, 500);
             if (Game1.random.NextDouble() < 0.75)
             {
                 framesUntilNextMove += Game1.random.Next(200, 300);
             }
         }
     }
 }
Ejemplo n.º 5
0
        public override void behaviorAtGameTick(GameTime time)
        {
            base.behaviorAtGameTick(time);

            if (Health <= 0)
            {
                return;
            }

            // fire!

            timeUntilNextAttack -= time.ElapsedGameTime.Milliseconds;

            List <Farmer> farmers = new List <Farmer>();

            FarmerCollection.Enumerator enumerator = currentLocation.farmers.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (enumerator.Current.currentLocation == currentLocation && enumerator.Current.GetBoundingBox().Intersects(GetBoundingBox()))
                {
                    enumerator.Current.takeDamage((int)Math.Round(20 * difficulty), true, null);
                    totalFireTime = 0;
                    nextFireTime  = 10;
                    attackState.Set(0);
                    timeUntilNextAttack = Game1.random.Next(1000, 2000);
                }
            }

            if (attackState.Value == 0 && withinPlayerThreshold(20))
            {
                firing.Set(false);
                if (timeUntilNextAttack < 0)
                {
                    timeUntilNextAttack = 0;
                    attackState.Set(1);
                    nextFireTime  = 50;
                    totalFireTime = 3000;
                    return;
                }
            }
            else if (totalFireTime > 0)
            {
                Farmer player = Player;
                if (!firing.Value)
                {
                    if (player != null)
                    {
                        faceGeneralDirection(player.Position, 0, false);
                    }
                }
                totalFireTime -= time.ElapsedGameTime.Milliseconds;
                if (nextFireTime > 0)
                {
                    nextFireTime -= time.ElapsedGameTime.Milliseconds;
                    if (nextFireTime <= 0)
                    {
                        if (!firing.Value)
                        {
                            firing.Set(true);
                        }
                        float   fire_angle  = 0f;
                        Vector2 shot_origin = new Vector2((float)GetBoundingBox().Center.X, (float)GetBoundingBox().Center.Y);
                        faceGeneralDirection(player.Position, 0, false);
                        switch (facingDirection.Value)
                        {
                        case 0:
                            fire_angle = 90f;
                            break;

                        case 1:
                            fire_angle = 0f;
                            break;

                        case 2:
                            fire_angle = 270f;
                            break;

                        case 3:
                            fire_angle = 180f;
                            break;
                        }
                        fire_angle += (float)Math.Sin((double)((float)totalFireTime / 1000f * 180f) * 3.1415926535897931 / 180.0) * 25f;
                        Vector2 shot_velocity = new Vector2((float)Math.Cos((double)fire_angle * 3.1415926535897931 / 180.0), -(float)Math.Sin((double)fire_angle * 3.1415926535897931 / 180.0));
                        shot_velocity *= 5f;

                        for (int i = 0; i < 8; i++)
                        {
                            bool one   = i < 4;
                            bool two   = i % 4 < 2;
                            bool three = i % 2 == 0;

                            Vector2 v = new Vector2((three ? shot_velocity.X : shot_velocity.Y) * (one ? -1 : 1), (three ? shot_velocity.Y : shot_velocity.X) * (two ? -1 : 1));
                            //v = ModEntry.RotateVector(v, j);
                            BasicProjectile projectile = new BossProjectile((int)(5 * difficulty), 766, 0, 1, 0.196349546f, v.X, v.Y, shot_origin, "", "", false, false, currentLocation, this, true, null, 13, true);
                            projectile.IgnoreLocationCollision       = true;
                            projectile.ignoreTravelGracePeriod.Value = true;
                            projectile.maxTravelDistance.Value       = 512;
                            currentLocation.projectiles.Add(projectile);

                            if (!ModEntry.IsLessThanHalfHealth(this))
                            {
                                i++;
                            }
                        }
                        if (ModEntry.IsLessThanHalfHealth(this))
                        {
                            j += 1;
                        }
                        j %= 360;


                        nextFireTime = 20;
                    }
                }
                if (totalFireTime <= 0)
                {
                    totalFireTime = 0;
                    nextFireTime  = 20;
                    attackState.Set(0);

                    timeUntilNextAttack = 0;
                }
            }
        }