Exemple #1
0
        public override void Update(GameTime gameTime)
        {
            // Player

            if (PlayerWon)
            {
                GameStateManager.Instance.SetCurrentState(new EndScreen(ContentManager, GraphicsDevice, Game, GameResult.Won));
            }

            if (player.IsDead)
            {
                GameStateManager.Instance.SetCurrentState(new EndScreen(ContentManager, GraphicsDevice, Game, GameResult.Lost));
            }

            player.Update(gameTime);

            // Clock
            clock.Update(gameTime);
            clock.UpdatePosition(ScreenPosition.Top(player));

            // Heathbar
            healtbar.SetHealth(player);
            healtbar.UpdatePosition(ScreenPosition.RightTopCorner(player));

            // Inventory
            inventroyHelper.UpdatePosition(ScreenPosition.LeftLopCorner(player), player.Sprite.Position);

            // Camera
            camera.Follow(player);

            // Levels
            AllWorlds[CurrentWorld].Update(gameTime);
            collisionManager.CheckCollision(player, AllWorlds[CurrentWorld]);
            if (AllWorlds[CurrentWorld] is SpecialWorld)
            {
                SpecialWorld hardLevel = AllWorlds[CurrentWorld] as SpecialWorld;
                hardLevel.CreateBullets();
            }
        }
