private static Vector2 BlockMovement(GameField gameField, MoveObject movement, float movementY, float movementX, Vector2 gamefieldPos)
 {
     Vector2 newPosition;
     newPosition = movement.DestinationScreenPos;
     //stop against that wall.
     Rectangle targetBlock = gameField.GetBlocksRectange(gamefieldPos);
     if (movementX > 0 && movement.DestinationHitBox.Right >= targetBlock.Left)
     {
         //Set the player next the left side of the block,
         //Align the hitbox with the wall
         int actualMovement = movement.DestinationHitBox.Right - targetBlock.Left;
         newPosition.X = newPosition.X - actualMovement - 1;
     }
     else if (movementX < 0 && movement.DestinationHitBox.Left <= targetBlock.Right)
     {
         //set the player to the right side of the block
         int actualMovement = movement.DestinationHitBox.Left - targetBlock.Right;
         newPosition.X = newPosition.X - actualMovement + 1;
     }
     if (movementY > 0 && movement.DestinationHitBox.Bottom >= targetBlock.Top)
     {
         //set the player to the bottom side of the block
         int actualMovement = movement.DestinationHitBox.Bottom - targetBlock.Top;
         newPosition.Y = newPosition.Y - actualMovement - 1;
     }
     else if (movementY < 0 && movement.DestinationHitBox.Top <= targetBlock.Bottom)
     {
         //set the player to the top of the block.
         int actualMovement = movement.DestinationHitBox.Top - targetBlock.Bottom;
         newPosition.Y = newPosition.Y - actualMovement + 1;
     }
     return newPosition;
 }
 public static Vector2 CheckPlayerMovement(GameField gameField, List<BomberManGuy> players, int playerID, MoveObject movement)
 {
     Vector2 newpoint = checkCollisionWithGameField(gameField, players[playerID], movement);
     checkCollisionWithBombs();
     checkCollisionWithPlayers();
     return newpoint;
 }
        private static Vector2 checkCollisionWithGameField(GameField gameField, BomberManGuy bomberManGuy, MoveObject movement)
        {
            Vector2 newPosition = movement.DestinationScreenPos;
            float movementX = movement.DestinationScreenPos.X - movement.OrigionalScreenPos.X;
            float movementY = movement.DestinationScreenPos.Y - movement.OrigionalScreenPos.Y;
            foreach (Vector2 gamefieldPos in movement.DestinationGameFieldPosition)
            {
                foreach (GamefieldItem gamefieldItem in gameField.Gamefield[(int)gamefieldPos.X, (int)gamefieldPos.Y].Items)
                {
                    switch (gamefieldItem.CollisionType)
                    {
                        case CollisionTypes.Block:
                            newPosition = movement.DestinationScreenPos;
                            //stop against that wall.
                            Rectangle targetBlock = gameField.GetBlocksRectange(gamefieldPos);
                            if (movementX > 0 && movement.DestinationHitBox.Right >= targetBlock.Left)
                            {   //Set the player next the left side of the block,
                                //Align the hitbox with the wall
                                int actualMovement = movement.DestinationHitBox.Right - targetBlock.Left;
                                newPosition.X = newPosition.X - actualMovement - 1;

                            }
                            else if (movementX < 0 && movement.DestinationHitBox.Left <= targetBlock.Right)
                            {   //set the player to the right side of the block
                                int actualMovement = movement.DestinationHitBox.Left - targetBlock.Right;
                                newPosition.X = newPosition.X - actualMovement + 1;

                            }
                            if (movementY > 0 && movement.DestinationHitBox.Bottom >= targetBlock.Top)
                            {   //set the player to the bottom side of the block
                                int actualMovement = movement.DestinationHitBox.Bottom - targetBlock.Top;
                                newPosition.Y = newPosition.Y - actualMovement - 1;

                            }
                            else if (movementY < 0 && movement.DestinationHitBox.Top <= targetBlock.Bottom)
                            {   //set the player to the top of the block.
                                int actualMovement = movement.DestinationHitBox.Top - targetBlock.Bottom;
                                newPosition.Y = newPosition.Y - actualMovement + 1;

                            }

                            break;
                        case CollisionTypes.Moveable:
                            //something else
                            break;
                        case CollisionTypes.PowerUp:
                            //something ellie
                            break;
                        case CollisionTypes.Empty:
                        default:
                            newPosition = movement.DestinationScreenPos;

                            break;
                    }

                }
            }
            return newPosition;
        }
