Ejemplo n.º 1
0
 public Building builder(BuildingType type, Vector2 location)
 {
     factory = new SpriteFactory();
     if (type == BuildingType.pokeCenterLeft)
     {
         state = new BuildingTileState(SpriteFactory.sprites.pokeCenterLeft);
     }
     if (type == BuildingType.pokeCenterRight)
     {
         state = new BuildingTileState(SpriteFactory.sprites.pokeCenterRight);
     }
     Building product = new Building(state, location);
     return product;
 }
Ejemplo n.º 2
0
        public void PlayerTileCollide(Player player, Building building)
        {
            Rectangle playerBox = player.state.GetBoundingBox(player.position);
            Rectangle buildingBox = building.GetBoundingBox();
            int middle = buildingBox.Left + buildingBox.Width / 2;
            int right = buildingBox.Right;

            Rectangle intersection = Rectangle.Intersect(playerBox, buildingBox);

            if (intersection.Height > intersection.Width)
            {
                if (playerBox.Right > buildingBox.Left && playerBox.Right < buildingBox.Right)
                {
                    player.position.X -= intersection.Width;
                }
                else
                {
                    player.position.X += intersection.Width;
                }
            }
            else if (intersection.Height < intersection.Width)
            {
                if (playerBox.Bottom > buildingBox.Top && playerBox.Bottom < buildingBox.Bottom)
                {
                    if (intersection.Height > 1)
                    {
                        player.position.Y -= intersection.Height;
                    }
                }
                else if (playerBox.Location.X > middle && playerBox.Location.X < right && building.isDoor)
                {
                    game.prevPlayerPosition = game.level.player.position;
                    game.transition = true;
                    game.level = new Level(building.destination, game);
                    game.keyboard = new KeyboardController(game.level.player, game);
                }
                else
                {
                    player.position.Y += intersection.Height;
                }
            }
        }