Exemple #2
0
        public override void LoadContent()
        {
            // Player 1
            Texture2D playerTexture;
            int       spriteSheetLength;

            spriteSheetLength = 1;
            playerTexture     = ContentManager.Load <Texture2D>("PlayerTank");


            Output          output                  = new Output();
            TouchController playerController        = new TouchController(output);
            Vector2         playerPosition          = new Vector2();
            Vector2         playerSpeed             = new Vector2(7, 0);
            Animation       playerAnimation         = new Animation();
            Sprite          playerSprite            = new Sprite(playerTexture, spriteSheetLength, playerPosition);
            Rectangle       playerCollisonRectangle = new Rectangle((int)playerPosition.X, (int)playerPosition.Y, playerTexture.Width / spriteSheetLength, playerTexture.Height);
            Inventory       playerInventory         = new Inventory();

            player = new Player(playerSprite, playerController, playerAnimation, playerCollisonRectangle, playerSpeed, playerInventory);
            player.Respawn();

            // Other

            AllWorlds              = new List <World>();
            collisionManager       = new CollisionManager();
            PlayerWon              = false;
            Factory.contentManager = ContentManager;

            // SoundEffects

            GameSounds.PickSound      = ContentManager.Load <SoundEffect>("PickSound");
            GameSounds.HitSound       = ContentManager.Load <SoundEffect>("HitSound");
            GameSounds.DrinkSound     = ContentManager.Load <SoundEffect>("DrinkSound");
            GameSounds.GameOverSound  = ContentManager.Load <SoundEffect>("GameOverSound");
            GameSounds.JumpSound      = ContentManager.Load <SoundEffect>("JumpSound");
            GameSounds.ExplosionSound = ContentManager.Load <SoundEffect>("ExplosionSound");
            GameSounds.ShootSound     = ContentManager.Load <SoundEffect>("ShootSound");

            // Clock

            defaultFont = ContentManager.Load <SpriteFont>("DefaultFont");
            clock       = new Clock(defaultFont);

            // Camera

            camera = new Camera2D();

            // Inventory Helper

            keyTexture     = ContentManager.Load <Texture2D>("Pickable1");
            coinTexture    = ContentManager.Load <Texture2D>("Pickable2");
            potionTexture  = ContentManager.Load <Texture2D>("Pickable3");
            diamondTexture = ContentManager.Load <Texture2D>("Diamond");
            allTextures    = new List <Texture2D>()
            {
                keyTexture, coinTexture, potionTexture, diamondTexture
            };
            inventroyHelper = new InventoryBar(player.Inventory, allTextures, defaultFont);

            // Healthbar

            healtTexture = ContentManager.Load <Texture2D>("Health");
            healtbar     = new HealthBar(healtTexture);

            #region World1

            byte[,] ObstaclesWorld1 = new byte[, ]
            {
                { 1, 1, 0, 0, 0, 0, 1, 1 },
                { 1, 1, 1, 0, 0, 1, 0, 0 },
                { 2, 1, 1, 1, 1, 1, 0, 0 }
            };

            byte[,] PickablesWorld1 = new byte[, ]
            {
                { 0, 0, 0, 0, 0, 0, 0, 4 },
                { 0, 0, 1, 0, 0, 0, 0, 0 },
                { 0, 0, 2, 0, 0, 0, 0, 0 }
            };

            List <int> MoneySafeIdentiefiers1 = new List <int>()
            {
                10006,
            };

            World world1 = new World(ObstaclesWorld1, PickablesWorld1, MoneySafeIdentiefiers1);
            world1.Create(ContentManager);
            world1.NextWorld = AllWorlds.Count + 1;
            AllWorlds.Add(world1);

            #endregion

            #region World2

            byte[,] ObstaclesWorld2 = new byte[, ]
            {
                { 1, 0, 0, 0, 1, 0, 0, 1, 0, 0 },
                { 1, 0, 0, 0, 1, 1, 1, 0, 0, 1 },
                { 1, 1, 2, 1, 1, 1, 0, 0, 1, 1 },
                { 1, 1, 0, 1, 0, 1, 1, 1, 0, 1 }
            };

            byte[,] PickablesWorld2 = new byte[, ]
            {
                { 0, 0, 0, 0, 2, 0, 0, 4, 0, 0 },
                { 2, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 3, 0, 0, 0, 4 },
                { 0, 1, 0, 0, 0, 0, 0, 0, 0, 2 }
            };

            List <int> MoneySafeIdentiefiers2 = new List <int>()
            {
                10006, 10007
            };

            World world2 = new World(ObstaclesWorld2, PickablesWorld2, MoneySafeIdentiefiers2);
            world2.Create(ContentManager);
            world2.NextWorld = AllWorlds.Count + 1;
            AllWorlds.Add(world2);

            #endregion

            #region World3

            byte[,] ObstaclesWorld3 = new byte[, ]
            {
                { 1, 0, 0, 1, 0, 0, 1, 0, 1, 0 },
                { 1, 1, 1, 1, 1, 0, 0, 1, 1, 1 },
                { 0, 1, 2, 1, 0, 1, 1, 1, 1, 1 },
            };

            byte[,] PickablesWorld3 = new byte[, ]
            {
                { 0, 0, 0, 3, 0, 0, 2, 0, 4, 0 },
                { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 1, 0, 0, 0, 2 },
            };


            byte[,] EnemiesWorld3 = new byte[, ]
            {
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 2, 0 },
            };

            List <int> MoneySafeIdentiefiers3 = new List <int>()
            {
                10009
            };

            World world3 = new SpecialWorld(ObstaclesWorld3, PickablesWorld3, MoneySafeIdentiefiers3, EnemiesWorld3);
            world3.Create(ContentManager);
            world3.NextWorld = AllWorlds.Count + 1;
            AllWorlds.Add(world3);

            #endregion

            #region World4

            byte[,] ObstaclesWorld4 = new byte[, ]
            {
                { 1, 0, 0, 1, 0, 0, 1, 0, 1, 0 },
                { 1, 0, 0, 1, 1, 0, 0, 1, 1, 1 },
                { 1, 1, 1, 0, 0, 1, 0, 0, 0, 1 },
                { 1, 2, 1, 0, 0, 1, 1, 0, 1, 1 },
                { 1, 1, 1, 1, 1, 1, 0, 0, 1, 1 },
                { 1, 1, 0, 1, 0, 1, 1, 1, 1, 1 },
            };

            byte[,] PickablesWorld4 = new byte[, ]
            {
                { 0, 0, 0, 1, 0, 0, 0, 0, 4, 0 },
                { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 4, 0, 0, 1, 0, 0, 2, 0 },
                { 0, 0, 0, 0, 0, 0, 2, 0, 0, 4 },
                { 0, 2, 0, 0, 0, 0, 0, 0, 0, 1 },
                { 0, 4, 0, 1, 0, 0, 0, 0, 0, 2 },
            };


            byte[,] EnemiesWorld4 = new byte[, ]
            {
                { 0, 0, 0, 0, 0, 0, 2, 0, 0, 0 },
                { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 },
                { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
                { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
            };

            List <int> MoneySafeIdentiefiers4 = new List <int>()
            {
                10000, 10000, 10000, 10000
            };

            World world4 = new SpecialWorld(ObstaclesWorld4, PickablesWorld4, MoneySafeIdentiefiers4, EnemiesWorld4);
            world4.Create(ContentManager);
            world4.NextWorld = GAMEISDONECODE;
            AllWorlds.Add(world4);

            #endregion
        }