Exemplo n.º 1
0
        /*
         * SERIOUS MEMORY LEAK HERE!
         */
        void DrawBodyShape(Sprite sprite, SpriteBatch spriteBatch, Color color)
        {
            Texture2D texture = new Texture2D(Graphics.GraphicsDevice, (int)sprite.Body.CollisionRect.Width, (int)sprite.Body.CollisionRect.Height);

            DrawMe.Fill(texture, color);

            spriteBatch.Draw(texture, sprite.Body.CollisionRect.Position, Color.White);
        }
Exemplo n.º 2
0
        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");
            song               = content.Load <Song>("InkStuff");
            MediaPlayer.Volume = 0.3f;
            MediaPlayer.Play(song);
            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"));

            /*
             * Player init
             */
            player = new Player(this, tilemapTexture, Vector2.Zero, 32, 32, true);
            /*player.Animations.CurrentFrame = new Frame(96, 176, 16, 32);*/ // woman
            player.Animations.CurrentFrame = new Frame(16, 64, 32, 32);      // actual player
            //player.Animations.Add("shooting", new int[] { 147, 149, 151, 153, 155}, 6, true);
            //player.Animations.Add("woman-run", new int[] { 183, 184, 185, 186, 187, 188 }, 12, true);
            player.Body.X = 16 * 440; /*330*/   //spawn x
            player.Body.Y = 16 * 3;             //spawn y
            player.Body.SetSize(16, 32, 0, 0);  // woman
            player.Body.SetSize(10, 26, 11, 3); // actual player

            //player.Animations.Play("woman-run");

            /*
             * Level init
             */
            XMLLevelLoader XMLloader = new XMLLevelLoader();

            level = XMLloader.LoadLevel(this, @"Content\Level1.tmx", tilemapTexture);
            level.SetCollisionTiles(new int[] { 2, 33, 34, 35, 47, 66, });


            /*
             * 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);


                    // 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);

                    Console.WriteLine("added jelly");
                }
                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);


                    // 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);

                    Console.WriteLine("added puffer");
                }

                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")
                {
                    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);



                    Console.WriteLine("added particles");
                }
                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")));
                }
            }


            // build spikes tiles list
            spikesPointingDown = level.GetTilesListByID(new int[] { 514 });
            spikesPointingUp   = level.GetTilesListByID(new int[] { 515 });

            foreach (Tile spike in spikesPointingDown)
            {
                spike.Body.SetSize(12, 6, 1, 0);
            }
            foreach (Tile spike in spikesPointingUp)
            {
                spike.Body.SetSize(12, 6, 2, 10);
            }

            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, 32 + 4), 256, 16, new Color(255, 0, 0));

            /*
             * 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;
        }
Exemplo n.º 3
0
        public override void LoadContent()
        {
            base.LoadContent();
            MediaPlayer.Stop();

            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-jn");

            /*
             * Player Health & Energy
             */
            texturePlayerHealth = this.content.Load <Texture2D>("HeartDraft");
            texturePlayerEnergy = this.content.Load <Texture2D>("EnergyBar");

            /*
             * 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"));

            /*
             * Player init
             */
            player = new Player(this, tilemapTexture, Vector2.Zero, 32, 32, true);
            player.Animations.CurrentFrame = new Frame(96, 176, 16, 32); // woman
            player.Animations.CurrentFrame = new Frame(0, 144, 32, 32);  // actual player
            //player.Animations.Add("robot-idle", new int[] { 177, 178, 179, 180, 181, 182 }, 6, false, true);
            //player.Animations.Add("woman-run", new int[] { 183, 184, 185, 186, 187, 188 }, 12, true);
            player.Body.X = 16 * 7;
            player.Body.Y = 16 * 5;
            player.Body.SetSize(16, 32, 0, 0);  // woman
            player.Body.SetSize(10, 26, 11, 3); // actual player
            Karma.maxKarma          = 0;
            Karma.playerShotsFired  = 0;
            Karma.playerTotalDamage = 0f;
            Karma.playerCollect     = 0;

            //player.Animations.Play("woman-run");

            /*
             * Level init
             */
            XMLLevelLoader XMLloader = new XMLLevelLoader();

            level = XMLloader.LoadLevel(this, @"Content\featureTestMap.tmx", tilemapTexture);
            level.SetCollisionTiles(new int[] { 1, 2, 17, 18, 33, 34 });


            /*
             * 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);
                    j.Animations.CurrentFrame = new Frame(48, 112, 16, 32);

                    enemies.Add(j);
                    Karma.maxKarma = Karma.DefineMaxKarma(Karma.maxKarma, j.Health);

                    Console.WriteLine("added jelly");
                }
                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);
                    p.Animations.CurrentFrame = new Frame(0, 112, 32, 32);

                    enemies.Add(p);
                    Karma.maxKarma = Karma.DefineMaxKarma(Karma.maxKarma, p.Health);

                    Console.WriteLine("added puffer");
                }
                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);

                    enemies.Add(p);
                    Karma.maxKarma = Karma.DefineMaxKarma(Karma.maxKarma, p.Health);

                    Console.WriteLine("added turtlex");
                }
                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")
                {
                    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(3 * 16, 6 * 16, 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);



                    Console.WriteLine("added particles");
                }
                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")));
                }
            }

            // build spikes tiles list
            spikesPointingDown = level.GetTilesListByID(new int[] { 97 });
            spikesPointingUp   = level.GetTilesListByID(new int[] { 98 });

            foreach (Tile spike in spikesPointingDown)
            {
                spike.Body.SetSize(12, 6, 2, 0);
            }
            foreach (Tile spike in spikesPointingUp)
            {
                spike.Body.SetSize(12, 6, 2, 10);
            }

            topWaterTiles = level.GetTilesListByID(new int[] { 49, 50, 51 });

            /*
             * UI Elements init
             */
            energyBar   = new EnergyBar(Graphics, new Vector2(16, 32 + 4), 64, 8, new Color(255, 0, 0));
            Karma.karma = Karma.maxKarma;

            /*
             * 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;
        }
Exemplo n.º 4
0
        public override void LoadContent()
        {
            base.LoadContent();

            Camera      = new Camera2D(Vector2.Zero);
            Camera.Zoom = 2.45f;

            font           = content.Load <SpriteFont>("Font");
            tilemapTexture = this.content.Load <Texture2D>("spritesheet-jn");

            /*
             * Level init
             */
            XMLLevelLoader XMLloader = new XMLLevelLoader();

            level = XMLloader.LoadLevel(this, @"Content\tiledObjectTest.tmx", tilemapTexture);
            level.SetCollisionTiles(new int[] { 1, 2, 17, 18, 33, 34 });

            /*
             * Enemies init
             */
            foreach (TiledObject obj in level.Objects)
            {
                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);
                    j.Animations.CurrentFrame = new Frame(48, 112, 16, 32, 0);

                    enemies.Add(j);

                    Console.WriteLine("added jelly");
                }
                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);
                    p.Animations.CurrentFrame = new Frame(0, 112, 32, 32, 0);

                    enemies.Add(p);

                    Console.WriteLine("added puffer");
                }
            }

            /*
             * Player init
             */

            player = new Player(this, tilemapTexture, new Vector2(0, 0), 16, 32, true);
            player.Animations.CurrentFrame = new Frame(96, 176, 16, 32);
            player.Animations.Add("robot-idle", new int[] { 177, 178, 179, 180, 181, 182 }, 6, false, true);
            player.Animations.Add("woman-run", new int[] { 183, 184, 185, 186, 187, 188 }, 12, true);
            player.Body.X           = 0;
            player.Body.Y           = 0;
            player.Body.MaxVelocity = 3f;
            player.Body.Drag.X      = 0.6f;
            player.Body.Enabled     = true;
            player.Body.Tag         = "player";
            player.Body.SetSize(16, 32, 0, 0);


            /*
             * Build Background Gradient
             */
            backgroundGradientStrip = 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 < backgroundGradientStrip.Height; i++)
            {
                float ratio = Math2.Map(i, 0f, backgroundGradientStrip.Height, 0f, 1.0f);

                currentColor = Color.Lerp(startColor, finishColor, ratio);
                DrawMe.Pixel(backgroundGradientStrip, 0, i, currentColor);
            }

            emitter1 = new ParticleEmitter(this, Graphics.PreferredBackBufferWidth / 2, Graphics.PreferredBackBufferWidth / 2, 512);
            //emitter1.MakeParticles(tilemapTexture, 16, 16);
            //emitter1.SetTextureCropRectangle(new Rectangle(48, 96, 16, 16));
            emitter1.ParseTextureToParticles(tilemapTexture, 0, 0, 16, 32, 4, 4);
            emitter1.ParticleVelocity        = new Vector2(0, 0f);
            emitter1.XVelocityVariationRange = new Vector2(-10f, 10f);
            emitter1.YVelocityVariationRange = new Vector2(-30f, 0f);
            emitter1.EmitterBox.X            = 0;
            //emitter1.EmitterBox.Y = level.Height * level.TileHeight;
            emitter1.EmitterBox.Y = 0;
            //emitter1.EmitterBox.Resize(level.Width * level.TileWidth, 1f);
            emitter1.EmitterBox.Resize(1f, 1f);
            emitter1.SpawnRate = 0f;
            emitter1.ParticleLifespanMilliseconds          = 5000f;
            emitter1.ParticleLifespanVariationMilliseconds = 500f;
            emitter1.Burst = false;
            //emitter1.Burst = true;
            emitter1.ParticlesPerBurst = 512;
            emitter1.InitialScale      = 1.0f;
            emitter1.FinalScale        = 0.1f;
            //emitter1.RandomizeParticlePositions = false;

            emitter1.SetAcceleration(0.0f, -0.01f);

            //emitter1.ForEachParticle(TintBlue);

            //playerDeathEmitter = new ParticleEmitter(this, 0, 0);

            ContentLoaded = true;
        }
