Class for anything that can be drawn with a sprite. Characters and Pickups (and other drawable game components) can extend from this class to add behavior to the sprite. Alternative, just use this class for simple or static drawings.
상속: IInteractable
예제 #1
0
        /// <summary>
        /// Sets the given Sprite one pixel off the closest side of the given Rectangle
        /// </summary>
        /// <param name="sprite"></param>
        /// <param name="rect"></param>
        /// <returns>True if the sprite's position changed, false otherwise</returns>
        public static bool setSpriteOutsideRectangle(Sprite sprite, Rectangle rect)
        {
            if (sprite.getY() + sprite.getHeight() < rect.Y && sprite.getY() != rect.Y - sprite.getHeight())
            {
                sprite.setY(rect.Y - sprite.getHeight());
                return true;
            }
            else if (sprite.getY() > rect.Y + rect.Height && sprite.getY() != rect.Y + rect.Height)
            {
                sprite.setY(rect.Y + rect.Height);
                return true;
            }

            if (sprite.getX() + sprite.getWidth() < rect.X && sprite.getX() != rect.X - sprite.getWidth())
            {
                sprite.setX(rect.X - sprite.getWidth());
                return true;
            }
            else if (sprite.getX() > rect.X + rect.Width && sprite.getX() != rect.X + rect.Width)
            {
                sprite.setX(rect.X + rect.Width);
                return true;
            }
            return false;
        }
예제 #2
0
 public static MapObject collisionWithObjectAtRelative(Sprite p_sprite, Point p_offset)
 {
     return collisionWithObjectAtRelative(p_sprite, p_offset, "Solid");
 }