public void Update(GameTime gameTime)
        {
            if (collided && !powerupSpawned)
            {
                int temp = Game1.random.Next(2);
                if (temp != 1)
                {
                    powerup = new Powerup(loader.LoadSpriteSheet("Powerups\\coin", Vector2.Zero, new Vector2(14, 14), 1), level, Position, new Vector2(14, 14), Powerup.PowerupType.Coin);
                }
                else
                {
                    powerup = new Powerup(loader.LoadSpriteSheet("Powerups\\flowerpowerup", Vector2.Zero, new Vector2(16, 16), 1), level, Position, new Vector2(16, 16), Powerup.PowerupType.FireFlower);
                }
                powerupSpawned            = true;
                currentSpriteSheet.XIndex = collidedIndex;
            }

            if (powerup == null)
            {
                return;
            }
            powerup.Update(gameTime);
            if (powerup.isDead)
            {
                if (powerup.Type == Powerup.PowerupType.Coin)
                {
                    level.scoreToAdd = 100;
                }
                powerup = null;
            }
        }
예제 #2
0
        private void Create(SpriteSheetLoader loader)
        {
            this.spritesheet = loader.LoadSpriteSheet(levelData.SpriteSheetFilePath, Vector2.Zero, new Vector2(16, 16), 0);

            this.tiles = new Tile[levelData.Size];
            for (int i = 0; i < tiles.Length; i++)
            {
                Tile tile = levelData.Tiles[i];

                int sx = (int)tile.IDType % spritesheet.Columns;
                int sy = (int)tile.IDType / spritesheet.Columns;

                SpriteSheet sheet = loader.LoadSpriteSheet(levelData.SpriteSheetFilePath, Vector2.Zero, new Vector2(16, 16), 0);
                sheet.XIndex = sx;
                sheet.YIndex = sy;

                tiles[i] = new Tile(sheet, this, tile.Position, tile.IDType);
            }

            this.objects = new Tile[levelData.Objects.Length];
            for (int i = 0; i < levelData.Objects.Length; i++)
            {
                Tile tile = levelData.Objects[i];

                int sx = (int)tile.IDType % spritesheet.Columns;
                int sy = (int)tile.IDType / spritesheet.Columns;

                SpriteSheet sheet = loader.LoadSpriteSheet(levelData.SpriteSheetFilePath, Vector2.Zero, new Vector2(16, 16), 0);
                sheet.XIndex = sx;
                sheet.YIndex = sy;

                objects[i] = new Tile(sheet, this, tile.Position, tile.IDType);
            }


            for (int i = objects.Length - 1; i > -1; i--)
            {
                if (objects[i].IDType == 10)
                {
                    playerSpawn = objects[i].Position;
                    continue;
                }

                Enemy enemy = Enemy.Get(loader, this, objects[i].IDType);
                enemy.Position = objects[i].Position;

                AddEnemy(enemy);
            }

            for (int i = 0; i < tiles.Length; i++)
            {
                if (tiles[i].IDType == 0)
                {
                    powerupBlocks.Add(new PowerupBlock(loader.LoadSpriteSheet("blocks", Vector2.Zero, new Vector2(16, 16), 0), this, tiles[i].Position, new Vector2(16, 16), loader));
                }
            }
        }
