Beispiel #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()
        {
            // 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
            // city background
            var backgroundTexture = Content.Load <Texture2D>("city");
            var backgroundSprite  = new StaticSprite(backgroundTexture);
            var backgroundLayer   = new ParallaxLayer(this);

            backgroundLayer.Sprites.Add(backgroundSprite);
            backgroundLayer.DrawOrder = 1;
            Components.Add(backgroundLayer);

            // city midground
            var midTexture = Content.Load <Texture2D>("city2");
            var midSprite  = new StaticSprite(midTexture, new Vector2(0, 240));
            var midLayer   = new ParallaxLayer(this);

            midLayer.Sprites.Add(midSprite);
            midLayer.ScrollController.Speed = 40f;
            midLayer.DrawOrder = 2;
            Components.Add(midLayer);

            // plane
            plane = new Player(Content.Load <Texture2D>("plane"),
                               new Vector2(0, 240),
                               new Rectangle {
                X = 0, Y = 0, Width = 200, Height = 109
            });
            plane.UpdateDirection = () =>
            {
                Vector2 direction = Vector2.Zero;
                var     keyboard  = Keyboard.GetState();
                var     s         = 5;
                if (keyboard.IsKeyDown(Keys.Left))
                {
                    direction.X -= s;
                }
                if (keyboard.IsKeyDown(Keys.Right))
                {
                    direction.X += s;
                }
                if (keyboard.IsKeyDown(Keys.Up))
                {
                    direction.Y -= s;
                }
                if (keyboard.IsKeyDown(Keys.Down))
                {
                    direction.Y += s;
                }
                return(direction);
            };
            var planeLayer = new ParallaxLayer(this);

            planeLayer.Sprites.Add(plane);
            planeLayer.DrawOrder = 3;
            Components.Add(planeLayer);

            // viruses
            var virusLayer = new ParallaxLayer(this);
            var r          = new Random();

            for (var i = 0; i < viruses.Length; i++)
            {
                viruses[i] = new Player(Content.Load <Texture2D>("virus"),
                                        new Vector2(r.Next(400, 800), r.Next(480)),
                                        new Rectangle {
                    X = 0, Y = 0, Width = 34, Height = 34
                });
                viruses[i].UpdateDirection = () =>
                {
                    return(new Vector2(-2, 0));
                };
                virusLayer.Sprites.Add(viruses[i]);
            }
            virusLayer.DrawOrder = 4;
            Components.Add(virusLayer);

            gameOverTexture = Content.Load <Texture2D>("gameOver");
            gameOver        = false;
        }
Beispiel #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()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            pixel      = Content.Load <Texture2D>("Sprites/Pixel");
            circle     = Content.Load <Texture2D>("Sprites/Circle");
            spriteFont = Content.Load <SpriteFont>("Fonts/MangaTemple18");

            // Set up Parallax
            var backgroundTexture = Content.Load <Texture2D>("Parallax/Background");
            var backgroundSprite  = new StaticSprite(backgroundTexture);
            var backgroundLayer   = new ParallaxLayer(this);

            backgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.1f);
            backgroundLayer.Sprites.Add(backgroundSprite);
            backgroundLayer.DrawOrder = 0;

            var midgroundTextures = new Texture2D[]
            {
                Content.Load <Texture2D>("Parallax/Midground1"),
                Content.Load <Texture2D>("Parallax/Midground2")
            };
            var midgroundSprites = new StaticSprite[]
            {
                new StaticSprite(midgroundTextures[0]),
                new StaticSprite(midgroundTextures[1], new Vector2(3500, 0))
            };
            var midgroundLayer = new ParallaxLayer(this);

            midgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.4f);
            midgroundLayer.Sprites.AddRange(midgroundSprites);
            midgroundLayer.DrawOrder = 1;

            var gameLayer = new ParallaxLayer(this);

            gameLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f);
            gameLayer.Sprites.Add(player);
            gameLayer.DrawOrder = 2;


            Components.Add(backgroundLayer);
            Components.Add(midgroundLayer);
            Components.Add(gameLayer);

            //Levels.Add(Content.Load<Level>("Levels/Level1"));
            //Levels.Add(Content.Load<Level>("Levels/Level2"));
            //Levels.Add(Content.Load<Level>("Levels/Level3"));
            //foreach (Level level in Levels) level.SetGame(this);
            //((Level)Levels[0]).LoadLevel();

            Level lv = Content.Load <Level>("Levels/Level1");

            lv.SetGame(this);
            lv.LoadLevel();

            player.LoadContent();

            GameObject.GameObjectIterator(GameObjects, (obj) => {
                gameLayer.Sprites.Add(obj);
                obj.LoadContent();
            });
        }
