Beispiel #1
0
        private void RenderMap()
        {
            var modelList = new List <_2DModel>();
            var graphics  = Global.Instance.Graphics;
            var unit      = Global.Instance.Unit;
            var colors    = new Color[]
            {
                new Color(246, 215, 152),
                new Color(222, 182, 104)
            };
            int colorIndex = 0;


            for (int i = 0; i < mapWidth; i++)
            {
                for (int j = 0; j < mapHeight; j++)
                {
                    var realPosition = MazeObject.MapToRealPosition(i, j);
                    if (matrix[i, j] == 1)
                    {
                        modelList.Add(new _2DModel(ResManager.Instance.Wall,
                                                   new Rectangle(realPosition.X, realPosition.Y, unit, unit), Color.White));
                    }
                    else
                    {
                        var cell = new Texture2D(graphics, 1, 1);
                        cell.SetData(new Color[]
                        {
                            colors[colorIndex]
                        });

                        modelList.Add(new _2DModel(cell, new Rectangle(realPosition.X, realPosition.Y, unit, unit), Color.White));
                    }
                    colorIndex = 1 - colorIndex;
                }
            }

            mazeModels = modelList.ToArray();
        }
Beispiel #2
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            switch (state)
            {
            case State.Waiting:
                if (PlayerRequestMoving)
                {
                    SoundManager.Instance.PlaySound(ResManager.Instance.FootSteps);
                    player.NumOfSteps = 1;
                    state             = State.PlayerMoving;
                }
                break;

            case State.CalculateMonsterMovement:
                if (currentMonsterIndex == monsters.Length)
                {
                    currentMonsterIndex = 0;
                    state = State.Waiting;
                }
                else
                {
                    if (MonsterReadyToMove())
                    {
                        SoundManager.Instance.PlaySound(ResManager.Instance.FootSteps);
                        state = State.MonsterMoving;
                    }
                }
                break;

            case State.MonsterMoving:
            {
                var currentMonster = monsters[currentMonsterIndex];
                if (currentMonster.NeedMoving)
                {
                    currentMonster.Move(gameTime);
                }
                else
                {
                    currentMonster.Stop();
                    if (CheckCollision())
                    {
                        SoundManager.Instance.PlaySound(ResManager.Instance.Explosion);
                        var pos = MazeObject.MapToRealPosition(currentMonster.LogicPos);
                        collision.Rect = new Rectangle(pos.X - 25, pos.Y - 25, 100, 100);
                        state          = State.Collision;
                        return;
                    }
                    SoundManager.Instance.PlaySound(ResManager.Instance.FootSteps);

                    PlayerScanning();
                    if (currentMonster.NumOfSteps == 0)
                    {
                        currentMonsterIndex++;
                    }
                    state = State.CalculateMonsterMovement;
                }
            }
            break;

            case State.PlayerMoving:
                if (player.NeedMoving)
                {
                    player.Move(gameTime);
                }
                else
                {
                    player.Stop();
                    SoundManager.Instance.PlaySound(ResManager.Instance.FootSteps);
                    if (CheckCollision(true))
                    {
                        SoundManager.Instance.PlaySound(ResManager.Instance.Explosion);
                        var pos = MazeObject.MapToRealPosition(player.LogicPos);
                        collision.Rect = new Rectangle(pos.X - 25, pos.Y - 25, 100, 100);
                        state          = State.Collision;
                        return;
                    }
                    if (GetOutOfMaze)
                    {
                        GameResult.Instance.IsWon = true;
                        GameResult.Instance.Score = 3 * numOfFreeSpace - numOfPlayerSteps;
                        EventBoard.Instance.AddEvent(EventBoard.Event.ShowResult);
                        state = State.End;
                        return;
                    }
                    for (int i = 0; i < monsters.Length; i++)
                    {
                        PlayerScanning(i);
                    }
                    numOfPlayerSteps++;
                    playerSteps.Text = "Numbers of step: " + numOfPlayerSteps;
                    state            = State.CalculateMonsterMovement;
                }
                break;

            case State.Collision:
                collision.Update(gameTime);
                endTime -= (int)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (endTime <= 0)
                {
                    GameResult.Instance.IsWon = false;
                    EventBoard.Instance.AddEvent(EventBoard.Event.ShowResult);
                    state = State.End;
                }
                break;

            case State.End:
                break;
            }
        }