Exemplo n.º 5
0
        public override void LoadContent()
        {
            base.LoadContent();
            MediaPlayer.Stop();

            camera      = new Camera2D(Vector2.Zero);
            camera.Zoom = 2.45f;

            font           = content.Load <SpriteFont>("Font");
            tilemapTexture = this.content.Load <Texture2D>("SpriteSheetDraft");

            /*
             * A single pixel to draw lines and stuff
             */
            pixel = new Texture2D(Graphics.GraphicsDevice, 1, 1);
            DrawMe.Fill(pixel, Color.White);

            /*
             * Player init
             */
            player = new Player(Graphics, tilemapTexture, Vector2.Zero, 32, 32, true);
            player.TextureBoundingRect = new Rectangle(96, 0, 32, 32);
            player.Body.X           = 16 * 3;
            player.Body.Y           = 16 * 3;
            player.Body.MaxVelocity = 3f;
            player.Body.Drag.X      = 0.6f;
            player.Body.Enabled     = true;
            player.Body.Tag         = "player";
            player.Body.SetSize(16, 29, 9, 2);

            /*
             * Enemies
             */

            enemies.Add(new PufferFish(Graphics, tilemapTexture, new Vector2(149 * 16, 11 * 16), 32, 32, 174 * 16 - 149 * 16, 1.5f));
            enemies.Add(new PufferFish(Graphics, tilemapTexture, new Vector2(150 * 16, 2 * 16), 32, 32, 174 * 16 - 150 * 16, 1.5f));
            enemies.Add(new PufferFish(Graphics, tilemapTexture, new Vector2(191 * 16, 2 * 16), 32, 32, 210 * 16 - 191 * 16, 1.5f));
            enemies.Add(new PufferFish(Graphics, tilemapTexture, new Vector2(181 * 16, 11 * 16), 32, 32, 210 * 16 - 181 * 16, 1.5f));
            enemies.Add(new PufferFish(Graphics, tilemapTexture, new Vector2(219 * 16, 5 * 16), 32, 32, 235 * 16 - 219 * 16, 1.5f));

            enemies.Add(new JellyFish(Graphics, tilemapTexture, Vector2.Zero, 16, 32, new Vector2(60 * 16, 6 * 16), new Vector2(4 * 16, 4 * 16), 0.5f));
            enemies.Add(new JellyFish(Graphics, tilemapTexture, Vector2.Zero, 16, 32, new Vector2(120 * 16, 6 * 16), new Vector2(10 * 16, 5 * 16), 0.5f));

            /*
             * Level init
             */
            XMLLevelLoader XMLloader = new XMLLevelLoader();

            level = XMLloader.LoadLevel(@"Content\prototipo.tmx", tilemapTexture);
            level.SetCollisionTiles(new int[] { 1, 2, 4, 6 });

            // build spikes tiles list
            spikesPointingDown = level.GetTilesListByID(new int[] { 3 });
            spikesPointingUp   = level.GetTilesListByID(new int[] { 5 });

            foreach (Tile spike in spikesPointingDown)
            {
                spike.Body.SetSize(12, 6, 2, 0);
            }
            foreach (Tile spike in spikesPointingUp)
            {
                spike.Body.SetSize(12, 6, 2, 10);
            }

            /*
             * 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, 32 + 4), 256, 16, new Color(255, 0, 0));

            /*
             * Build Background Gradient
             */
            backgroundGradientStrip = 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 < backgroundGradientStrip.Height; i++)
            {
                float ratio = Math2.Map(i, 0f, backgroundGradientStrip.Height, 0f, 1.0f);

                currentColor = Color.Lerp(startColor, finishColor, ratio);
                DrawMe.Pixel(backgroundGradientStrip, 0, i, currentColor);
            }

            ContentLoaded = true;
        }
