public ActionScreen(Game game, SpriteBatch SpriteBatch, Texture2D image, ContentManager Content) : base(game, SpriteBatch, Content) { //default loadout spriteBatch = SpriteBatch; _defaultFont = Content.Load<SpriteFont>("Fonts/Verdana"); //get background from the game1 this._background = image; _backgroundRect = new Rectangle(0, 0, 1350, 690); //timer _startTimer = false; Timer = new GameTimer(game, 300f); Timer.Position = new Vector2(10, 10); Timer.Font = _defaultFont; _timerProgress = Content.Load<Texture2D>("Textures/Board/white_64x64"); _timerProgressPosition = new Vector2(0, 190); //Game Over GameOver = new GameOver(game, _defaultFont, Content); //load level Level = new Level(game); Level.LoadContent(Content); //load Player Player = new Player(Content, new Vector2(80, 610), Content.Load<Texture2D>("Textures/Player/Rat")); Player.Speed = 2f; Player.BoardPosition = new Vector2(-1, 5); //basic level components _userInterface = Content.Load<Texture2D>("Textures/Board/TileList"); _startTile = Content.Load<Texture2D>("Textures/Tiles/HorizantelTile"); _endTile = Content.Load<Texture2D>("Textures/Tiles/EndTile"); _waterMeter = Content.Load<Texture2D>("Textures/Timer/WaterMeter"); //load the tile textures _horizantelTile = new HorizantelTile(game, Content.Load<Texture2D>("Textures/Tiles/HorizantelTile"), new Vector2(1268, 195), 0); _verticalTile = new VerticalTile(game, Content.Load<Texture2D>("Textures/Tiles/VerticalTile"), new Vector2(1270, 273), 1); _leftDownTile = new LeftDownTile(game, Content.Load<Texture2D>("Textures/Tiles/LeftDownTile"), new Vector2(1275, 345), 2); _leftTopTile = new LeftTopTile(game, Content.Load<Texture2D>("Textures/Tiles/LeftTopTile"), new Vector2(1260, 450), 3); _rightDownTile = new RightDownTile(game, Content.Load<Texture2D>("Textures/Tiles/RightDownTile"), new Vector2(1275, 535), 4); _rightTopTile = new RightTopTile(game, Content.Load<Texture2D>("Textures/Tiles/RightTopTile"), new Vector2(1260, 600), 5); _dragDrop = Content.Load<SoundEffect>("Audio/Effects/Tile.wav"); AddRocks(); _isPopUp = false; }
public override void Update(GameTime gameTime) { base.Update(gameTime); _keyboardState = Keyboard.GetState(); if (_keyboardState.IsKeyDown(Keys.Escape)) game.Exit(); //update timer Timer.Update(gameTime); //Update player Player.Update(gameTime); //Level gehaald if(Timer.Time != 0 && Level.Board[13, 0] && _isPopUp == false) { if (Level.LastTileType == _verticalTile.Type) { Player.MoveYMin = true; if (Player.Position.Y <= 110) Player.MoveYMin = false; } else if (Level.LastTileType == _rightDownTile.Type) { Player.MoveXPlus = true; if (Player.Position.X >= 1200) { Player.MoveXPlus = false; Player.MoveYMin = true; } if (Player.Position.Y <= 110) Player.MoveYMin = false; } Timer.Stop = true; _startTimer = false; GameOver.State = 1; GameOver.Update(gameTime); if (GameOver.Restart == true) { Level.LevelNumber += 1; Level.Board = new bool[14, 6]; Level.TileType = new int[14, 6]; Level.CaneDraw = new bool[14, 6]; Level.LastTileType = 0; Level.LastTilePosition = new Vector2(0, 5); Level.CaneDraw[0, 5] = true; _tileNumber = 0; AddRocks(); Player = new Player(Content, new Vector2(80, 610), Content.Load<Texture2D>("Textures/Player/Rat")); Player.Speed = 2f; Player.BoardPosition = new Vector2(-1, 5); _timerProgressPosition = new Vector2(0, 190); Timer = new GameTimer(game, 300f); Timer.Font = _defaultFont; Timer.Position = new Vector2(10, 10); GameOver.Restart = false; } } //Game Over if (Timer.Time <= 0) { Timer.Stop = true; _startTimer = false; GameOver.State = 0; GameOver.Update(gameTime); if(GameOver.Restart == true) { Level.Board = new bool[14, 6]; Level.TileType = new int[14, 6]; Level.CaneDraw = new bool[14, 6]; Level.LastTileType = 0; Level.LastTilePosition = new Vector2(0, 5); Level.CaneDraw[0, 5] = true; _tileNumber = 0; AddRocks(); Player = new Player(Content, new Vector2(80, 610), Content.Load<Texture2D>("Textures/Player/Rat")); Player.Speed = 2f; Player.BoardPosition = new Vector2(-1, 5); _timerProgressPosition = new Vector2(0, 190); Timer = new GameTimer(game, 300f); Timer.Font = _defaultFont; Timer.Position = new Vector2(10, 10); GameOver.Restart = false; } } //get the current state of the mouse (position, buttons, etc.) _currentMouse = Mouse.GetState(); //remember the mouseposition for use in this Update and subsequent Draw _currentMousePosition = new Vector2(_currentMouse.X, _currentMouse.Y); CheckForLeftButtonDown(); CheckForLeftButtonRelease(); CheckForRightButtonReleaseOverBoard(); //store the current state of the mouse as the old _oldMouse = _currentMouse; if (_startTimer == true) { Timer.Start = true; _timerProgressPosition.Y += Timer.Time / Timer.Time / 40; } if (_isPopUp == true) { PopUpScreen.Update(gameTime); if (Level.TileType[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y] == _leftDownTile.Type) { if (PopUpScreen.Answer == false) { Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y] = false; if ((int)Level.LastTilePosition.X - 1 >= 0) if (Level.Board[(int)Level.LastTilePosition.X - 1, (int)Level.LastTilePosition.Y] == false) Level.CaneDraw[(int)Level.LastTilePosition.X - 1, (int)Level.LastTilePosition.Y] = false; if ((int)Level.LastTilePosition.Y + 1 < Level.LevelIndexY) if (Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y + 1] == false) Level.CaneDraw[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y + 1] = false; } else { if (PopUpScreen.Enter == true) { if ((int)Level.LastTilePosition.X - 1 >= 0 && Level.TileType[(int)Level.LastTilePosition.X - 1, (int)Level.LastTilePosition.Y] != 6) Level.CaneDraw[(int)Level.LastTilePosition.X - 1, (int)Level.LastTilePosition.Y] = true; if ((int)Level.LastTilePosition.Y + 1 < Level.LevelIndexY && Level.TileType[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y + 1] != 6) Level.CaneDraw[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y + 1] = true; if ((int)Level.LastTilePosition.X - 1 >= 0) { if (Level.Board[(int)Level.LastTilePosition.X - 1, (int)Level.LastTilePosition.Y] == false && Level.Board[(int)Player.BoardPosition.X, (int)Player.BoardPosition.Y - 1] && (Level.LastTileType == _verticalTile.Type || Level.LastTileType == _leftTopTile.Type || Level.LastTileType == _rightDownTile.Type)) { if ((int)Player.BoardPosition.X >= 0) Level.CaneDraw[(int)Player.BoardPosition.X, (int)Player.BoardPosition.Y] = false; Player.MoveYMin = true; Player.BoardPosition = new Vector2((int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y); } } if ((int)Level.LastTilePosition.Y + 1 < Level.LevelIndexY) { if (Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y + 1] == false && Level.Board[(int)Player.BoardPosition.X + 1, (int)Player.BoardPosition.Y] && (Level.LastTileType == _horizantelTile.Type || Level.LastTileType == _leftTopTile.Type || Level.LastTileType == _rightTopTile.Type)) { if ((int)Player.BoardPosition.X >= 0) Level.CaneDraw[(int)Player.BoardPosition.X, (int)Player.BoardPosition.Y] = false; Player.MoveXPlus = true; Player.BoardPosition = new Vector2((int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y); } } Level.LastTileType = _leftDownTile.Type; _isPopUp = false; PopUpScreen.Enter = false; } } } if (Level.TileType[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y] == _leftTopTile.Type) { if (PopUpScreen.Answer == false) { Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y] = false; if ((int)Level.LastTilePosition.X + 1 < Level.LevelIndexX) if (Level.Board[(int)Level.LastTilePosition.X + 1, (int)Level.LastTilePosition.Y] == false) Level.CaneDraw[(int)Level.LastTilePosition.X + 1, (int)Level.LastTilePosition.Y] = false; if ((int)Level.LastTilePosition.Y - 1 >= 0) if (Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y - 1] == false) Level.CaneDraw[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y - 1] = false; } else { if (PopUpScreen.Enter == true) { if ((int)Level.LastTilePosition.X + 1 < Level.LevelIndexX && Level.TileType[(int)Level.LastTilePosition.X + 1, (int)Level.LastTilePosition.Y] != 6) Level.CaneDraw[(int)Level.LastTilePosition.X + 1, (int)Level.LastTilePosition.Y] = true; if ((int)Level.LastTilePosition.Y - 1 >= 0 && Level.TileType[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y - 1] != 6) Level.CaneDraw[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y - 1] = true; if ((int)Level.LastTilePosition.X + 1 < Level.LevelIndexX) { if (Level.Board[(int)Level.LastTilePosition.X + 1, (int)Level.LastTilePosition.Y] == false && Level.Board[(int)Player.BoardPosition.X, (int)Player.BoardPosition.Y + 1] && (Level.LastTileType == _verticalTile.Type || Level.LastTileType == _leftDownTile.Type || Level.LastTileType == _rightTopTile.Type)) { if ((int)Player.BoardPosition.X >= 0) Level.CaneDraw[(int)Player.BoardPosition.X, (int)Player.BoardPosition.Y] = false; Player.MoveYPlus = true; Player.BoardPosition = new Vector2((int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y); } } if ((int)Level.LastTilePosition.Y - 1 >= 0) { if (Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y - 1] == false && Level.Board[(int)Player.BoardPosition.X - 1, (int)Player.BoardPosition.Y] && (Level.LastTileType == _horizantelTile.Type || Level.LastTileType == _leftDownTile.Type || Level.LastTileType == _rightDownTile.Type)) { if ((int)Player.BoardPosition.X >= 0) Level.CaneDraw[(int)Player.BoardPosition.X, (int)Player.BoardPosition.Y] = false; Player.MoveXMin = true; Player.BoardPosition = new Vector2((int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y); } } Level.LastTileType = _leftTopTile.Type; _isPopUp = false; PopUpScreen.Enter = false; } } } if (Level.TileType[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y] == _rightDownTile.Type) { if (PopUpScreen.Answer == false) { Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y] = false; if ((int)Level.LastTilePosition.X - 1 >= 0) if (Level.Board[(int)Level.LastTilePosition.X - 1, (int)Level.LastTilePosition.Y] == false) Level.CaneDraw[(int)Level.LastTilePosition.X - 1, (int)Level.LastTilePosition.Y] = false; if ((int)Level.LastTilePosition.Y - 1 >= 0) if (Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y - 1] == false) Level.CaneDraw[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y - 1] = false; } else { if (PopUpScreen.Enter == true) { if ((int)Level.LastTilePosition.X - 1 >= 0 && Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y] && Level.TileType[(int)Level.LastTilePosition.X - 1, (int)Level.LastTilePosition.Y] != 6) Level.CaneDraw[(int)Level.LastTilePosition.X - 1, (int)Level.LastTilePosition.Y] = true; if ((int)Level.LastTilePosition.Y - 1 >= 0 && Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y] && Level.TileType[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y - 1] != 6) Level.CaneDraw[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y - 1] = true; if ((int)Level.LastTilePosition.Y - 1 >= 0) { if (Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y - 1] == false && Level.Board[(int)Player.BoardPosition.X + 1, (int)Player.BoardPosition.Y] && (Level.LastTileType == _horizantelTile.Type || Level.LastTileType == _leftTopTile.Type || Level.LastTileType == _rightTopTile.Type)) { if ((int)Player.BoardPosition.X >= 0) Level.CaneDraw[(int)Player.BoardPosition.X, (int)Player.BoardPosition.Y] = false; Player.MoveXPlus = true; Player.BoardPosition = new Vector2((int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y); } } if ((int)Level.LastTilePosition.X - 1 >= 0) { if (Level.Board[(int)Level.LastTilePosition.X - 1, (int)Level.LastTilePosition.Y] == false && Level.Board[(int)Player.BoardPosition.X, (int)Player.BoardPosition.Y + 1] && (Level.LastTileType == _verticalTile.Type || Level.LastTileType == _leftDownTile.Type || Level.LastTileType == _rightTopTile.Type)) { if ((int)Player.BoardPosition.X >= 0) Level.CaneDraw[(int)Player.BoardPosition.X, (int)Player.BoardPosition.Y] = false; Player.MoveYPlus = true; Player.BoardPosition = new Vector2((int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y); } } Level.LastTileType = _rightDownTile.Type; _isPopUp = false; PopUpScreen.Enter = false; } } } if (Level.TileType[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y] == _rightTopTile.Type) { if (PopUpScreen.Answer == false) { Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y] = false; if ((int)Level.LastTilePosition.X + 1 < Level.LevelIndexX) if (Level.Board[(int)Level.LastTilePosition.X + 1, (int)Level.LastTilePosition.Y] == false) Level.CaneDraw[(int)Level.LastTilePosition.X + 1, (int)Level.LastTilePosition.Y] = false; if ((int)Level.LastTilePosition.Y + 1 < Level.LevelIndexY) if (Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y + 1] == false) Level.CaneDraw[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y + 1] = false; } else { if (PopUpScreen.Enter == true) { if ((int)Level.LastTilePosition.X + 1 < Level.LevelIndexX && Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y] && Level.TileType[(int)Level.LastTilePosition.X + 1, (int)Level.LastTilePosition.Y] != 6) Level.CaneDraw[(int)Level.LastTilePosition.X + 1, (int)Level.LastTilePosition.Y] = true; if ((int)Level.LastTilePosition.Y + 1 < Level.LevelIndexY && Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y] && Level.TileType[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y + 1] != 6) Level.CaneDraw[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y + 1] = true; if ((int)Level.LastTilePosition.X + 1 < Level.LevelIndexX) { if (Level.Board[(int)Level.LastTilePosition.X + 1, (int)Level.LastTilePosition.Y] == false && Level.Board[(int)Player.BoardPosition.X, (int)Player.BoardPosition.Y - 1] && (Level.LastTileType == _verticalTile.Type || Level.LastTileType == _rightDownTile.Type || Level.LastTileType == _leftTopTile.Type)) { if ((int)Player.BoardPosition.X >= 0) Level.CaneDraw[(int)Player.BoardPosition.X, (int)Player.BoardPosition.Y] = false; Player.MoveYMin = true; Player.BoardPosition = new Vector2((int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y); } } if ((int)Level.LastTilePosition.Y + 1 < Level.LevelIndexY) { if (Level.Board[(int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y + 1] == false && Level.Board[(int)Player.BoardPosition.X - 1, (int)Player.BoardPosition.Y] && (Level.LastTileType == _horizantelTile.Type || Level.LastTileType == _rightDownTile.Type || Level.LastTileType == _leftDownTile.Type)) { if ((int)Player.BoardPosition.X >= 0) Level.CaneDraw[(int)Player.BoardPosition.X, (int)Player.BoardPosition.Y] = false; Player.MoveXMin = true; Player.BoardPosition = new Vector2((int)Level.LastTilePosition.X, (int)Level.LastTilePosition.Y); } } Level.LastTileType = _rightTopTile.Type; _isPopUp = false; PopUpScreen.Enter = false; } } } } }