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;
        }
        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 #3
0
        public void PlaceBomb(BomberManGuy bomberManGuy)
        {
            Vector2 bombpoint = GetPosistionInGrid(bomberManGuy.GetCenterOfPositionedHitBox(_fieldScale));
            if (_gamefield[(int)bombpoint.X, (int)bombpoint.Y].GetBomb() == null) //Make sure there isn't a bomb already
            {
                Bomb newBomb = bomberManGuy.GetBomb();
                if (newBomb != null)
                {
                    _gamefield[(int)bombpoint.X, (int)bombpoint.Y].Items.Add(newBomb);
                }

            }
        }