Ejemplo n.º 1
0
        /// <summary>
        /// Render the player sprite.  Should be invoked between
        /// SpriteBatch.Begin() and SpriteBatch.End()
        /// </summary>
        /// <param name="spriteBatch">The SpriteBatch to use</param>
        public void Draw(SpriteBatch spriteBatch)
        {
#if VISUAL_DEBUG
            VisualDebugging.DrawRectangle(spriteBatch, Bounds, Color.Red);
#endif
            frames[currentFrame].Draw(spriteBatch, Position, color, 0, origin, 2, spriteEffects, 1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
#if VISUAL_DEBUG
            VisualDebugging.LoadContent(Content);
#endif
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            var t = Content.Load <Texture2D>("spritesheet");
            sheet = new SpriteSheet(t, 21, 21, 3, 2);

            // Load the tilemap
            tilemap = Content.Load <Tilemap>("level1");

            // Create the player with the corresponding frames from the spritesheet
            var playerFrames = from index in Enumerable.Range(19, 30) select sheet[index];
            player = new Player(playerFrames);

            // Create the platforms
            platforms.Add(new Platform(new BoundingRectangle(80, 300, 105, 21), sheet[1]));
            platforms.Add(new Platform(new BoundingRectangle(280, 400, 84, 21), sheet[2]));
            platforms.Add(new Platform(new BoundingRectangle(160, 200, 42, 21), sheet[3]));

            // Add the platforms to the axis list
            world = new AxisList();
            foreach (Platform platform in platforms)
            {
                world.AddGameObject(platform);
            }

            tileset = Content.Load <Tileset>("tiledspritesheet");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Render the player sprite.  Should be invoked between
        /// SpriteBatch.Begin() and SpriteBatch.End()
        /// </summary>
        /// <param name="spriteBatch">The SpriteBatch to use</param>
        /// <param name="translationMatrix">Matrix used for translating the particles systems' Draw functions</param>
        public void Draw(SpriteBatch spriteBatch, Matrix translationMatrix)
        {
#if VISUAL_DEBUG
            VisualDebugging.DrawRectangle(spriteBatch, Bounds, Color.Red);
#endif
            frames[currentFrame].Draw(spriteBatch, Position, color, 0, origin, 2, spriteEffects, 1);
            coinParticles.Draw(translationMatrix);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Draws the platform
        /// </summary>
        /// <param name="spriteBatch">The spriteBatch to render to</param>
        public void Draw(SpriteBatch spriteBatch)
        {
#if VISUAL_DEBUG
            VisualDebugging.DrawRectangle(spriteBatch, bounds, Color.Green);
#endif
            for (int i = 0; i < tileCount; i++)
            {
                sprite.Draw(spriteBatch, new Vector2(bounds.X + i * sprite.Width, bounds.Y), Color.Purple);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Draws the platform
        /// </summary>
        /// <param name="spriteBatch">The spriteBatch to render to</param>
        public void Draw(SpriteBatch spriteBatch)
        {
#if VISUAL_DEBUG
            VisualDebugging.DrawRectangle(spriteBatch, bounds, Color.Green);
#endif
            if (active)
            {
                sprite.Draw(spriteBatch, bounds, Color.White);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            #if VISUAL_DEBUG
            VisualDebugging.LoadContent(Content);
            #endif
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            var t = Content.Load <Texture2D>("spritesheet");
            sheet = new SpriteSheet(t, 21, 21, 3, 2);

            // Create the player with the corresponding frames from the spritesheet
            var           playerFrames     = from index in Enumerable.Range(19, 30) select sheet[index];
            List <Sprite> playerFramesPlus = playerFrames.ToList();
            playerFramesPlus.Add(sheet[112]);
            player = new Player(playerFramesPlus);

            // Create the platforms
            platforms.Add(new Platform(new BoundingRectangle(160, 200, 63, 21), sheet[3]));
            platforms.Add(new Platform(new BoundingRectangle(349, 200, 63, 21), sheet[3]));
            platforms.Add(new Platform(new BoundingRectangle(233, 258, 105, 21), sheet[3]));
            platforms.Add(new Platform(new BoundingRectangle(538, 142, 84, 21), sheet[3]));
            platforms.Add(new Platform(new BoundingRectangle(811, 374, 84, 21), sheet[3]));

            tokens.Add(new Token(new BoundingRectangle(370, 179, 21, 21), sheet[115]));
            tokens.Add(new Token(new BoundingRectangle(570, 121, 21, 21), sheet[115]));
            tokens.Add(new Token(new BoundingRectangle(843, 353, 21, 21), sheet[115]));

            // Add the platforms to the axis list
            platformAxis = new AxisList();
            foreach (Platform platform in platforms)
            {
                platformAxis.AddGameObject(platform);
            }

            tokenAxis = new AxisList();
            foreach (Token token in tokens)
            {
                tokenAxis.AddGameObject(token);
            }

            lava = new Lava(sheet[13], sheet[42]);

            score = 0;

            gameText.LoadContent(Content);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
#if VISUAL_DEBUG
            VisualDebugging.LoadContent(Content);
#endif
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            var t = Content.Load <Texture2D>("spritesheet");
            sheet = new SpriteSheet(t, 21, 21, 3, 2);

            var r = Content.Load <Texture2D>("SaloonResized2");
            saloonSheet = new SpriteSheet(r, 596, 156, 0, 0);

            // Create the player with the corresponding frames from the spritesheet
            var playerFrames = from index in Enumerable.Range(79, 90) select sheet[index];
            player = new Player(playerFrames);

            //var buildingFrames = from index in Enumerable.Range(0, 0) select saloonSheet[index];


            // Create the platforms
            //platforms.Add(new Platform(new BoundingRectangle(80, 300, 105, 21), sheet[1]));
            //platforms.Add(new Platform(new BoundingRectangle(280, 400, 84, 21), sheet[2]));
            //platforms.Add(new Platform(new BoundingRectangle(160, 200, 42, 21), sheet[3]));
            platforms.Add(new Platform(new BoundingRectangle(0, 400, 600, 21), sheet[242]));           //Starting Platform
            platforms.Add(new Platform(new BoundingRectangle(575, 400, 600, 21), sheet[242]));         //Under Saloon Platform
            platforms.Add(new Platform(new BoundingRectangle(800, 150, 200, 21), sheet[1]));           //Upper Platform
            //platforms.Add(new Platform(new BoundingRectangle(575, 200, 50, 21), sheet[1])); //Jump Assist
            Platform saloon = new Platform(new BoundingRectangle(575, 255, 596, 300), saloonSheet[0]); //Saloon
            saloon.setBounds(100);
            platforms.Add(saloon);
            platforms.Add(new Platform(new BoundingRectangle(900, 130, 21, 21), sheet[18])); //Cactus
            //platforms.Add(new Platform(new BoundingRectangle(575, 225, 600, 150), saloonSheet[0]));



            // Add the platforms to the axis list
            world = new AxisList();
            foreach (Platform platform in platforms)
            {
                world.AddGameObject(platform);
            }

            tileset = Content.Load <Tileset>("tiledspritesheet");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
#if VISUAL_DEBUG
            VisualDebugging.LoadContent(Content);
#endif
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            var t = Content.Load <Texture2D>("spritesheet");
            sheet = new SpriteSheet(t, 21, 21, 3, 2);

            // Load the tilemap
            tilemap = Content.Load <Tilemap>("level2");

            SoundEffect tokenSound = Content.Load <SoundEffect>("PickupCoin");

            SoundEffect playerJump = Content.Load <SoundEffect>("Jump");
            SoundEffect playerHurt = Content.Load <SoundEffect>("Hurt");

            //Gets the texture for the particle systems and initializes them
            Texture2D texture = Content.Load <Texture2D>("Particle");
            playerDeathParticles = new ParticleSystem(GraphicsDevice, 1000, texture);
            playerDeathParticles.SpawnPerFrame = 20;

            ParticleSystem coinCollectParticles = new ParticleSystem(GraphicsDevice, 1000, texture);
            coinCollectParticles.SpawnPerFrame = 20;

            //Set the SpawnParticle method for the systems
            playerDeathParticles.SpawnParticle = (ref Particle particle) =>
            {
                Random random = new Random();
                particle.Position = new Vector2(player.Position.X, player.Position.Y - 20);
                particle.Velocity = new Vector2(
                    MathHelper.Lerp(-75, 75, (float)random.NextDouble()), //X between -75 and 75
                    MathHelper.Lerp(0, -150, (float)random.NextDouble())  //Y between 0 and -150
                    );
                particle.Acceleration = 0.1f * new Vector2(0, (float)random.NextDouble());
                particle.Color        = Color.Red;
                particle.Scale        = 1f;
                particle.Life         = 1.0f;
            };

            coinCollectParticles.SpawnParticle = (ref Particle particle) =>
            {
                Random random = new Random();
                particle.Position = coinCollectParticles.Emitter;
                particle.Velocity = new Vector2(
                    MathHelper.Lerp(-180, 180, (float)random.NextDouble()), //X between -180 and 180
                    MathHelper.Lerp(-180, 180, (float)random.NextDouble())  //Y between 180 and 180
                    );
                particle.Acceleration = new Vector2(0, 0);
                particle.Color        = Color.Gold;
                particle.Scale        = 0.5f;
                particle.Life         = 0.25f;
            };

            //Set the UpdateParticle method for the systems
            playerDeathParticles.UpdateParticle = (float deltaT, ref Particle particle) =>
            {
                particle.Velocity += deltaT * particle.Acceleration;
                particle.Position += deltaT * particle.Velocity;
                particle.Scale    -= deltaT;
                particle.Life     -= deltaT;
            };

            coinCollectParticles.UpdateParticle = playerDeathParticles.UpdateParticle;

            // Use the object groups to load in the tokens, platforms, and player spawn point
            foreach (ObjectGroup objectGroup in tilemap.ObjectGroups)
            {
                if (objectGroup.Name == "Coin Layer")
                {
                    foreach (GroupObject groupObject in objectGroup.Objects)
                    {
                        BoundingRectangle bounds = new BoundingRectangle(
                            groupObject.X,
                            groupObject.Y,
                            groupObject.Width,
                            groupObject.Height
                            );
                        tokens.Add(new Token(bounds, sheet[groupObject.SheetIndex - 1], tokenSound));
                    }
                    tokenAxis = new AxisList();
                    foreach (Token token in tokens)
                    {
                        tokenAxis.AddGameObject(token);
                    }
                }
                else if (objectGroup.Name == "Platform Layer")
                {
                    foreach (GroupObject groupObject in objectGroup.Objects)
                    {
                        BoundingRectangle bounds = new BoundingRectangle(
                            groupObject.X,
                            groupObject.Y,
                            groupObject.Width,
                            groupObject.Height
                            );
                        platforms.Add(new Platform(bounds, sheet[groupObject.SheetIndex - 1]));
                    }

                    platformAxis = new AxisList();
                    foreach (Platform platform in platforms)
                    {
                        platformAxis.AddGameObject(platform);
                    }
                }
                else if (objectGroup.Name == "Spawn Layer")
                {
                    GroupObject groupObject = objectGroup.Objects[0];
                    // Create the player with the corresponding frames from the spritesheet
                    var           playerFrames     = from index in Enumerable.Range(19, 11) select sheet[index];
                    List <Sprite> playerFramesList = playerFrames.ToList();
                    playerFramesList.Add(sheet[112]);
                    player = new Player(playerFramesList, groupObject.X, groupObject.Y, playerJump, playerHurt, coinCollectParticles);
                }
            }

            score = 0;

            // Loads the background texture, makes its Sprite, and creates its parallax layer
            var backgroundTexture = Content.Load <Texture2D>("background");
            var backgroundSprite  = new StaticSprite(backgroundTexture);
            var backgroundLayer   = new ParallaxLayer(this, player, 0.1f);
            backgroundLayer.Sprites.Add(backgroundSprite);
            backgroundLayer.DrawOrder = 0;
            Components.Add(backgroundLayer);

            // Loads the midground textures
            var midgroundTextures = new Texture2D[]
            {
                Content.Load <Texture2D>("midground1"),
                Content.Load <Texture2D>("midground2")
            };

            // Creates the midground sprites
            var midgroundSprites = new StaticSprite[]
            {
                new StaticSprite(midgroundTextures[0]),
                new StaticSprite(midgroundTextures[1], new Vector2(3500, 0))
            };

            // Creates the midground layer and initializes its controller
            var midgroundLayer = new ParallaxLayer(this, player, 0.4f);
            midgroundLayer.Sprites.AddRange(midgroundSprites);
            midgroundLayer.DrawOrder = 1;
            Components.Add(midgroundLayer);

            var birdTexture  = Content.Load <Texture2D>("birds");
            var birdsSprites = new StaticSprite(birdTexture);
            var birdsLayer   = new ParallaxLayer(this, 80f);
            birdsLayer.Sprites.Add(birdsSprites);
            birdsLayer.DrawOrder = 2;
            Components.Add(birdsLayer);

            gameText.LoadContent(Content);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
#if VISUAL_DEBUG
            VisualDebugging.LoadContent(Content);
#endif
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //load in spritefont
            spriteFont = Content.Load <SpriteFont>("File");

            // TODO: use this.Content to load your game content here
            var t = Content.Load <Texture2D>("spritesheet");
            sheet = new SpriteSheet(t, 21, 21, 1, 2);


            // Load the level
            tilemap = Content.Load <Tilemap>("level5");

            foreach (ObjectGroup objectGroup in tilemap.ObjectGroups)
            {
                if (objectGroup.Name == "Platforms") //create all of the tiles from the tile objects
                {
                    foreach (GroupObject groupObject in objectGroup.Objects)
                    {
                        BoundingRectangle bounds = new BoundingRectangle(
                            groupObject.X,
                            groupObject.Y,
                            groupObject.Width,
                            groupObject.Height
                            );
                        platforms.Add(new Platform(bounds, sheet[groupObject.SheetIndex - 1]));
                    }

                    world = new AxisList();
                    foreach (Platform platform in platforms)
                    {
                        world.AddGameObject(platform);
                    }
                }
                else if (objectGroup.Name == "Spawn")// give the player the starting point from the object
                {
                    GroupObject groupObject = objectGroup.Objects[0];
                    // Create the player with the corresponding frames from the spritesheet
                    var playerFrames = from index in Enumerable.Range(139, 150) select sheet[index];
                    //List<Sprite> playerFramesList = playerFrames.ToList();
                    //playerFramesList.Add(sheet[112]);
                    player = new Player(playerFrames, groupObject.X, groupObject.Y);
                }
                else if (objectGroup.Name == "Ghost")
                {
                    GroupObject groupObject = objectGroup.Objects[0];
                    var         GhostFrames = from index in Enumerable.Range(445, 449) select sheet[index];
                    ghost = new GhostEnemy(GhostFrames, player, groupObject.X, groupObject.Y);
                }
                else if (objectGroup.Name == "End") //get the ending location which will end the game
                {
                    GroupObject groupObject = objectGroup.Objects[0];
                    endX = groupObject.X;
                    endY = groupObject.Y;
                }
            }


            // Add the platforms to the axis list
            world = new AxisList();
            foreach (Platform platform in platforms)
            {
                world.AddGameObject(platform);
            }

            tileset = Content.Load <Tileset>("BetterSet2");

            // particle information for when player reaches the door

            NormalParticle              = Content.Load <Texture2D>("particle");
            DoorParticles               = new ParticleSystem(GraphicsDevice, 1000, NormalParticle);
            DoorParticles.Emitter       = new Vector2(100, 100);
            DoorParticles.SpawnPerFrame = 4;

            // Set the SpawnParticle method
            DoorParticles.SpawnParticle = (ref Particle particle) =>
            {
                particle.Position = new Vector2(player.Position.X, player.Position.Y);
                particle.Velocity = new Vector2(
                    MathHelper.Lerp(-200, 200, (float)random.NextDouble()),
                    MathHelper.Lerp(-200, 200, (float)random.NextDouble())
                    );
                particle.Acceleration = 2.0f * new Vector2(0, (float)-random.NextDouble());
                particle.Color        = Color.Gold;
                particle.Scale        = 1.5f;
                particle.Life         = 8.0f;
            };

            // Set the UpdateParticle method
            DoorParticles.UpdateParticle = (float deltaT, ref Particle particle) =>
            {
                particle.Velocity += deltaT * particle.Acceleration;
                particle.Position += deltaT * particle.Velocity;
                particle.Scale    -= deltaT;
                particle.Life     -= deltaT;
            };


            // particle info for rain
            RainParticle       = Content.Load <Texture2D>("rain drop");
            Rain               = new ParticleSystem(GraphicsDevice, 5000, RainParticle);
            Rain.Emitter       = new Vector2(100, 100);
            Rain.SpawnPerFrame = 4;

            // Set the SpawnParticle method
            Rain.SpawnParticle = (ref Particle particle) =>
            {
                particle.Position = new Vector2(
                    MathHelper.Lerp(0, 2100, (float)random.NextDouble()),
                    MathHelper.Lerp(0, 1, (float)random.NextDouble())
                    );
                particle.Velocity = new Vector2(
                    MathHelper.Lerp(0, 0, (float)random.NextDouble()),
                    MathHelper.Lerp(-100, -25, (float)random.NextDouble())
                    );
                particle.Acceleration = 0.0f * new Vector2(0, (float)-random.NextDouble());
                particle.Color        = Color.OrangeRed;
                particle.Scale        = 0.5f;
                particle.Life         = 200.0f;
            };

            // Set the UpdateParticle method
            Rain.UpdateParticle = (float deltaT, ref Particle particle) =>
            {
                particle.Velocity += deltaT * particle.Acceleration;
                particle.Position -= deltaT * particle.Velocity;
                //particle.Scale = particle.Scale;
                particle.Life -= deltaT;
            };


            // particle info for ghost
            FireParticle                 = Content.Load <Texture2D>("Fire");
            GhostParticles               = new ParticleSystem(GraphicsDevice, 1000, FireParticle);
            GhostParticles.Emitter       = new Vector2(100, 100);
            GhostParticles.SpawnPerFrame = 4;

            // Set the SpawnParticle method
            GhostParticles.SpawnParticle = (ref Particle particle) =>
            {
                particle.Position = new Vector2(
                    MathHelper.Lerp(ghost.Position.X - 42, ghost.Position.X, (float)random.NextDouble()),
                    MathHelper.Lerp(ghost.Position.Y - 42, ghost.Position.Y, (float)random.NextDouble())
                    );
                particle.Velocity = new Vector2(
                    MathHelper.Lerp(-50, 50, (float)random.NextDouble()),
                    MathHelper.Lerp(-50, 50, (float)random.NextDouble())
                    );
                particle.Acceleration = 1.0f * new Vector2(0, (float)-random.NextDouble());
                particle.Color        = Color.GhostWhite;
                particle.Scale        = 0.5f;
                particle.Life         = 0.5f;
            };

            // Set the UpdateParticle method
            GhostParticles.UpdateParticle = (float deltaT, ref Particle particle) =>
            {
                particle.Velocity += deltaT * particle.Acceleration;
                particle.Position += deltaT * particle.Velocity;
                particle.Scale    -= deltaT;
                particle.Life     -= deltaT;
            };

            // put player and ghost drawings on layer 2

            /*
             * var playerLayer = new ParallaxLayer(this);
             * playerLayer.Sprites.Add(player);
             * playerLayer.Sprites.Add(ghost);
             * playerLayer.DrawOrder = 3;
             * Components.Add(playerLayer);
             */

            //fireballs background drawing
            var FireTextures = new Texture2D[]
            {
                Content.Load <Texture2D>("FireBalls2")
            };

            var FireSprites = new StaticSprite[]
            {
                new StaticSprite(FireTextures[0]),
                new StaticSprite(FireTextures[0], new Vector2(500, 0)),
                new StaticSprite(FireTextures[0], new Vector2(1000, 0)),
                new StaticSprite(FireTextures[0], new Vector2(1500, 0)),
                new StaticSprite(FireTextures[0], new Vector2(2000, 0))
            };
            var FireLayer = new ParallaxLayer(this);
            FireLayer.Sprites.AddRange(FireSprites);
            FireLayer.DrawOrder = 2;
            Components.Add(FireLayer);


            //Cloud layer background Drawing
            var CloudTextures = new Texture2D[]
            {
                Content.Load <Texture2D>("Clouds2")
            };

            var CloudSprites = new StaticSprite[]
            {
                new StaticSprite(CloudTextures[0]),
                new StaticSprite(CloudTextures[0], new Vector2(500, 0)),
                new StaticSprite(CloudTextures[0], new Vector2(1000, 0)),
                new StaticSprite(CloudTextures[0], new Vector2(1500, 0)),
                new StaticSprite(CloudTextures[0], new Vector2(2000, 0))
            };

            var CloudLayer = new ParallaxLayer(this);
            CloudLayer.Sprites.AddRange(CloudSprites);
            CloudLayer.DrawOrder = 1;
            Components.Add(CloudLayer);

            //Mountain layer background Drawing
            var FlourTextures = new Texture2D[]
            {
                Content.Load <Texture2D>("Flours")
            };

            var FlourSprites = new StaticSprite[]
            {
                new StaticSprite(FlourTextures[0]),
                new StaticSprite(FlourTextures[0], new Vector2(500, 0)),
                new StaticSprite(FlourTextures[0], new Vector2(1000, 0)),
                new StaticSprite(FlourTextures[0], new Vector2(1500, 0)),
                new StaticSprite(FlourTextures[0], new Vector2(2000, 0))
            };

            var FlourLayer = new ParallaxLayer(this);
            FlourLayer.Sprites.AddRange(FlourSprites);
            FlourLayer.DrawOrder = 0;
            Components.Add(FlourLayer);


            //speeds of each background and character layer
            FlourLayer.ScrollController = new PlayerTrackingScrollController(player, 0.1f);
            CloudLayer.ScrollController = new PlayerTrackingScrollController(player, 0.4f);
            //playerLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f);
            FireLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f);
        }