Beispiel #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch   = new SpriteBatch(GraphicsDevice);
            font          = Content.Load <SpriteFont>("Points");
            coinPickupSFX = Content.Load <SoundEffect>("coinPickupSound");

            // TODO: use this.Content to load your game content here
            ball.LoadContent(Content);
            coin.LoadContent(Content);
            paddle.LoadContent(Content);

            smokeTexture        = Content.Load <Texture2D>("smoke");
            smokeParticleSystem = new ParticleSystem(GraphicsDevice, 1000, smokeTexture);
            smokeParticleSystem.SpawnPerFrame = 4;

            // Set the SpawnParticle method
            smokeParticleSystem.SpawnParticle = (ref Particle particle) =>
            {
                particle.Position = new Vector2(ball.bounds.X, ball.bounds.Y);
                particle.Velocity = new Vector2(
                    MathHelper.Lerp(-50, 50, (float)rand.NextDouble()), // X between -50 and 50
                    MathHelper.Lerp(0, 100, (float)rand.NextDouble())   // Y between 0 and 100
                    );
                particle.Acceleration = 0.1f * new Vector2(0, (float)-rand.NextDouble());
                particle.Color        = Color.Gold;
                particle.Scale        = 1f;
                particle.Life         = 1.0f;
            };

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

            //////////////////COIN

            coinSparkTexture   = Content.Load <Texture2D>("pixelYellow");
            coinParticleSystem = new ParticleSystem(GraphicsDevice, 1000, coinSparkTexture);
            coinParticleSystem.SpawnPerFrame = 4;

            // Set the SpawnParticle method
            coinParticleSystem.SpawnParticle = (ref Particle particle) =>
            {
                particle.Position = new Vector2(coin.bounds.X, coin.bounds.Y);
                particle.Velocity = new Vector2(
                    MathHelper.Lerp(-70, 70, (float)rand.NextDouble()), // X between -50 and 50
                    MathHelper.Lerp(60, -60, (float)rand.NextDouble())  // Y between 0 and 100
                    );
                particle.Acceleration = 0.1f * new Vector2(0, (float)-rand.NextDouble() / 2);
                particle.Color        = Color.Gold;
                particle.Scale        = 2f;
                particle.Life         = 0.85f;
            };

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

            ///////////////////PLAYER TRAIL

            playerParticleTexture = Content.Load <Texture2D>("pixelWhite");
            playerParticleSystem  = new ParticleSystem(GraphicsDevice, 1000, playerParticleTexture);
            playerParticleSystem.SpawnPerFrame = 16;

            // Set the SpawnParticle method
            playerParticleSystem.SpawnParticle = (ref Particle particle) =>
            {
                particle.Position = new Vector2(paddle.bounds.X, paddle.bounds.Y);
                particle.Velocity = new Vector2(
                    MathHelper.Lerp(-5, 5, (float)rand.NextDouble()), // X between -50 and 50
                    MathHelper.Lerp(-5, 5, (float)rand.NextDouble())  // Y between 0 and 100
                    );
                particle.Acceleration = 0.1f * new Vector2(0, (float)-rand.NextDouble());
                particle.Color        = Color.Gold;
                particle.Scale        = 2f;
                particle.Life         = 2.0f;
            };

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



            var backgroundTexture = Content.Load <Texture2D>("mountainBACK1");
            var backgroundSprite  = new StaticSprite(backgroundTexture);
            var backgroundLayer   = new ParallaxLayer(this);

            backgroundLayer.Sprites.Add(backgroundSprite);
            backgroundLayer.DrawOrder = 0;
            Components.Add(backgroundLayer);


            var cloudTexture = Content.Load <Texture2D>("clouds2");
            var cloudSprite  = new StaticSprite(cloudTexture);
            var cloudLayer   = new ParallaxLayer(this);

            cloudLayer.Sprites.Add(cloudSprite);
            cloudLayer.DrawOrder = 1;
            Components.Add(cloudLayer);


            var landTexture = Content.Load <Texture2D>("land3");
            var landSprite  = new StaticSprite(landTexture);
            var landLayer   = new ParallaxLayer(this);

            landLayer.Sprites.Add(landSprite);
            landLayer.DrawOrder = 2;
            Components.Add(landLayer);

            var topBTexture = Content.Load <Texture2D>("topbleachers4");
            var topBSprite  = new StaticSprite(topBTexture);
            var topBLayer   = new ParallaxLayer(this);

            topBLayer.Sprites.Add(topBSprite);
            topBLayer.DrawOrder = 3;
            Components.Add(topBLayer);

            var midBTexture = Content.Load <Texture2D>("middlebleachers5");
            var midBSprite  = new StaticSprite(midBTexture);
            var midBLayer   = new ParallaxLayer(this);

            midBLayer.Sprites.Add(midBSprite);
            midBLayer.DrawOrder = 4;
            Components.Add(midBLayer);

            var botBTexture = Content.Load <Texture2D>("bottombleachers6");
            var botBSprite  = new StaticSprite(botBTexture);
            var botBLayer   = new ParallaxLayer(this);

            botBLayer.Sprites.Add(botBSprite);
            botBLayer.DrawOrder = 5;
            Components.Add(botBLayer);



            backgroundLayer.ScrollController = new PlayerTrackingScrollController(paddle, 0.1f);
            cloudLayer.ScrollController      = new PlayerTrackingScrollController(paddle, 0.2f);
            landLayer.ScrollController       = new PlayerTrackingScrollController(paddle, 0.4f);
            topBLayer.ScrollController       = new PlayerTrackingScrollController(paddle, 0.6f);
            midBLayer.ScrollController       = new PlayerTrackingScrollController(paddle, 0.8f);
            botBLayer.ScrollController       = new PlayerTrackingScrollController(paddle, 1.0f);
        }
