Class Rect
A rectangle
Functions
| Rect.new (x, y, width, height) | Creates a new rectangle. |
Fields
| Rect.x | The x of the rectangle |
| Rect.y | The y of the rectangle |
| Rect.width | The width of the rectangle |
| Rect.height | The height of the rectangle |
Methods
| Rect:contains (vec) | Checks if a rect contains a point. |
| Rect:collide (targ, vel, dt) | Collides a rect with walls in the current level. |
| Rect:center () | Gets the center point of a rectangle. |
| Rect:offset (offset) | Adds a value to the location of a Rect. |
| Rect:to_screenspace () | Converts a world space Rect to screen space |
Functions
Methods- Rect.new (x, y, width, height)
-
Creates a new rectangle.
Parameters:
- x float the x position
- y float the y position
- width float the width
- height float the height
Returns:
-
Rect
the new rectangle
Fields
- Rect.x
- The x of the rectangle
- Rect.y
- The y of the rectangle
- Rect.width
- The width of the rectangle
- Rect.height
- The height of the rectangle
Methods
- Rect:contains (vec)
-
Checks if a rect contains a point.
Parameters:
- vec Vec2 the Vector to check
Returns:
-
boolean
true if the Vector is in the Rect
- Rect:collide (targ, vel, dt)
-
Collides a rect with walls in the current level.
Parameters:
- targ integer the collisions to interact with
- vel Vec2 the initial velocity of the Rect.
- dt float the time step.
Returns:
-
Vec2
the new velocity
See also:
Usage:
rect = Rect.new(20, 20, 1, 1) vel = Vec2.new(5, 5) vel = rect:collide(collision.entity, vel, dt) - Rect:center ()
-
Gets the center point of a rectangle.
Returns:
-
Vec2
the center
- Rect:offset (offset)
-
Adds a value to the location of a Rect.
Parameters:
- offset Vec2 the offset to add
Returns:
-
Rect
the new rectangle
- Rect:to_screenspace ()
-
Converts a world space Rect to screen space
Returns:
-
Rect
the new rectangle in screen space