25 virtual void draw()
const = 0;
28 virtual void setPos(
double x,
double y);
31 template <
class Vect>
void setPos(Vect p) {
48 void setLeft(
double x);
52 void setTop(
double y);
56 void setRight(
double x);
60 void setBottom(
double y);
90template <
class Box>
bool contains(
const Box& box,
const Vec2 point) {
91 return (box.getX() <= point.
x && point.
x < box.getX() + box.getWidth() &&
92 box.getY() <= point.
y && point.
y < box.getY() + box.getHeight());
Contains jngl::Vec2 class.
Base class for drawable objects with a position and a rectangle size.
double getBottom() const
Returns the distance from the bottom of the screen.
virtual void draw() const =0
Called when drawing a frame.
double getTop() const
Returns the distance from the top of the screen.
virtual void setPos(double x, double y)
Sets the position of the top-left of the Drawable.
void setCenter(Vect c)
Centers the Sprite at c (e.g. jngl::Vec2)
bool contains(jngl::Vec2 point) const
Returns whether point is inside the bounding box.
void drawBoundingBox() const
Draws a red box around the Drawable.
virtual void step()=0
Advance object's state.
float getWidth() const
Returns the width in screen coordinates.
double getRight() const
Returns the distance from the right side of the screen.
jngl::Vec2 getCenter() const
Returns the position of the center of the Drawable.
float getHeight() const
Returns the height in screen coordinates.
Vec2 getSize() const
Returns {width, height} in screen coordinates.
virtual void setCenter(double x, double y)
Centers the Sprite at (x, y)
void setPos(Vect p)
Sets the position of the top-left of the Drawable.
double getLeft() const
Returns the distance from the left side of the screen.
bool contains(const Box &box, const Vec2 point)
Pass any class that implements getX(), getY(), getWidth() and getHeight()