Example #4
0
 public BomberManInput(List<BomberManGuy> players, GameField gameField)
 {
     _players = players;
     _gameField = gameField;
     _playerControlses = new List<PlayerControls>();
     PlayerControls defaultPlayerControls = new PlayerControls(Keys.Up, Keys.Down, Keys.Left, Keys.Right, Keys.Space);
     PlayerControls defaultPlayer2Controls = new PlayerControls(Keys.W, Keys.S, Keys.A, Keys.D, Keys.G);
     _playerControlses.Add(defaultPlayerControls);
     _playerControlses.Add(defaultPlayer2Controls);
 }
 public static void CheckExplosionsOnPLayers(GameField gameField, List<BomberManGuy> bomberManGuys)
 {
     foreach (BomberManGuy bomberManGuy in bomberManGuys)
     {
         Rectangle hitBox = bomberManGuy.GetBombermanGuyPositionedHitBox(gameField.FieldScale);
         List<Vector2> hitBoxGameFieldPosition = gameField.getPosistionOfRectInGrid(hitBox);
         foreach (Vector2 gameFieldPosition in hitBoxGameFieldPosition)
         {//Is once of these vectors on an explosion, If so. DIE!!!
             if (gameField.Gamefield[(int)gameFieldPosition.X, (int)gameFieldPosition.Y].GetExplosions().Count > 0)
             {
                 bomberManGuy.Dead = true;
             }
         }
     }
 }
        private static Vector2 checkCollisionWithGameField(GameField gameField, BomberManGuy bomberManGuy, MoveObject movement)
        {
            Vector2 newPosition = movement.DestinationScreenPos;
            float movementX = movement.DestinationScreenPos.X - movement.OrigionalScreenPos.X;
            float movementY = movement.DestinationScreenPos.Y - movement.OrigionalScreenPos.Y;

            foreach (Vector2 gamefieldPos in movement.DestinationGameFieldPosition)
            {
                foreach (GamefieldItem gamefieldItem in gameField.Gamefield[(int)gamefieldPos.X, (int)gamefieldPos.Y].Items)
                {
                    switch (gamefieldItem.CollisionType)
                    {
                        case CollisionTypes.BlockBreakable:
                        case CollisionTypes.Block:
                            newPosition = BlockMovement(gameField, movement, movementY, movementX, gamefieldPos);

                            break;
                        case CollisionTypes.Bomb:
                            if (WasPlayerOnThisPointPreviously(gameField, gamefieldPos.X, gamefieldPos.Y, movement))
                            {
                                newPosition = UnRestrictedWalk(newPosition, movement);
                            }
                            else
                            {
                                newPosition = BlockMovement(gameField, movement, movementY, movementX, gamefieldPos);
                            }
                            break;
                        case CollisionTypes.PowerUp:
                            //something ellie
                            break;
                        case CollisionTypes.Explosion:
                            bomberManGuy.Dead = true;
                            break;

                        case CollisionTypes.Empty:
                        default:
                            newPosition = UnRestrictedWalk(movement.DestinationScreenPos, movement);

                            break;
                    }

                }
            }
            return newPosition;
        }
Example #7
0
 public BomberManInput(List<BomberManGuy> players, GameField gameField)
 {
     _players = players;
     _gameField = gameField;
 }
Example #8
0
        private void BuildGameField()
        {
            int sizeX = 15;
            int sizeY = 11;

            GamefieldItems[,] buildingField = new GamefieldItems[sizeX, sizeY];
            for (int i = 0; i < sizeX; i++)
            {
                for (int j = 0; j < sizeY; j++)
                {
                    List<GamefieldItem> items = new List<GamefieldItem>();
                    if ((!(i == 1 && j == 1) ^ !(i == 1 && j == 2) ^ !(i == 2 && j == 1)))
                    {
                        if ((!(i == sizeX - 2 && j == sizeY - 2) ^ !(i == sizeX - 3 && j == sizeY - 2) ^ !(i == sizeX - 2 && j == sizeY - 3)))
                        {
                            if (i % 2 == 0 && j % 2 == 0)
                                items.Add(new BrickSollid());
                            else
                                items.Add(new BrickBreakAble());
                        }

                    }
                    GamefieldItems gamefieldItems = new GamefieldItems(items);
                    buildingField[i, j] = gamefieldItems;
                }
            }
            List<GamefieldItem> brickBorderItem = new List<GamefieldItem>();
            brickBorderItem.Add(new InvisableBlick());
            GamefieldItems brickBorderItems = new GamefieldItems(brickBorderItem);

            for (int i = 0; i < sizeX; i++)
            {
                buildingField[i, 0] = brickBorderItems;
                buildingField[i, sizeY - 1] = brickBorderItems;
            }
            for (int i = 0; i < sizeY; i++)
            {
                buildingField[0, i] = brickBorderItems;
                buildingField[sizeX - 1, i] = brickBorderItems;
            }
            _gameField = new GameField(buildingField, _totalSize, _fieldSize, _fieldPosition);
        }
Example #9
0
 public bool wasPlayerOnThisPointPreviously(GameField gameField, float xPos, float yPos, MoveObject moveObject)
 {
     Vector2 topLeft = GetPosistionInGrid(new Vector2(moveObject.PreviousHitBox.Left, moveObject.PreviousHitBox.Top));
     Vector2 topRight = GetPosistionInGrid(new Vector2(moveObject.PreviousHitBox.Right, moveObject.PreviousHitBox.Top));
     Vector2 bottomLeft = GetPosistionInGrid(new Vector2(moveObject.PreviousHitBox.Left, moveObject.PreviousHitBox.Bottom));
     Vector2 bottomRight = GetPosistionInGrid(new Vector2(moveObject.PreviousHitBox.Right, moveObject.PreviousHitBox.Bottom));
     if (topLeft.X == xPos && topLeft.Y == yPos)
     {
         return true;
     }
     if (topRight.X == xPos && topRight.Y == yPos)
     {
         return true;
     }
     if (bottomLeft.X == xPos && bottomLeft.Y == yPos)
     {
         return true;
     }
     if (bottomRight.X == xPos && bottomRight.Y == yPos)
     {
         return true;
     }
     return false;
 }
 /// <summary>
 /// Check if the player was at that point previus update, for when walking on and off a bomb
 /// </summary>
 /// <param name="gameField"></param>
 /// <param name="xPos"> </param>
 /// <param name="yPos"> </param>
 /// <param name="moveObject"> </param>
 /// <returns>true if the player was on that point previously. thus ignore the bomb</returns>
 private static bool WasPlayerOnThisPointPreviously(GameField gameField, float xPos, float yPos, MoveObject moveObject)
 {
     return gameField.wasPlayerOnThisPointPreviously(gameField, xPos, yPos, moveObject);
 }