Members
backgroundImg
(constant) canvasEl
(constant) ctx
(constant) cursor
debug
(constant) drawables
(constant) hoverInfoEl
(constant) keys
(constant) mousePosEl
(constant) prevKeys
Methods
autoGenerateHitbox(sprite, alphaThresholdopt)
Automatically generates and assigns a hitbox polygon to a sprite.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
sprite | Sprite | The sprite object. | ||
alphaThreshold | number | <optional> | 10 | Alpha threshold for hitbox generation. |
convexHull(points) → {Array.<Object>}
Computes the convex hull of a set of points using the Graham Scan algorithm.
Parameters:
| Name | Type | Description |
|---|---|---|
points | Array.<Object> | Array of points. |
Returns:
Array of points representing the convex hull.
- Type
- Array.<Object>
createSprite(xopt, yopt, coloropt, …imageSrcs) → {Sprite}
Creates a new sprite and adds it to the list of drawable objects.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
x | number | <optional> | 0 | Initial x-coordinate. |
y | number | <optional> | 0 | Initial y-coordinate. |
color | string | <optional> | 'white' | The sprite's color. |
imageSrcs | string | <repeatable> | One or more image source URLs. |
Returns:
The newly created sprite.
- Type
- Sprite
createText(x, y, color, text, fontopt) → {Text}
Creates a new text object and adds it to the list of drawable objects.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
x | number | The x-coordinate. | ||
y | number | The y-coordinate. | ||
color | string | The text color. | ||
text | string | The text content. | ||
font | string | <optional> | "20px monospace" | The font style. |
Returns:
The newly created text object.
- Type
- Text
cross(o, a, b) → {number}
Computes the cross product of vectors OA and OB.
Parameters:
| Name | Type | Description |
|---|---|---|
o | Object | The origin point. |
a | Object | Point A. |
b | Object | Point B. |
Returns:
The cross product.
- Type
- number
gameLoop()
The main game loop that updates and renders all sprites.
generateHitboxFromImage(image, alphaThresholdopt) → {Array.<Object>}
Generates a hitbox polygon for an image by scanning its pixels.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
image | HTMLImageElement | The image element. | ||
alphaThreshold | number | <optional> | 10 | Alpha threshold for edge detection. |
Returns:
An array of points representing the convex hull of the hitbox.
- Type
- Array.<Object>
hide(object)
Hides a drawable object.
Parameters:
| Name | Type | Description |
|---|---|---|
object | Drawable | The object to hide. |
polygonsIntersect(poly1, poly2) → {boolean}
Determines if two polygons intersect using the Separating Axis Theorem.
Parameters:
| Name | Type | Description |
|---|---|---|
poly1 | Array.<Object> | Array of points defining the first polygon. |
poly2 | Array.<Object> | Array of points defining the second polygon. |
Returns:
True if the polygons intersect; otherwise, false.
- Type
- boolean
resizeCanvas()
Resizes the canvas to match the window dimensions.
setBackground(src)
Sets the background image of the document. If the source is empty or the image fails to load, the background is set to black.
Parameters:
| Name | Type | Description |
|---|---|---|
src | string | URL of the background image. |
Type Definitions
Cursor
Type:
- Object
Properties:
| Name | Type | Description |
|---|---|---|
x | number | Current x-coordinate of the cursor. |
y | number | Current y-coordinate of the cursor. |
isDown | boolean | Whether the cursor button is pressed. |
left | boolean | Whether the left button is pressed. |
right | boolean | Whether the right button is pressed. |