Esempio n. 1
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);
        }
Esempio 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>("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);
        }