Exemplo n.º 6
0
        public override void LoadContent()
        {
            base.LoadContent();

            Camera      = new Camera2D(Vector2.Zero);
            Camera.Zoom = 2.45f;

            font           = content.Load <SpriteFont>("Font");
            tilemapTexture = this.content.Load <Texture2D>("spritesheet-jn");

            /*
             * Level init
             */
            XMLLevelLoader XMLloader = new XMLLevelLoader();

            level = XMLloader.LoadLevel(this, @"Content\tiledObjectTest.tmx", tilemapTexture);
            level.SetCollisionTiles(new int[] { 1, 2, 17, 18, 33, 34 });

            /*
             * Enemies init
             */
            foreach (TiledObject obj in level.Objects)
            {
                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);
                    j.Animations.CurrentFrame = new Frame(48, 112, 16, 32, 0);

                    enemies.Add(j);

                    Console.WriteLine("added jelly");
                }
                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);
                    p.Animations.CurrentFrame = new Frame(0, 112, 32, 32, 0);

                    enemies.Add(p);

                    Console.WriteLine("added puffer");
                }
            }

            /*
             * Player init
             */

            player = new Player(this, tilemapTexture, new Vector2(0, 0), 16, 32, true);
            player.Animations.CurrentFrame = new Frame(96, 176, 16, 32);
            player.Animations.Add("robot-idle", new int[] { 177, 178, 179, 180, 181, 182 }, 6, false, true);
            player.Animations.Add("woman-run", new int[] { 183, 184, 185, 186, 187, 188 }, 12, true);
            player.Body.X           = 15 * 16;
            player.Body.Y           = 8 * 16;
            player.Body.MaxVelocity = 3f;
            player.Body.Drag.X      = 0.6f;
            player.Body.Enabled     = true;
            player.Body.Tag         = "player";
            player.Body.SetSize(16, 32, 0, 0);


            /*
             * Build Background Gradient
             */
            backgroundGradientStrip = 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 < backgroundGradientStrip.Height; i++)
            {
                float ratio = Math2.Map(i, 0f, backgroundGradientStrip.Height, 0f, 1.0f);

                currentColor = Color.Lerp(startColor, finishColor, ratio);
                DrawMe.Pixel(backgroundGradientStrip, 0, i, currentColor);
            }

            ContentLoaded = true;
        }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
        public override void LoadContent()
        {
            base.LoadContent();
            MediaPlayer.Stop();

            camera      = new Camera2D(Vector2.Zero);
            camera.Zoom = 4.85f;

            font           = content.Load <SpriteFont>("Font");
            tilemapTexture = this.content.Load <Texture2D>("SpriteSheetDraft");

            /*
             * A single pixel to draw lines and stuff
             */
            pixel = new Texture2D(Graphics.GraphicsDevice, 1, 1);
            DrawMe.Fill(pixel, Color.White);

            /*
             * Player init
             */
            player = new Player(this, tilemapTexture, Vector2.Zero, 32, 32, true);
            player.Animations.CurrentFrame = new Frame(96, 0, 32, 32);
            player.Body.X           = 16 * 3; /*330*/ //spawn x
            player.Body.Y           = 16 * 3;         //spawn y
            player.Body.MaxVelocity = 3f;
            player.Body.Drag.X      = 0.7f;
            player.Body.Enabled     = true;
            player.Body.Tag         = "player";
            player.Body.SetSize(11, 27, 10, 2);

            /*
             * Enemies
             */
            enemies.Add(new TurtleX(this, tilemapTexture, new Vector2(20 * 16, 8 * 16), 32, 32, 5 * 16, 174 * 16 - 149 * 16, 1.5f));

            pufferFish.Add(new PufferFish(this, tilemapTexture, new Vector2(149 * 16, 11 * 16), 32, 32, 174 * 16 - 149 * 16, 1.5f));
            pufferFish.Add(new PufferFish(this, tilemapTexture, new Vector2(150 * 16, 2 * 16), 32, 32, 174 * 16 - 150 * 16, 1.5f));
            pufferFish.Add(new PufferFish(this, tilemapTexture, new Vector2(191 * 16, 2 * 16), 32, 32, 210 * 16 - 191 * 16, 1.5f));
            pufferFish.Add(new PufferFish(this, tilemapTexture, new Vector2(181 * 16, 11 * 16), 32, 32, 210 * 16 - 181 * 16, 1.5f));
            pufferFish.Add(new PufferFish(this, tilemapTexture, new Vector2(219 * 16, 5 * 16), 32, 32, 235 * 16 - 219 * 16, 1.5f));

            enemies.Add(new JellyFish(this, tilemapTexture, Vector2.Zero, 16, 32, new Vector2(60 * 16, 6 * 16), new Vector2(4 * 16, 4 * 16), 0.5f));
            enemies.Add(new JellyFish(this, tilemapTexture, Vector2.Zero, 16, 32, new Vector2(120 * 16, 6 * 16), new Vector2(10 * 16, 5 * 16), 0.5f));

            /*
             * Level init
             */
            XMLLevelLoader XMLloader = new XMLLevelLoader();

            level = XMLloader.LoadLevel(this, @"Content\prototipo.tmx", tilemapTexture);
            level.SetCollisionTiles(new int[] { 1, 2, 4, 6 });

            /*
             * Enemies Init tiled
             */

            foreach (TiledObject obj in level.Objects)
            {
                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);
                    j.TextureBoundingRect = new Rectangle(192, 0, 16, 32);

                    enemies.Add(j);

                    Console.WriteLine("added jelly");
                }
                else if (obj.Name.ToLower() == "pufferfish")
                {
                    Vector2 position = new Vector2(obj.X, obj.Y);

                    float speed            = float.Parse(obj.GetProperty("speed"));
                    int   walkingDirection = int.Parse(obj.GetProperty("direction"));

                    PufferFish p = new PufferFish(this, tilemapTexture, position, 32, 32, obj.Width, speed);
                    //if (walkingDirection == 1)
                    //{
                    //    p.Body.X += obj.Width;
                    //    p.CurrentDistance = obj.Width;
                    //    p.FacingDirection = -1;
                    //}

                    p.TextureBoundingRect = new Rectangle(9 * 16, 0, 32, 32);



                    enemies.Add(p);

                    Console.WriteLine("added puffer");
                }
            }
            //

            // build spikes tiles list
            spikesPointingDown = level.GetTilesListByID(new int[] { 3 });
            spikesPointingUp   = level.GetTilesListByID(new int[] { 5 });
            //spikesPointingRight = level.GetTilesListByID(new int[] { 35 }); lvl2

            foreach (Tile spike in spikesPointingDown)
            {
                spike.Body.SetSize(5, 6, 6, 0);
            }
            foreach (Tile spike in spikesPointingUp)
            {
                spike.Body.SetSize(5, 6, 6, 10);
            }

            //foreach (Tile spike in spikesPointingRight)
            //{
            //    spike.Body.SetSize(6, 12, 0, 2); dar tweaks ao offset
            //}

            /*
             * 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, 32 + 4), 256, 16, new Color(255, 0, 0));

            /*
             * Build Background Gradient
             */
            backgroundGradientStrip = 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 < backgroundGradientStrip.Height; i++)
            {
                float ratio = Math2.Map(i, 0f, backgroundGradientStrip.Height, 0f, 1.0f);

                currentColor = Color.Lerp(startColor, finishColor, ratio);
                DrawMe.Pixel(backgroundGradientStrip, 0, i, currentColor);
            }

            ContentLoaded = true;
        }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
        public override void LoadContent()
        {
            base.LoadContent();

            camera      = new Camera2D(new Vector2(12 * 16, 12 * 16));
            camera.Zoom = 2.45f;

            font           = content.Load <SpriteFont>("Font");
            tilemapTexture = this.content.Load <Texture2D>("SpriteSheet");

            MediaPlayer.Volume = 0.3f;
            MediaPlayer.Play(Globals.JingleSong);
            MediaPlayer.IsRepeating = false;


            for (int i = 0; i < Graphics.PreferredBackBufferWidth; i += 16)
            {
                Sprite s = new Sprite(this, tilemapTexture, new Vector2(i, 0), 16, 16);
                s.Animations.CurrentFrame = new Frame(16, 0, 16, 16);

                topTiles.Add(s);

                s = new Sprite(this, tilemapTexture, new Vector2(i, Graphics.PreferredBackBufferHeight / camera.Zoom - 32 - 4), 16, 16);
                s.Animations.CurrentFrame = new Frame(16, 0, 16, 16);

                bottomTiles.Add(s);
            }


            // build boxes
            Sprite box = new Sprite(this, tilemapTexture, new Vector2(16 * 2, 16 * 5), 96 + 16, 32);

            box.Animations.CurrentFrame = new Frame(160, 288, 96 + 16, 32);
            boxes.Add(box);

            box = new Sprite(this, tilemapTexture, new Vector2(16 * 2, 16 * 8), 96 + 16, 32);
            box.Animations.CurrentFrame = new Frame(160, 288, 96 + 16, 32);
            boxes.Add(box);

            box = new Sprite(this, tilemapTexture, new Vector2(16 * 2, 16 * 11), 96 + 16, 32);
            box.Animations.CurrentFrame = new Frame(160, 288, 96 + 16, 32);
            boxes.Add(box);

            ///*
            // * Level init
            // */
            //XMLLevelLoader XMLloader = new XMLLevelLoader();

            //// se o load do mapa falhar, well shit. vai para o menu.
            //try
            //{
            //    level = XMLloader.LoadLevel(this, @"Content\KarmaScreen.tmx", tilemapTexture);

            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine("Error Loading Map. Error message: " + e.Message);

            //    StateManager.Instance.StartGameState("MenuState");

            //}

            /*
             * Build Background Gradient
             */
            backgroundWaterGradientStrip = new Texture2D(Graphics.GraphicsDevice, 1, Graphics.PreferredBackBufferHeight / 2);

            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;
        }