-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new body()
events, land
and headbutted
, mirrors of `headb…
#301
Conversation
…utt` and `ground`
commit:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would've done this change myself but I'm working on the rest of the game :)
also, maybe a separate issue/pr, but can an event when the object that triggered the "land" event (and itself got a "ground" event) moves away, can the object get an "unLand" event? I am calling it "unstomp" but you get the idea. Not sure exactly what the un-headbutted event should be called. |
when an object is out of a platform, it calls onCollideEnd, the same with the headbutt |
Ok, this works, but I noticed that if the player clips the corner of the button as you're jumping up on to the button, it triggers the "onCollideEnd" too, but it wouldn't be a valid "unstomped" event. How would I check if it's a valid "unstomp"? |
can you give me a playground link? |
The kaplayground doesn't have the latest version with kaplay();
loadSprite("bean", "/sprites/bean.png");
loadSprite("spike", "/sprites/spike.png");
loadSprite("grass", "/sprites/grass.png");
const SPEED = 480;
setGravity(2400);
const level = addLevel([
"@ ^ ",
"=======",
], {
tileWidth: 64,
tileHeight: 64,
pos: vec2(100, 200),
tiles: {
"@": () => [sprite("bean"), area(), body(), anchor("bot"), "player"],
"=": () => [sprite("grass"), area(), body({ isStatic: true }), anchor("bot")],
"^": () => [sprite("spike"), area(), body({ isStatic: true }), anchor("bot"), "danger"],
},
});
const player = level.get("player")[0];
const spikes = level.get("danger")[0];
onKeyPress("space", () => {
if (player.isGrounded()) {
player.jump();
}
});
onKeyDown("left", () => {
player.move(-SPEED, 0);
});
onKeyDown("right", () => {
player.move(SPEED, 0);
});
spikes.onCollideEnd(() => {
debug.log("unstomped");
});
spikes.onLand(() => {
debug.log("stomped");
}); Also, in this example the "unstomped" log occurs when you bonk the spikes from the side, and then move away (as well as the corner clipping I described above: hold arrow key to go against the spikes, while still holding the key, press space). So there needs to be more filtering on whether it's a valid "unstomp". |
onGround
andonHeadbutt
) #300