-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose platform effector (#413)
- Loading branch information
1 parent
4b051ae
commit 96c2e0b
Showing
5 changed files
with
210 additions
and
14 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,75 @@ | ||
// @ts-check | ||
|
||
kaplay(); | ||
|
||
loadSprite("bean", "/sprites/bean.png"); | ||
loadSprite("coin", "/sprites/coin.png"); | ||
loadSprite("grass", "/sprites/grass.png"); | ||
|
||
const SPEED = 480; | ||
|
||
setGravity(2400); | ||
|
||
const level = addLevel([ | ||
"", | ||
"= @ $$ =", | ||
"==========", | ||
], { | ||
tileWidth: 64, | ||
tileHeight: 64, | ||
// Define what each symbol means (in components) | ||
tiles: { | ||
"@": () => [ | ||
sprite("bean"), | ||
area(), | ||
body(), | ||
anchor("bot"), | ||
z(2), | ||
"player", | ||
], | ||
"=": () => [ | ||
sprite("grass"), | ||
area(), | ||
body({ isStatic: true }), | ||
anchor("bot"), | ||
], | ||
"$": () => [ | ||
sprite("coin"), | ||
area(), | ||
body(), | ||
anchor("bot"), | ||
platformEffector({ | ||
shouldCollide(obj, normal) { | ||
if (obj !== player) return true; | ||
// Let the player push them if they hold shift | ||
if (isKeyDown("shift")) return true; | ||
if (normal.sub(LEFT).len() < Number.EPSILON) return false; | ||
if (normal.sub(RIGHT).len() < Number.EPSILON) return false; | ||
return true; | ||
} | ||
}), | ||
], | ||
}, | ||
}); | ||
|
||
// Get the player object from tag | ||
const player = level.get("player")[0]; | ||
|
||
// Movements | ||
onKeyPress("space", () => { | ||
if (player.isGrounded()) { | ||
player.jump(900); | ||
} | ||
}); | ||
|
||
onKeyDown("left", () => { | ||
player.move(-SPEED, 0); | ||
}); | ||
|
||
onKeyDown("right", () => { | ||
player.move(SPEED, 0); | ||
}); | ||
|
||
onUpdate(() => { | ||
camPos(player.worldPos()); | ||
}); |
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,84 @@ | ||
// @ts-check | ||
|
||
kaplay(); | ||
|
||
loadSprite("bean", "/sprites/bean.png"); | ||
loadSprite("steel", "/sprites/steel.png"); | ||
loadSprite("grass", "/sprites/grass.png"); | ||
|
||
const SPEED = 480; | ||
|
||
setGravity(2400); | ||
|
||
const level = addLevel([ | ||
" ##", | ||
"", | ||
" ##", | ||
"", | ||
" ##", | ||
"", | ||
" ##", | ||
"", | ||
"====##====", | ||
"", | ||
"= @ ## =", | ||
"==========", | ||
], { | ||
tileWidth: 64, | ||
tileHeight: 64, | ||
// Define what each symbol means (in components) | ||
tiles: { | ||
"@": () => [ | ||
sprite("bean"), | ||
area(), | ||
body(), | ||
anchor("bot"), | ||
z(2), | ||
"player", | ||
], | ||
"=": () => [ | ||
sprite("grass"), | ||
area(), | ||
body({ isStatic: true }), | ||
anchor("bot"), | ||
], | ||
"#": () => [ | ||
sprite("steel"), | ||
area(), | ||
body({ isStatic: true }), | ||
anchor("bot"), | ||
platformEffector(), | ||
], | ||
}, | ||
}); | ||
|
||
// Get the player object from tag | ||
const player = level.get("player")[0]; | ||
|
||
// Always look at player | ||
onUpdate(() => { | ||
camPos(player.worldPos()); | ||
}); | ||
|
||
// Movements | ||
onKeyPress("space", () => { | ||
if (player.isGrounded()) { | ||
player.jump(900); | ||
} | ||
}); | ||
|
||
onKeyDown("left", () => { | ||
player.move(-SPEED, 0); | ||
}); | ||
|
||
onKeyDown("right", () => { | ||
player.move(SPEED, 0); | ||
}); | ||
|
||
// Fall through when down is pressed | ||
onKeyDown("down", () => { | ||
const p = player.curPlatform(); | ||
if (p != null && p.is("platformEffector")) { | ||
p.platformIgnore.add(player); | ||
} | ||
}); |
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
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