This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit of polygon component. Updates types, adds the logic, and provised a real boring example in examples/ * Fixes a linting issues in examples/polygon.js * Removes extraneous comment, reorders components to polygon() is first in example * nit: Fixes newlines in import * Updates the polygon fn to return a polygon render area, which makes it so that polygons always collide with their shape not a rect * Use this.pnts instead of just pnts so we can capture any updates to points later
- Loading branch information
1 parent
0884197
commit c485a3f
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
kaboom( | ||
) | ||
|
||
// Add a thing that follows the mouse | ||
var CURSOR = "cursor" | ||
|
||
const cursor = add([ | ||
circle(10), | ||
area(), | ||
pos(), | ||
CURSOR, | ||
]) | ||
|
||
cursor.onMouseMove(pos => { | ||
cursor.pos = pos | ||
}) | ||
|
||
// Make a weird shape | ||
const poly = add([ | ||
polygon([ | ||
vec2(300,300), | ||
vec2(500,300), | ||
vec2(350,600), | ||
vec2(300,400), | ||
]), | ||
pos(80, 120), | ||
outline(4), | ||
area(), | ||
color(rgb(255,0,0)), | ||
opacity(0.2), | ||
]) | ||
|
||
// Change the color when the cursor object collides with the polygon | ||
poly.onCollide(CURSOR, () => { | ||
poly.color = poly.color.lighten(100) | ||
}) | ||
|
||
poly.onCollideEnd(CURSOR, obj => { | ||
poly.color = poly.color.darken(100) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters