public override void LoadContent() { base.LoadContent(); camera = new Camera2D(Vector2.Zero); camera.Zoom = 1.5f; font = content.Load <SpriteFont>("Font"); tilemapTexture = this.content.Load <Texture2D>("SpriteSheet"); MediaPlayer.Volume = 0.3f; MediaPlayer.Play(Globals.MenuSong); MediaPlayer.IsRepeating = true; diveButton = new Trigger(Graphics.PreferredBackBufferWidth / 2 - 128 / 2, Graphics.PreferredBackBufferHeight - 48 - 32, 128f, 48f, "dive"); //Graphics.PreferredBackBufferWidth / 2 - 128 / 2, Graphics.PreferredBackBufferHeight - 48 - 32, 128, 48 /* * Level init */ XMLLevelLoader XMLloader = new XMLLevelLoader(); // se o load do mapa falhar, well shit. vai para o menu. try { level = XMLloader.LoadLevel(this, @"Content\Menu.tmx", tilemapTexture); } catch (Exception e) { Console.WriteLine("Error Loading Map. Error message: " + e.Message); StateManager.Instance.StartGameState("MenuState"); } level.SetCollisionTiles(new int[] { 2, 33, 34, 35, 47, 66, 15, 79 }); /* * parse objects */ foreach (TiledObject obj in level.Objects) { Console.WriteLine("parsing " + obj.Name); if (obj.Name.ToLower() == "jellyfish") { Vector2 center = new Vector2(obj.X + obj.Width / 2, obj.Y + obj.Height / 2); Vector2 radius = new Vector2(obj.Width / 2, obj.Height / 2); float speed = float.Parse(obj.GetProperty("speed")); JellyFish j = new JellyFish(this, tilemapTexture, Vector2.Zero, 16, 32, center, radius, speed); Karma.maxKarma += j.Health; // make it start on the right side of its path if (obj.GetProperty("start_rotation") == "right") { j.FacingDirection = 1; } else { j.FacingDirection = -1; } Console.WriteLine(obj.GetProperty("start_rotation")); enemies.Add(j); } else if (obj.Name.ToLower() == "pufferfish") { Vector2 position = new Vector2(obj.X, obj.Y); float speed = float.Parse(obj.GetProperty("speed")); PufferFish p = new PufferFish(this, tilemapTexture, position, 32, 32, obj.Width, speed); for (int i = 0; i < p.Bullets.Count; i++) { p.Bullets[i].Alive = true; p.Bullets[i].Visible = false; } Karma.maxKarma += p.Health; // make it start on the right side of its path if (obj.GetProperty("start_side") == "right") { p.Body.X = obj.X + obj.Width; p.CurrentDistance = obj.Width - 33; } enemies.Add(p); } else if (obj.Name.ToLower() == "turtlex") { Vector2 position = new Vector2(obj.X, obj.Y); float speed = float.Parse(obj.GetProperty("speed")); TurtleX p = new TurtleX(this, tilemapTexture, position, 32, 32, 64, obj.Width, speed); p.Animations.CurrentFrame = new Frame(96, 112, 32, 32); Karma.maxKarma += p.Health; // make it start on the right side of its path if (obj.GetProperty("start_side") == "right") { p.Body.X = obj.X + obj.Width; p.CurrentDistance = obj.Width - 33; } enemies.Add(p); } else if (obj.Name.ToLower() == "goldfish") { goldenFishs.Add(new GoldFish(this, tilemapTexture, new Vector2(obj.X, obj.Y), 16, 16)); } else if (obj.Name.ToLower() == "particles") { if (obj.GetProperty("type") == "dark_ambient") { ParticleEmitter particleEmitter = new ParticleEmitter(this, obj.X, obj.Y, 256); particleEmitter.EmitterBox.Resize(obj.Width, obj.Height); particleEmitter.MakeRandomParticles(tilemapTexture, new Rectangle[] { new Rectangle(128, 257, 3, 3), new Rectangle(132, 257, 3, 3), new Rectangle(136, 257, 3, 3) }); particleEmitter.ParticleVelocity = new Vector2(0, 0); particleEmitter.SetAcceleration(0, 0); particleEmitter.XVelocityVariationRange = new Vector2(-20f, 20f); particleEmitter.YVelocityVariationRange = new Vector2(-20f, 20f); particleEmitter.SpawnRate = 100f; particleEmitter.ParticleLifespanMilliseconds = 5000f; particleEmitter.ParticleLifespanVariationMilliseconds = 1000f; particleEmitter.InitialScale = 1.5f; particleEmitter.FinalScale = 0.5f; backgroundParticles.Add(particleEmitter); } else { ParticleEmitter particleEmitter = new ParticleEmitter(this, obj.X, obj.Y, 256); particleEmitter.EmitterBox.Resize(obj.Width, obj.Height); particleEmitter.MakeParticles(tilemapTexture, 16, 16); particleEmitter.ParticleVelocity = new Vector2(0, -0.01f); particleEmitter.SetAcceleration(0, -0.005f); particleEmitter.XVelocityVariationRange = new Vector2(-20f, 20f); particleEmitter.YVelocityVariationRange = new Vector2(-20f, 0f); particleEmitter.SetTextureCropRectangle(new Rectangle(0, 78, 16, 16)); particleEmitter.SpawnRate = 250f; particleEmitter.ParticleLifespanMilliseconds = 5000f; particleEmitter.ParticleLifespanVariationMilliseconds = 1000f; particleEmitter.InitialScale = 0.1f; particleEmitter.FinalScale = 1.5f; particleEmitter.ForEachParticle(ChangeSpriteTintBlue); backgroundParticles.Add(particleEmitter); } } else if (obj.Name.ToLower() == "player_spawn") { //player.Body.X = obj.X; //player.Body.Y = obj.Y; } else if (obj.Name.ToLower() == "change_state_trigger") { triggers.Add(new Trigger(obj.X, obj.Y, obj.Width, obj.Height, obj.GetProperty("value"))); } else if (obj.Name.ToLower() == "speedbox") { SpeedBox s = new SpeedBox(obj.X, obj.Y, obj.Width, obj.Height, float.Parse(obj.GetProperty("speedX")), float.Parse(obj.GetProperty("speedY"))); ParticleEmitter particleEmitter = new ParticleEmitter(this, obj.X, obj.Y, 512); particleEmitter.EmitterBox.Resize(obj.Width, obj.Height); particleEmitter.MakeRandomParticles(tilemapTexture, new Rectangle[] { new Rectangle(128, 257, 3, 3), new Rectangle(132, 257, 3, 3), new Rectangle(136, 257, 3, 3), new Rectangle(128 - 16, 257, 3, 3), new Rectangle(132 - 16, 257, 3, 3), new Rectangle(136 - 16, 257, 3, 3) }); particleEmitter.ParticleVelocity = new Vector2(s.SpeedIncrease.X * 10, s.SpeedIncrease.Y * 10); particleEmitter.XVelocityVariationRange = new Vector2(-20f, 20f); particleEmitter.YVelocityVariationRange = new Vector2(-20f, 20f); particleEmitter.SpawnRate = 60f; particleEmitter.ParticleLifespanMilliseconds = 5000f; particleEmitter.ParticleLifespanVariationMilliseconds = 1000f; particleEmitter.InitialScale = 1.0f; particleEmitter.FinalScale = 0.5f; backgroundParticles.Add(particleEmitter); speedBoxes.Add(s); } Console.WriteLine("added " + obj.Name); } topWaterTiles = level.GetTilesListByID(new int[] { 97, 98, 99 }); /* * Build Background Gradient */ backgroundWaterGradientStrip = new Texture2D(Graphics.GraphicsDevice, 1, level.Height * level.TileHeight); Color startColor = new Color(57, 92, 181); Color finishColor = new Color(17, 43, 104); Color currentColor; for (int i = 0; i < backgroundWaterGradientStrip.Height; i++) { float ratio = Math2.Map(i, 0f, backgroundWaterGradientStrip.Height, 0f, 1.0f); currentColor = Color.Lerp(startColor, finishColor, ratio); DrawMe.Pixel(backgroundWaterGradientStrip, 0, i, currentColor); } /* * Build Background Gradient */ backgroundSkyGradientStrip = new Texture2D(Graphics.GraphicsDevice, 1, Graphics.PreferredBackBufferHeight / 2); startColor = new Color(61, 28, 111); finishColor = new Color(158, 98, 123); for (int i = 0; i < backgroundSkyGradientStrip.Height; i++) { float ratio = Math2.Map(i, 0f, backgroundSkyGradientStrip.Height, 0f, 1.0f); currentColor = Color.Lerp(startColor, finishColor, ratio); DrawMe.Pixel(backgroundSkyGradientStrip, 0, i, currentColor); } ContentLoaded = true; }
public override void LoadContent() { base.LoadContent(); camera = new Camera2D(Vector2.Zero); camera.Zoom = (float)Graphics.PreferredBackBufferHeight * 2.45f / 600f; // the ideal zoom is 2.45 at 600px of screen height font = content.Load <SpriteFont>("Font"); tilemapTexture = this.content.Load <Texture2D>("SpriteSheet"); MediaPlayer.Volume = 0.3f; MediaPlayer.Play(Globals.LevelSong); MediaPlayer.IsRepeating = true; /* * A single pixel to draw lines and stuff */ pixel = new Texture2D(Graphics.GraphicsDevice, 1, 1); DrawMe.Fill(pixel, Color.White); /* * Load sfx */ SFX.Add("bubble", content.Load <SoundEffect>("sfx_bubble")); SFX.Add("bubble_noise_single", content.Load <SoundEffect>("BubbleNoisesSingle")); SFX.Add("anchor", content.Load <SoundEffect>("Anchor3")); SFX.Add("fall", content.Load <SoundEffect>("Falling")); SFX.Add("enemyDeath", content.Load <SoundEffect>("EnemyDeath")); SFX.Add("goldenFish", content.Load <SoundEffect>("GoldenFish2")); SFX.Add("energyWarning", content.Load <SoundEffect>("EnergyEmpty")); //done SFX.Add("turtleExplosion", content.Load <SoundEffect>("TurtleExplosion")); //done SFX.Add("playerHurt", content.Load <SoundEffect>("Player hurt")); //done SFX.Add("playerDeath", content.Load <SoundEffect>("Player Death3")); //done faltar esperar uns segundos antes de fazer reload de state /* * Player init */ player = new Player(this, tilemapTexture, Vector2.Zero, 32, 32, true); /* * Level init */ XMLLevelLoader XMLloader = new XMLLevelLoader(); // se o load do mapa falhar, well shit. vai para o menu. try { level = XMLloader.LoadLevel(this, @"Content\" + Globals.CurrentLevel + ".tmx", tilemapTexture); } catch (Exception e) { Console.WriteLine("Error Loading Map. Error message: " + e.Message); StateManager.Instance.StartGameState("MenuState"); } level.SetCollisionTiles(new int[] { 2, 33, 34, 35, 47, 66, 15, 79 }); /* * parse objects */ foreach (TiledObject obj in level.Objects) { Console.WriteLine("parsing " + obj.Name); if (obj.Name.ToLower() == "jellyfish") { Vector2 center = new Vector2(obj.X + obj.Width / 2, obj.Y + obj.Height / 2); Vector2 radius = new Vector2(obj.Width / 2, obj.Height / 2); float speed = float.Parse(obj.GetProperty("speed")); JellyFish j = new JellyFish(this, tilemapTexture, Vector2.Zero, 16, 32, center, radius, speed); Karma.maxKarma += j.Health; // make it start on the right side of its path if (obj.GetProperty("start_rotation") == "right") { j.FacingDirection = 1; } else { j.FacingDirection = -1; } Console.WriteLine(obj.GetProperty("start_rotation")); enemies.Add(j); } else if (obj.Name.ToLower() == "pufferfish") { Vector2 position = new Vector2(obj.X, obj.Y); float speed = float.Parse(obj.GetProperty("speed")); PufferFish p = new PufferFish(this, tilemapTexture, position, 32, 32, obj.Width, speed); Karma.maxKarma += p.Health; // make it start on the right side of its path if (obj.GetProperty("start_side") == "right") { p.Body.X = obj.X + obj.Width; p.CurrentDistance = obj.Width - 33; } enemies.Add(p); } else if (obj.Name.ToLower() == "turtlex") { Vector2 position = new Vector2(obj.X, obj.Y); float speed = float.Parse(obj.GetProperty("speed")); TurtleX p = new TurtleX(this, tilemapTexture, position, 32, 32, 64, obj.Width, speed); p.Animations.CurrentFrame = new Frame(96, 112, 32, 32); Karma.maxKarma += p.Health; // make it start on the right side of its path if (obj.GetProperty("start_side") == "right") { p.Body.X = obj.X + obj.Width; p.CurrentDistance = obj.Width - 33; } enemies.Add(p); } else if (obj.Name.ToLower() == "goldfish") { goldenFishs.Add(new GoldFish(this, tilemapTexture, new Vector2(obj.X, obj.Y), 16, 16)); } else if (obj.Name.ToLower() == "particles") { if (obj.GetProperty("type") == "dark_ambient") { ParticleEmitter particleEmitter = new ParticleEmitter(this, obj.X, obj.Y, 256); particleEmitter.EmitterBox.Resize(obj.Width, obj.Height); particleEmitter.MakeRandomParticles(tilemapTexture, new Rectangle[] { new Rectangle(128, 257, 3, 3), new Rectangle(132, 257, 3, 3), new Rectangle(136, 257, 3, 3) }); particleEmitter.ParticleVelocity = new Vector2(0, 0); particleEmitter.SetAcceleration(0, 0); particleEmitter.XVelocityVariationRange = new Vector2(-20f, 20f); particleEmitter.YVelocityVariationRange = new Vector2(-20f, 20f); particleEmitter.SpawnRate = 100f; particleEmitter.ParticleLifespanMilliseconds = 5000f; particleEmitter.ParticleLifespanVariationMilliseconds = 1000f; particleEmitter.InitialScale = 1.5f; particleEmitter.FinalScale = 0.5f; backgroundParticles.Add(particleEmitter); } else { ParticleEmitter particleEmitter = new ParticleEmitter(this, obj.X, obj.Y, 256); particleEmitter.EmitterBox.Resize(obj.Width, obj.Height); particleEmitter.MakeParticles(tilemapTexture, 16, 16); particleEmitter.ParticleVelocity = new Vector2(0, -0.01f); particleEmitter.SetAcceleration(0, -0.005f); particleEmitter.XVelocityVariationRange = new Vector2(-20f, 20f); particleEmitter.YVelocityVariationRange = new Vector2(-20f, 0f); particleEmitter.SetTextureCropRectangle(new Rectangle(0, 78, 16, 16)); particleEmitter.SpawnRate = 250f; particleEmitter.ParticleLifespanMilliseconds = 5000f; particleEmitter.ParticleLifespanVariationMilliseconds = 1000f; particleEmitter.InitialScale = 0.1f; particleEmitter.FinalScale = 1.5f; particleEmitter.ForEachParticle(ChangeSpriteTintBlue); backgroundParticles.Add(particleEmitter); } } else if (obj.Name.ToLower() == "player_spawn") { player.Body.X = obj.X; player.Body.Y = obj.Y; } else if (obj.Name.ToLower() == "change_state_trigger") { triggers.Add(new Trigger(obj.X, obj.Y, obj.Width, obj.Height, obj.GetProperty("value"))); } else if (obj.Name.ToLower() == "speedbox") { SpeedBox s = new SpeedBox(obj.X, obj.Y, obj.Width, obj.Height, float.Parse(obj.GetProperty("speedX")), float.Parse(obj.GetProperty("speedY"))); ParticleEmitter particleEmitter = new ParticleEmitter(this, obj.X, obj.Y, 512); particleEmitter.EmitterBox.Resize(obj.Width, obj.Height); particleEmitter.MakeRandomParticles(tilemapTexture, new Rectangle[] { new Rectangle(128, 257, 3, 3), new Rectangle(132, 257, 3, 3), new Rectangle(136, 257, 3, 3), new Rectangle(128 - 16, 257, 3, 3), new Rectangle(132 - 16, 257, 3, 3), new Rectangle(136 - 16, 257, 3, 3) }); particleEmitter.ParticleVelocity = new Vector2(s.SpeedIncrease.X * 10, s.SpeedIncrease.Y * 10); particleEmitter.XVelocityVariationRange = new Vector2(-20f, 20f); particleEmitter.YVelocityVariationRange = new Vector2(-20f, 20f); particleEmitter.SpawnRate = 60f; particleEmitter.ParticleLifespanMilliseconds = 5000f; particleEmitter.ParticleLifespanVariationMilliseconds = 1000f; particleEmitter.InitialScale = 1.0f; particleEmitter.FinalScale = 0.5f; backgroundParticles.Add(particleEmitter); speedBoxes.Add(s); } Console.WriteLine("added " + obj.Name); } // build spikes tiles list spikesPointingDown = level.GetTilesListByID(new int[] { 514 }); spikesPointingUp = level.GetTilesListByID(new int[] { 515 }); spikesPointingLeft = level.GetTilesListByID(new int[] { 516 }); spikesPointingRight = level.GetTilesListByID(new int[] { 517 }); foreach (Tile spike in spikesPointingDown) { spike.Body.SetSize(12, 6, 1, 0); } foreach (Tile spike in spikesPointingUp) { spike.Body.SetSize(12, 6, 2, 10); } foreach (Tile spike in spikesPointingLeft) { spike.Body.SetSize(6, 12, 10, 2); } foreach (Tile spike in spikesPointingRight) { spike.Body.SetSize(6, 12, 0, 2); } topWaterTiles = level.GetTilesListByID(new int[] { 97, 98, 99 }); /* * UI Elements init */ //healthBar = new EnergyBar(Graphics, new Vector2(16, 16), 256, 16, new Color(0, 255, 0)); energyBar = new EnergyBar(Graphics, new Vector2(16 + 6, 16 + 25), 16 * 10 - 9, 16, new Color(255, 0, 0)); //16+2, 16 + 8, 16*10, 32+16 Karma.karma = Karma.maxKarma; Karma.maxCollectables = goldenFishs.Count; /* * Build Background Gradient */ backgroundWaterGradientStrip = new Texture2D(Graphics.GraphicsDevice, 1, level.Height * level.TileHeight); Color startColor = new Color(57, 92, 181); Color finishColor = new Color(17, 43, 104); Color currentColor; for (int i = 0; i < backgroundWaterGradientStrip.Height; i++) { float ratio = Math2.Map(i, 0f, backgroundWaterGradientStrip.Height, 0f, 1.0f); currentColor = Color.Lerp(startColor, finishColor, ratio); DrawMe.Pixel(backgroundWaterGradientStrip, 0, i, currentColor); } /* * Build Background Gradient */ backgroundSkyGradientStrip = new Texture2D(Graphics.GraphicsDevice, 1, Graphics.PreferredBackBufferHeight / 2); startColor = new Color(61, 28, 111); finishColor = new Color(158, 98, 123); for (int i = 0; i < backgroundSkyGradientStrip.Height; i++) { float ratio = Math2.Map(i, 0f, backgroundSkyGradientStrip.Height, 0f, 1.0f); currentColor = Color.Lerp(startColor, finishColor, ratio); DrawMe.Pixel(backgroundSkyGradientStrip, 0, i, currentColor); } ContentLoaded = true; }