예제 #3
0
 public static Enemy Get(SpriteSheetLoader loader, Level level, int id)
 {
     return(id switch
     {
         5 => new Cannon(loader.LoadSpriteSheet("Obstacles\\canon", Vector2.Zero, new Vector2(16, 16), 0), level, Vector2.Zero, new Vector2(16, 16), loader.LoadSpriteSheet("Obstacles\\bullet", Vector2.Zero, new Vector2(16, 13), 0)),
         6 => new PatrollingEnemy(loader.LoadSpriteSheet("Enemies\\DKenemy", Vector2.Zero, new Vector2(15, 20), 1), level, Vector2.Zero, new Vector2(15, 20), 1, 70.0f),
         7 => new TurtleEnemy(loader.LoadSpriteSheet("Enemies\\TurtleEnemy", Vector2.Zero, new Vector2(16, 24), 1), level, Vector2.Zero, new Vector2(17, 24), 1, 70.0f),
         11 => new Spike(loader.LoadSpriteSheet("Enemies\\spikes", Vector2.Zero, new Vector2(16, 16), 1), level, Vector2.Zero, new Vector2(16, 16), 0, 0.0f),
         _ => null,
     });
예제 #4
0
        public void LoadLevel(string levelPath)
        {
            currentLevelPath = levelPath;

            tiles.Clear();
            gameObjectTiles.Clear();

            LevelData data = LevelData.LoadLevelData(levelPath);

            System.Diagnostics.Debug.WriteLine("Loaded level: " + levelPath);

            if (data == null)
            {
                return;
            }

            this.palette = loader.LoadSpriteSheet(data.SpriteSheetFilePath, Vector2.Zero, new Vector2(16, 16), 0);
            foreach (Tile tile in data.Tiles)
            {
                int         x     = tile.IDType % palette.Columns;
                int         y     = tile.IDType / palette.Columns;
                SpriteSheet sheet = GetSpriteSheetAt(x, y);

                tiles.Add(tile.Position, new Tile(sheet, null, tile.Position, tile.IDType));
            }
            foreach (Tile tile in data.Objects)
            {
                int         x     = tile.IDType % palette.Columns;
                int         y     = tile.IDType / palette.Columns;
                SpriteSheet sheet = GetSpriteSheetAt(x, y);
                gameObjectTiles.Add(tile.Position, new Tile(sheet, null, tile.Position, tile.IDType));
            }
        }
예제 #5
0
        public Editor(SpriteSheetLoader loader, GameWindow window)
        {
            this.loader          = loader;
            this.tiles           = new Dictionary <Vector2, Tile>();
            this.gameObjectTiles = new Dictionary <Vector2, Tile>();
            this.camera          = new Camera(new Viewport());

            this.mouseTile = GetTileOnCursor();

            this.palette                = loader.LoadSpriteSheet("blocks", Vector2.Zero, new Vector2(16, 16), 0);
            this.paletteBackground      = loader.CreateFilledTexture(1, 1, new Color(10, 10, 10));
            this.viewportSplit          = loader.CreateFilledTexture(1, 1, new Color(128, 128, 128));
            this.viewportLineSplitWidth = 1;
            this.selectedPaletteIndex   = new Vector2(0, 0);
            this.selectedPalette        = GetSpriteSheetAt((int)selectedPaletteIndex.X, (int)selectedPaletteIndex.Y);

            this.levelViewport   = new Viewport(0, 0, window.ClientBounds.Width - this.palette.Texture.Width, window.ClientBounds.Height);
            this.paletteViewport = new Viewport(levelViewport.Width, 0, this.palette.Texture.Width, window.ClientBounds.Height);

            Texture2D rectangleTexture = loader.CreateRectangleTexture(Tile.SIZE, Tile.SIZE, Color.White);

            this.selectionSprite = new SpriteSheet(rectangleTexture).Sprite;

            this.currentLevelPath = "Content\\Level1.lvl";
        }
예제 #6
0
        public Level(SpriteSheetLoader loader, LevelData levelData, HUD hud)
        {
            this.levelData = levelData;
            this.hud       = hud;

            this.lvlWon = false;

            this.enemies       = new List <Enemy>();
            this.powerupBlocks = new List <PowerupBlock>();

            playerSpawn = new Vector2(0, 250);

            Create(loader);

            SpriteSheet playerAnimationSheet = loader.LoadSpriteSheet("player");

            this.player = new Player(playerAnimationSheet, this, playerSpawn, new Vector2(16, 16), 5, 200.0f, loader);
        }
예제 #7
0
        protected override void InternalUpdate(GameTime gameTime)
        {
            direction = Vector2.Zero;
            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                direction.X = -1;
                facingLeft  = true;
                walking     = true;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                direction.X = 1;
                facingLeft  = false;
                walking     = true;
            }

            if (!Keyboard.GetState().IsKeyDown(Keys.D) && !Keyboard.GetState().IsKeyDown(Keys.A))
            {
                walking = false;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.LeftShift) && walking)
            {
                running = true;
                speed   = runSpeed;
            }
            else
            {
                running = false;
                speed   = walkSpeed;
            }

            bool canJump = false;

            GameObject[] colliders = GetColliders(level.Tiles);
            foreach (GameObject collider in colliders)
            {
                if (IsOnTopOf(collider) && !jumping)
                {
                    canJump = true;
                    break;
                }
            }

            if (Mouse.GetState().LeftButton == ButtonState.Pressed && powerupTimer > 0 && lastMouseState != ButtonState.Pressed)
            {
                fireBalls.Add(new FireBall(loader.LoadSpriteSheet("Powerups\\fire", Vector2.Zero, new Vector2(16, 16), 0), level, Position, new Vector2(8, 8), facingLeft ? new Vector2(-1, 0) : new Vector2(1, 0)));
            }


            if ((Keyboard.GetState().IsKeyDown(Keys.Space) || Keyboard.GetState().IsKeyDown(Keys.W)))
            {
                if (canJump)
                {
                    Jump(400.0f);
                }
            }
            else
            {
                jumping = false;
            }
            foreach (FireBall fireBall in fireBalls)
            {
                fireBall.Update(gameTime);
            }
            for (int i = fireBalls.Count - 1; i > -1; i--)
            {
                if (fireBalls[i].IsDead)
                {
                    fireBalls.RemoveAt(i);
                }
            }

            lastMouseState = Mouse.GetState().LeftButton;
            powerupTimer  -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
        }
예제 #8
0
        private void StartGame()
        {
            HUD hud = new HUD(Window, 100, 100, spritesheetLoader.LoadTexture("score-numbers"), spritesheetLoader.LoadSpriteSheet("player", Vector2.Zero, new Vector2(16, 16)).GetAt(0, 0));

            menu = new MenuState(font, Window, hud);

            menu.Actions.Add(new MenuOption("1. Start Game", () => gameState  = inGameState));
            menu.Actions.Add(new MenuOption("2. Open Editor", () => gameState = editor));
            menu.Actions.Add(new MenuOption("3. Exit", () => Exit()));

            inGameState = new InGameState(spritesheetLoader, GraphicsDevice, Window, hud, font);
            editor      = new Editor(spritesheetLoader, Window);
            editor.LoadLevel("Content\\Level1.lvl");
            gameState = menu;
        }