Beispiel #4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);


            var backgroundTexture = Content.Load <Texture2D>("background");
            var backgroundSprite  = new StaticSprite(backgroundTexture);
            var backgroundLayer   = new ParallaxLayer(this);

            backgroundLayer.Sprites.Add(backgroundSprite);
            backgroundLayer.DrawOrder = 0;
            Components.Add(backgroundLayer);


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



            var midgroundTextures = new Texture2D[]
            {
                Content.Load <Texture2D>("midground1"),
                Content.Load <Texture2D>("midground2")
            };
            var midgroundSprites = new StaticSprite[]
            {
                new StaticSprite(midgroundTextures[0]),
                new StaticSprite(midgroundTextures[1], new Vector2(3500, 0))
            };

            var midgroundLayer = new ParallaxLayer(this);

            midgroundLayer.Sprites.AddRange(midgroundSprites);
            midgroundLayer.DrawOrder = 1;

            Components.Add(midgroundLayer);

            var foregroundTextures = new List <Texture2D>()
            {
                Content.Load <Texture2D>("foreground1"),
                Content.Load <Texture2D>("foreground2"),
                Content.Load <Texture2D>("foreground3"),
                Content.Load <Texture2D>("foreground4")
            };


            var foregroundSprites = new List <StaticSprite>();

            for (int i = 0; i < foregroundTextures.Count; i++)
            {
                var position = new Vector2(i * 3500, 0);
                var sprite   = new StaticSprite(foregroundTextures[i], position);
                foregroundSprites.Add(sprite);
            }

            var foregroundLayer = new ParallaxLayer(this);

            foreach (var sprite in foregroundSprites)
            {
                foregroundLayer.Sprites.Add(sprite);
            }
            foregroundLayer.DrawOrder = 4;

            //var foregroundScrollController = foregroundLayer.ScrollController as AutoScrollController;
            //foregroundScrollController.Speed = 80f;
            Components.Add(foregroundLayer);


            backgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.1f);
            midgroundLayer.ScrollController  = new PlayerTrackingScrollController(player, 0.4f);
            //playerLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f);
            foregroundLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f);



            player.LoadContent(Content);

            //foreach (Enemy en in enemies)
            //{
            //    en.LoadContent(Content);
            //}



            texture = Content.Load <Texture2D>("pixel");
            finish  = Content.Load <Texture2D>("finish");

            win  = Content.Load <Texture2D>("win");
            lose = Content.Load <Texture2D>("lose");


            finishRect = new Rectangle(900, 550, 100, 250);

            // TODO: use this.Content to load your game content here


            won        = false;
            lost       = false;
            spriteFont = Content.Load <SpriteFont>("defaultFont");
        }
