Global

Members

backgroundImg

Source:

(constant) canvasEl

Source:

(constant) ctx

Source:

(constant) cursor

Source:

debug

Source:

(constant) drawables

Source:

(constant) hoverInfoEl

Source:

(constant) keys

Source:

(constant) mousePosEl

Source:

(constant) prevKeys

Source:

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.
Source:

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.
Source:
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.
Source:
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.
Source:
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.
Source:
Returns:
The cross product.
Type
number

gameLoop()

The main game loop that updates and renders all sprites.
Source:

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.
Source:
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.
Source:

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.
Source:
Returns:
True if the polygons intersect; otherwise, false.
Type
boolean

resizeCanvas()

Resizes the canvas to match the window dimensions.
Source:

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.
Source:

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.
Source: