Skip to content
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

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

lajbel
Copy link
Collaborator

@lajbel lajbel commented Aug 2, 2024

@lajbel lajbel added this to the 3001 milestone Aug 2, 2024
Copy link

pkg-pr-new bot commented Aug 2, 2024

commit: 0e831c1

pnpm add https://pkg.pr.new/kaplayjs/kaplay@301

Open in Stackblitz

Copy link
Contributor

@dragoncoder047 dragoncoder047 left a 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 :)

@dragoncoder047
Copy link
Contributor

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.

@lajbel
Copy link
Collaborator Author

lajbel commented Aug 2, 2024

when an object is out of a platform, it calls onCollideEnd, the same with the headbutt

@niceEli niceEli merged commit 97c2311 into master Aug 2, 2024
3 checks passed
@dragoncoder047
Copy link
Contributor

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"?

@lajbel
Copy link
Collaborator Author

lajbel commented Aug 3, 2024

can you give me a playground link?

@dragoncoder047
Copy link
Contributor

can you give me a playground link?

The kaplayground doesn't have the latest version with onLand() yet, but this should work (when it does):

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".

@lajbel lajbel deleted the headbutted branch August 4, 2024 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: event when an object is stomped on or headbutted (reflected forms of onGround and onHeadbutt)
3 participants