Example #1
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            for (int row = 0; row < _mazeTiles.GetLength(0); row++)
            {
                for (int col = 0; col < _mazeTiles.GetLength(1); col++)
                {
                    MazeTile mt  = _mazeTiles[row, col];
                    Vector2  pos = new Vector2(col * TileWidth, row * TileHeight) + MazeOffset;

                    spriteBatch.Draw(_mazeTiles[row, col].Tile, pos, Color.White);

                    switch (mt.DotType)
                    {
                    case MazeTile.DotTileType.None:
                        break;

                    case MazeTile.DotTileType.Dot:
                        _dot.Position = pos + CenterTile;
                        _dot.Draw(gameTime, spriteBatch);
                        break;

                    case MazeTile.DotTileType.Icon:
                        mt.Icon.Position = pos + CenterTile;
                        mt.Icon.Draw(gameTime, spriteBatch);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            base.Draw(gameTime, spriteBatch);
        }
Example #2
0
        private void CreateMaze(int[,] data)
        {
            Random r = new Random();

            _mazeTiles = new MazeTile[data.GetLength(0), data.GetLength(1)];

            for (int row = 0; row < data.GetLength(0); row++)
            {
                for (int col = 0; col < data.GetLength(1); col++)
                {
                    MazeTile mt = new MazeTile();
                    TileType tt = (TileType)data[row, col];
                    switch (tt)
                    {
                    case TileType.PathWithDot:
                        mt.DotType  = MazeTile.DotTileType.Dot;
                        mt.Tile     = _pathTile;
                        mt.TileType = MazeTile.MazeTileType.Path;
                        break;

                    case TileType.PlayerStart:
                    case TileType.EnemyStart:
                    case TileType.PathWithoutDot:
                        mt.DotType  = MazeTile.DotTileType.None;
                        mt.Tile     = _pathTile;
                        mt.TileType = MazeTile.MazeTileType.Path;
                        if (tt == TileType.PlayerStart)
                        {
                            PlayerStart = new Vector2(col, row);
                        }
                        if (tt == TileType.EnemyStart)
                        {
                            EnemyStart = new Vector2(col, row);
                        }
                        break;

                    case TileType.BlueWall:
                        mt.DotType  = MazeTile.DotTileType.None;
                        mt.Tile     = _blueWalls[r.Next(_blueWalls.Length)];
                        mt.TileType = MazeTile.MazeTileType.Wall;
                        break;

                    case TileType.GrayWall:
                        mt.DotType  = MazeTile.DotTileType.None;
                        mt.Tile     = _grayWalls[r.Next(_grayWalls.Length)];
                        mt.TileType = MazeTile.MazeTileType.Wall;
                        break;

                    case TileType.PathWithIcon:
                        mt.DotType  = MazeTile.DotTileType.Icon;
                        mt.Tile     = _pathTile;
                        mt.TileType = MazeTile.MazeTileType.Path;
                        mt.Icon     = new Icon();
                        break;
                    }
                    _mazeTiles[row, col] = mt;
                }
            }
        }
Example #3
0
        public override void Update(GameTime gameTime)
        {
            for (int row = 0; row < _mazeTiles.GetLength(0); row++)
            {
                for (int col = 0; col < _mazeTiles.GetLength(1); col++)
                {
                    MazeTile mt = _mazeTiles[row, col];
                    if (mt.DotType == MazeTile.DotTileType.Icon)
                    {
                        mt.Icon.Update(gameTime);
                    }
                }
            }

            _dot.Update(gameTime);

            base.Update(gameTime);
        }
Example #4
0
        private void CreateMaze(int[,] data)
        {
            //Random r = new Random();
            _mazeTiles = new MazeTile[data.GetLength(0), data.GetLength(1)];

            for (int row = 0; row < data.GetLength(0); row++)
            {
                for (int col = 0; col < data.GetLength(1); col++)
                {
                    MazeTile mt = new MazeTile();
                    TileType tt = (TileType)data[row, col];
                    switch (tt)
                    {
                        case TileType.PathWithDot:
                            mt.DotType = MazeTile.DotTileType.Dot;
                            //mt.Tile = _pathTile;
                            mt.TileType = MazeTile.MazeTileType.Path;
                            break;
                        case TileType.PlayerStart:
                        case TileType.EnemyStart:
                        case TileType.PathWithoutDot:
                            mt.DotType = MazeTile.DotTileType.None;
                            //mt.Tile = _pathTile;
                            mt.TileType = MazeTile.MazeTileType.Path;
                            //if (tt == TileType.PlayerStart)
                            //    PlayerStart = new Vector2(col, row);
                            //if (tt == TileType.EnemyStart)
                            //    EnemyStart = new Vector2(col, row);
                            break;
                        case TileType.BlueWall:
                            mt.DotType = MazeTile.DotTileType.None;
                            //mt.Tile = _blueWalls[r.Next(_blueWalls.Length)];
                            mt.TileType = MazeTile.MazeTileType.Wall;
                            break;
                        case TileType.GrayWall:
                            mt.DotType = MazeTile.DotTileType.None;
                            //mt.Tile = _grayWalls[r.Next(_grayWalls.Length)];
                            mt.TileType = MazeTile.MazeTileType.Wall;
                            break;
                        case TileType.PathWithIcon:
                            mt.DotType = MazeTile.DotTileType.Icon;
                            //mt.Tile = _pathTile;
                            mt.TileType = MazeTile.MazeTileType.Path;
                            //mt.Icon = new Icon();
                            break;
                    }
                    _mazeTiles[row, col] = mt;
                }
            }
        }
Example #5
0
        private bool IsOpen(int col, int row)
        {
            MazeTile tile = _maze.GetTile(row, col);

            return(tile != null && tile.TileType != MazeTile.MazeTileType.Wall);
        }
Example #6
0
        public override void Update(GameTime gameTime)
        {
            if (MonsterGame.Instance.IsPaused)
            {
                _pauseDialog.Update(gameTime);
                return;
            }

            if (InputManager.CurrentState.Start || InputManager.CurrentState.Back)
            {
                _pauseDialog.Show();
                MonsterGame.Instance.IsPaused = !MonsterGame.Instance.IsPaused;
            }

            switch (_state)
            {
            case GameScreenState.GetReady:
                if (AudioManager.SoundEffectInstances[AudioManager.Cue.GetReadyMusic].State == SoundState.Stopped)
                {
                    _getReady.Hide();
                    _state = GameScreenState.Play;
                    AudioManager.SoundEffectInstances[AudioManager.Cue.GameplayMusic].IsLooped = true;
                    AudioManager.SoundEffectInstances[AudioManager.Cue.GameplayMusic].Volume   = 0.6f;
                    AudioManager.SoundEffectInstances[AudioManager.Cue.GameplayMusic].Play();
                }
                break;

            case GameScreenState.Play:
                MovePlayer();
                MoveEnemy();
                HandleCollisions();
                break;

            case GameScreenState.PlayerEaten:
                if (AudioManager.SoundEffectInstances[AudioManager.Cue.PlayerEaten].State != SoundState.Playing)
                {
                    _numLives--;
                    ResetLevel();
                }
                break;

            case GameScreenState.LevelComplete:
                if (AudioManager.SoundEffectInstances[AudioManager.Cue.LevelCompleted].State != SoundState.Playing)
                {
                    MoveToNextLevel();
                }
                break;

            case GameScreenState.GameOver:
                _gameOverTimer += gameTime.ElapsedGameTime.Milliseconds;
                if (_gameOverTimer >= GameOverTimeout)
                {
                    MonsterGame.Instance.SetState(GameState.TitleScreen);
                }
                break;
            }

            _player.Update(gameTime);

            MazeTile mt = _maze.GetTile(_player.Row, _player.Column);

            if (mt != null)
            {
                switch (mt.DotType)
                {
                case MazeTile.DotTileType.None:
                    break;

                case MazeTile.DotTileType.Dot:
                    _player.EatDot();
                    _score += 100;
                    break;

                case MazeTile.DotTileType.Icon:
                    _player.EatIcon();
                    _score += 1000;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                mt.DotType = MazeTile.DotTileType.None;

                if (_maze.IsComplete)
                {
                    _state = GameScreenState.LevelComplete;
                    AudioManager.SoundEffectInstances[AudioManager.Cue.GameplayMusic].Stop();
                    _player.Move(Direction.None);
                    _enemy.Move(Direction.None);
                    AudioManager.SoundEffectInstances[AudioManager.Cue.LevelCompleted].Play();
                }
            }

            _enemy.Update(gameTime);
            _getReady.Update(gameTime);
            _gameOver.Update(gameTime);
            _livesDisplay.NumberOfLives = _numLives;
            _livesDisplay.Update(gameTime);
            _maze.Update(gameTime);
            _scoreDisplay.Update(gameTime, XboxLiveManager.Profile.Gamertag, _score);
        }