Beispiel #5
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //load sfx for player hit
            playerHitSFX = Content.Load <SoundEffect>("Hit_Hurt");

            // TODO: use this.Content to load your game content here
            var playerCar = Content.Load <Texture2D>("PixelCar");

            player = new Player(playerCar);

            //Load backgound
            var backgroundTexture = Content.Load <Texture2D>("Background");
            var backgroundSprite  = new StaticSprite(backgroundTexture);
            var backgroundLayer   = new ParallaxLayer(this);

            backgroundLayer.Sprites.Add(backgroundSprite);
            backgroundLayer.DrawOrder = 0;
            Components.Add(backgroundLayer);

            //load player
            var playerLayer = new ParallaxLayer(this);

            playerLayer.Sprites.Add(player);
            playerLayer.DrawOrder = 3;
            Components.Add(playerLayer);

            //load midground
            var midgroundTexture = Content.Load <Texture2D>("Midground");
            var midgroundSprite  = new StaticSprite(midgroundTexture);
            var midgroundLayer   = new ParallaxLayer(this);

            midgroundLayer.Sprites.Add(midgroundSprite);
            midgroundLayer.DrawOrder = 1;
            Components.Add(midgroundLayer);

            //load foregound Textures
            var foregroundTextures = Content.Load <Texture2D>("Foreground");
            var foregroundSprite   = new StaticSprite(foregroundTextures);
            var foregroundLayer    = new ParallaxLayer(this);

            foregroundLayer.Sprites.Add(foregroundSprite);
            foregroundLayer.DrawOrder = 2;
            Components.Add(foregroundLayer);

            //load and set hazards
            var hazardTexture = Content.Load <Texture2D>("Logs-Big");

            for (int i = 0; i < 5; i++)
            {
                var hazardVector = new Vector2(
                    MathHelper.Lerp(300, 2000, (float)random.NextDouble()),       // X between 300 and 2000
                    MathHelper.Lerp(300, 400, (float)random.NextDouble())         // Y between 300 and 400
                    );
                var sprite = new StaticSprite(hazardTexture, hazardVector);
                sprite.bounds = new BoundingRectangle(hazardVector, 64, 64);
                hazards.Add(sprite);
            }
            var hazardLayer = new ParallaxLayer(this);

            foreach (var item in hazards)
            {
                hazardLayer.Sprites.Add(item);
            }
            hazardLayer.DrawOrder = 3;
            Components.Add(hazardLayer);

            //setup for player tracking
            backgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.1f);
            midgroundLayer.ScrollController  = new PlayerTrackingScrollController(player, 0.4f);
            playerLayer.ScrollController     = new PlayerTrackingScrollController(player, 1.0f);
            foregroundLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f);
            hazardLayer.ScrollController     = new PlayerTrackingScrollController(player, 1.0f);
        }