public void SetSeason(Season season) { WeatherParticles.Clear(); FlashAmount = 1f; CurrentSeason = season; var rnd = new Random((int)DateTime.Now.Ticks); RectangleF mapbounds = (RectangleF)level.Meta["map_bounds"]; switch (CurrentSeason) { case Season.Spring: for (int i = 0; i < 18; i++) { var butterfly = new ButterflyParticle(new Vector2((float)rnd.NextDouble() * mapbounds.Width, (float)rnd.NextDouble() * mapbounds.Height), mapbounds, rnd.Next(4)); butterfly.SetTexture(Sprites); butterfly.Flipped = rnd.Next(2) == 1; WeatherParticles.Add(butterfly); } break; case Season.Summer: for (int i = 0; i < 8; i++) { var bee = new BeeParticle(new Vector2((float)rnd.NextDouble() * mapbounds.Width, (float)rnd.NextDouble() * mapbounds.Height), mapbounds, rnd.Next(4)); bee.SetTexture(Sprites); bee.Flipped = rnd.Next(2) == 1; WeatherParticles.Add(bee); } break; case Season.Autumn: for (int i = 0; i < 140; i++) { var leaf = new LeafParticle(new Vector2((float)rnd.NextDouble() * mapbounds.Width, (float)rnd.NextDouble() * mapbounds.Height), rnd.Next(2), rnd.Next(8)); leaf.SetTexture(Sprites); leaf.Flipped = rnd.Next(2) == 1; WeatherParticles.Add(leaf); } break; case Season.Winter: for (int i = 0; i < 320; i++) { var snow = new SnowParticle(new Vector2((float)rnd.NextDouble() * mapbounds.Width, (float)rnd.NextDouble() * mapbounds.Height), rnd.Next(5), rnd.Next(8)); snow.SetTexture(Sprites); snow.Flipped = rnd.Next(2) == 1; WeatherParticles.Add(snow); } break; } }
protected override void Update(GameTime gameTime) { #region Debug input handling KeyboardState ks = Keyboard.GetState(); if (ks.IsKeyDown(Keys.LeftControl) && ks.IsKeyDown(Keys.R) && !pkb.IsKeyDown(Keys.R)) { LoadMap("test"); } if (ks.IsKeyDown(Keys.Add) && !pkb.IsKeyDown(Keys.Add)) { Utils.DEBUG_FBF = !Utils.DEBUG_FBF; } if (ks.IsKeyDown(Keys.Subtract) && !pkb.IsKeyDown(Keys.Subtract)) { Utils.DEBUG_FBF_NEXT = true; } pkb = ks; if (Utils.DEBUG_FBF && !Utils.DEBUG_FBF_NEXT) { return; } Utils.DEBUG_FBF_NEXT = false; #endregion #region Debug queue Utils.QueueFlush(); #endregion Input.HandleInput(this, gameTime); Player.Update(gameTime, level); Player.InSecret = false; foreach (MapVolume volume in level.Volumes) { if (Collision.PointInPoly(Player.Position, volume.Poly, volume.Position)) { if (volume.Type == MapVolumeType.Secret) { Player.InSecret = true; } } } level.FadePos = Player.Position - Camera - new Vector2(Utils.GBW / 2, Utils.GBH / 2); float ft = Player.InSecret ? 1f : 0f; level.FadeAmount = Utils.Lerpf(level.FadeAmount, ft, (float)gameTime.ElapsedGameTime.TotalSeconds * 3f); foreach (Particle p in WeatherParticles) { Vector2 prevPos = p.TruePosition; p.Update(gameTime); //if (p is SnowParticle || p is LeafParticle) { // p.TruePosition = Utils.TrueMod(p.TruePosition, new Rectangle(Camera.X, 0, Utils.GBW * 2, Utils.GBH * 2)); //} else { // p.TruePosition = Utils.TrueMod(p.TruePosition, level.MapBounds); //} foreach (MapVolume v in level.Volumes) { if (v.Type == MapVolumeType.Weather) { Utils.QueueDebugPoly(v.Poly, v.Position, new Color(0, 255, 255)); if (Collision.PointInPoly(p.TruePosition, v.Poly, v.Position)) { Utils.QueueDebugPoint(p.TruePosition, 4f, new Color(0, 255, 0)); } else { Utils.QueueDebugPoint(p.TruePosition, 4f, new Color(255, 0, 0)); } } } if (p.Despawn) { WeatherParticles.Remove(p); } } for (int pi = 0; pi < Particles.Count; pi++) { Particles[pi].Update(gameTime); if (Particles[pi].Despawn) { Particles.Remove(Particles[pi--]); } } RectangleF mapbounds = (RectangleF)level.Meta["map_bounds"]; if (!mapbounds.Contains(Player.Position)) { if (level.Meta.ContainsKey("start_point")) { Player.Reset((Vector2)level.Meta["start_point"]); } else { Console.WriteLine("No start position found in map metadata!"); } } Camera.X = Player.Position.X - Utils.GBW / 2; Camera.Y = Player.Position.Y - Utils.GBH / 2 - 32; Camera = Utils.PointWithinRect(Camera, CameraBounds); if (Keyboard.GetState().IsKeyDown(Keys.OemMinus)) { FlashAmount = 1f; } FlashAmount -= (float)gameTime.ElapsedGameTime.TotalSeconds * 2.0f; FlashAmount = Math.Max(0f, FlashAmount); // TODO: Add your update logic here base.Update(gameTime); }