Esempio n. 1
0
        public void ItemBlockCollide(ICollectable item, Block block)
        {
            Rectangle itemRect     = item.GetBoundingBox();
            Rectangle blockRect    = block.GetBoundingBox();
            Rectangle intersection = Rectangle.Intersect(itemRect, blockRect);

            if (intersection.Height > intersection.Width)
            {
                if (itemRect.Right > blockRect.Left && itemRect.Right < blockRect.Right)
                {
                    item.position = new Vector2(item.position.X - intersection.Width, item.position.Y);
                    item.GoLeft();
                }
                else
                {
                    item.position = new Vector2(item.position.X + intersection.Width, item.position.Y);
                    item.GoRight();
                }
            }
            else
            {
                if (itemRect.Bottom > blockRect.Top && itemRect.Bottom < blockRect.Bottom)
                {
                    item.position = new Vector2(item.position.X, item.position.Y - intersection.Height);
                }
                else
                {
                    item.position = new Vector2(item.position.X, item.position.Y + intersection.Height);
                }
            }
        }
        public void HouseItemCollide(ICollectable item, House house)
        {
            Rectangle itemRect     = item.GetBoundingBox();
            Rectangle houseRect    = house.GetBoundingBox(house.position);
            Rectangle intersection = Rectangle.Intersect(itemRect, houseRect);

            if (intersection.Height > intersection.Width)
            {
                if (itemRect.Right > houseRect.Left && itemRect.Right < houseRect.Right)
                {
                    item.position = new Vector2(item.position.X - intersection.Width, item.position.Y);
                    item.GoLeft();
                }
                else
                {
                    item.position = new Vector2(item.position.X + intersection.Width, item.position.Y);
                    item.GoRight();
                }
            }
            else
            {
                if (itemRect.Bottom > houseRect.Top && itemRect.Bottom < houseRect.Bottom)
                {
                    item.position = new Vector2(item.position.X, item.position.Y - intersection.Height);
                }
                else
                {
                    item.position = new Vector2(item.position.X, item.position.Y + intersection.Height);
                }
            }
        }
Esempio n. 3
0
        public void PipeItemCollide(ICollectable item, Pipe pipe)
        {
            Rectangle itemRect     = item.GetBoundingBox();
            Rectangle pipeRect     = pipe.GetBoundingBox();
            Rectangle intersection = Rectangle.Intersect(itemRect, pipeRect);

            if (intersection.Height > intersection.Width)
            {
                if (itemRect.Right > pipeRect.Left && itemRect.Right < pipeRect.Right)
                {
                    item.position = new Vector2(item.position.X - intersection.Width, item.position.Y);
                    item.GoLeft();
                }
                else
                {
                    item.position = new Vector2(item.position.X + intersection.Width, item.position.Y);
                    item.GoRight();
                }
            }
            else
            {
                if (itemRect.Bottom > pipeRect.Top && itemRect.Bottom < pipeRect.Bottom)
                {
                    item.position = new Vector2(item.position.X, item.position.Y - intersection.Height);
                }
                else
                {
                    item.position = new Vector2(item.position.X, item.position.Y + intersection.Height);
                }
            }
        }