Example #1
0
        public override void prePhysicsUpdate(GameTime time)
        {
            base.prePhysicsUpdate(time);
            this.location = startLoc;

            float distanceFromPlayer = Vector2.Distance(world.player.location, this.location);

            if (currentSound == null || (currentSound != null && currentSound.IsDisposed))
            {
                currentSound = SoundManager.getSound("teleporter_ambiance").play(SoundType.AMBIENT);
            }
            currentSound.Volume = Math.Max(0, Math.Min(1, 1f / distanceFromPlayer * 75));

            if (distanceFromPlayer < Game1.instance.graphics.PreferredBackBufferWidth && rand.NextDouble() < .2f)
            {
                int xAddative = ((rand.Next(50) - 25) * (rand.Next(50) - 25));


                Vector2  particleLoc   = location + new Vector2(xAddative, -rand.Next(200) + 50);
                TileType particleBlock = world.getBlock(particleLoc);
                if (particleBlock != null && !particleBlock.Equals(TileTypeReferencer.AIR))
                {
                    ParticleTileBreak particle = new ParticleTileBreak(particleLoc, world, new Vector2(0, 0), particleBlock, 75);
                    particle.gravityMultiplier = -.000001f;
                    particle.width             = 5;
                    particle.height            = 5;
                    world.addEntity(particle);
                }
            }
        }
        private void handleWeather()
        {
            if (decorator.worldGenSubtype != WorldGenSubtype.CENOTE)
            {
                float cloudyness   = decorator.weatherManager.cloudyness;
                float windStrength = decorator.weatherManager.windStrength;
                float rainyness    = decorator.weatherManager.rainyness;


                //on random chance, generate a new cloud.
                if (clouds.Count < cloudyness)
                {
                    int startLoc = 0;


                    int cloudY      = rand.Next(Game1.instance.graphics.PreferredBackBufferHeight / 2) - 300;
                    int cloudWidth  = 300 + rand.Next(100);
                    int cloudHeight = 200 + rand.Next(50);
                    int subClouds   = 3 + rand.Next(6);
                    if (windStrength > 0)
                    {
                        startLoc = -cloudWidth - 30;
                    }
                    else
                    {
                        startLoc = Game1.instance.graphics.PreferredBackBufferWidth + cloudWidth + 30;
                    }

                    for (int i = 0; i < subClouds; i++)
                    {
                        AABB newCloudBounds = new AABB(startLoc + rand.Next(cloudWidth), cloudY + rand.Next(cloudHeight), cloudWidth / 2, cloudHeight / 2);
                        clouds.Add(new Cloud(newCloudBounds, rand));
                    }
                }


                foreach (Cloud cloud in clouds)
                {
                    cloud.shift(windStrength * (1 - (float)cloud.bounds.Y / (Game1.instance.graphics.PreferredBackBufferHeight * .5f)));
                    if (windStrength > 0)
                    {
                        if (cloud.bounds.X > Game1.instance.graphics.PreferredBackBufferWidth)
                        {
                            removedClouds.Add(cloud);
                        }
                    }
                    else if (cloud.bounds.X < -cloud.bounds.Width)
                    {
                        removedClouds.Add(cloud);
                    }
                }
                foreach (Cloud cloud in removedClouds)
                {
                    clouds.Remove(cloud);
                }
                removedClouds.Clear();

                if (decorator.weatherManager.weather == WeatherManager.Weather.WINDY || decorator.weatherManager.weather == WeatherManager.Weather.STORMY)
                {
                    if (rand.NextDouble() < .5f)
                    {
                        Vector2  loc  = new Vector2(playerLoc.X + rand.Next(Game1.instance.graphics.PreferredBackBufferWidth) - Game1.instance.graphics.PreferredBackBufferWidth / 2, playerLoc.Y + rand.Next(Game1.instance.graphics.PreferredBackBufferHeight) - (Game1.instance.graphics.PreferredBackBufferHeight + 400) / 2);
                        TileType tile = getBlock(loc);
                        if (tile != null && !tile.tags.Contains(TagReferencer.SOLID))
                        {
                            ParticleTileBreak particle = new ParticleTileBreak(loc, this, new Vector2(windStrength * 3, 0), tile, 200);
                            particle.gravityMultiplier  = .07f;
                            particle.frictionMultiplier = .97f; //actually sets friction higher for this particle
                            particle.velocity           = new Vector2(windStrength, 0);
                            addEntity(particle);
                        }
                    }

                    foreach (Particle particle in particles)
                    {
                        particle.velocity += new Vector2(windStrength * .1f, 0);
                    }

                    foreach (Entity entity in entities)
                    {
                        if (!entity.collideBottom)
                        {
                            entity.impulse += new Vector2(windStrength * .1f * entity.windMultiplier, 0);
                        }
                        else
                        {
                            entity.impulse += new Vector2(windStrength * .01f * entity.windMultiplier, 0);
                        }
                    }
                }
                else if (decorator.weatherManager.weather == WeatherManager.Weather.FOGGY)
                {
                    int numFogBallsOnScreen = 70;

                    if (fogBalls.Count < numFogBallsOnScreen)
                    {
                        Vector2 loc          = new Vector2(playerLoc.X + rand.Next(Game1.instance.graphics.PreferredBackBufferWidth + 400) - (Game1.instance.graphics.PreferredBackBufferWidth + 200) / 2, playerLoc.Y + rand.Next(Game1.instance.graphics.PreferredBackBufferHeight) - (Game1.instance.graphics.PreferredBackBufferHeight) / 2);
                        int     size         = 400 + rand.Next(200);
                        AABB    newFogBounds = new AABB(loc.X, loc.Y, size, size);
                        fogBalls.Add(new FogBall(newFogBounds, rand));
                    }

                    AABB screenBounds = new AABB(playerLoc.X - Game1.instance.graphics.PreferredBackBufferWidth / 2 - 400, playerLoc.Y - Game1.instance.graphics.PreferredBackBufferHeight / 2 - 200, Game1.instance.graphics.PreferredBackBufferWidth + 800, Game1.instance.graphics.PreferredBackBufferHeight + 400);
                    foreach (FogBall fog in fogBalls)
                    {
                        fog.update();
                        if (!fog.bounds.Intersects(screenBounds))
                        {
                            removedFogBalls.Add(fog);
                        }
                    }

                    foreach (FogBall fog in removedFogBalls)
                    {
                        fogBalls.Remove(fog);
                    }
                    removedFogBalls.Clear();
                }
                else if (decorator.weatherManager.weather == WeatherManager.Weather.RAINY)
                {
                    if (rand.NextDouble() < .3)
                    {
                        Vector2 loc = new Vector2(playerLoc.X + rand.Next(Game1.instance.graphics.PreferredBackBufferWidth + 400) - (Game1.instance.graphics.PreferredBackBufferWidth + 200) / 2, playerLoc.Y - (Game1.instance.graphics.PreferredBackBufferHeight) / 2 - 100);
                        addEntity(new ParticleRain(loc, this, new Vector2(0, 1f)));
                    }
                }
            }
        }