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

Add sprint/running to player #142

Closed
BrianCheung1 opened this issue Oct 11, 2024 · 11 comments · Fixed by #153
Closed

Add sprint/running to player #142

BrianCheung1 opened this issue Oct 11, 2024 · 11 comments · Fixed by #153
Assignees
Labels
hacktoberfest Hacktoberfest label for 2024

Comments

@BrianCheung1
Copy link
Contributor

BrianCheung1 commented Oct 11, 2024

Want to add

Recently we've added a new energy bar to the player

I would like to add a sprint key/running animation to the player model that allows the player to move a little faster depending on how much energy the player has left

I was thinking somewhere along the lines for 25% faster if player has 50% or higher energy and 10% if the player has less than 50% energy

Files to change

I believe the only file i would need to change would be player,controls.js and specially onButtonDown for up/down/left/right and onMouseDown

I believe adding some condition like this

k.onButtonDown(['up', 'down', 'left', 'right'], (dir) => {
        if (player.isInDialog) return;
        // If three buttons are pressed, the player should not move
        if (pressed.size > 2) return;
        if (pressed.size === 0) return;
        // Also, if opposite buttons are pressed, the player should not move
        if (pressed.has('left') && pressed.has('right')) return;
        if (pressed.has('up') && pressed.has('down')) return;

        // Move the player
        const dirX = pressed.has('left') ? -1 : pressed.has('right') ? 1 : 0;
        const dirY = pressed.has('up') ? -1 : pressed.has('down') ? 1 : 0;
        const moveDir = k.vec2(dirX, dirY);
        // const speed =
        //     pressed.size === 1
        //         ? player.speed
        //         : // Dot product for diagonal movement 45%
        //           player.speed * 0.707106781188095; // 1 / sqrt(2)
        const speed =
            pressed.size === 1
                ? player.state.energy  > 50
                    ? player.speed * 1.25
                    : player.speed
                : player.state.energy > 1.25
                  ? player.speed * 0.707106781188095 * 5
                  : player.speed * 0.707106781188095;
    });

would be a step in the right direction

@hpatel292-seneca
Copy link
Contributor

@BrianCheung1 Can I work on this?

@BrianCheung1
Copy link
Contributor Author

@r4pt0s

@r4pt0s
Copy link
Collaborator

r4pt0s commented Oct 12, 2024

Absolutely @BrianCheung1.
Go for it 🎉🚀

Make sure that the character isn't moving to fast because I saw a bug where the player was then able to "jump" over the map boundaries somehow.

@BrianCheung1
Copy link
Contributor Author

You can assign this to @hpatel292-seneca as I might not be able to get to it for a little.

@r4pt0s
Copy link
Collaborator

r4pt0s commented Oct 13, 2024

Done @BrianCheung1.
Welcome @hpatel292-seneca.
Go for it 🎉🚀

@r4pt0s r4pt0s added the hacktoberfest Hacktoberfest label for 2024 label Oct 13, 2024
@hpatel292-seneca
Copy link
Contributor

Hi @BrianCheung1, I have a question. In the description you mentioned "add a sprint key/running animation,"  is it like a permanent increase in speed or like a sprint (for a few seconds)??

@BrianCheung1
Copy link
Contributor Author

@hpatel292-seneca
Personally I was thinking as long as the key is held, the player would be sprinting depending on their energy.

However it is totally up to you how you would like to implement it.

It could be a permanent speed buff, a quick dash, some other kind of movement.

@hpatel292-seneca
Copy link
Contributor

And you said 25% increase in speed if energy is greater than 50% and 10% increase in speed if energy is less than 50%, here is what I came up with

const speed =
            pressed.size === 1
                ? player.state.energy > 50
                    ? player.speed * 1.25
                    : player.speed * 1.1
                : player.state.energy > 50
                  ? player.speed * 0.707106781188095 * 1.25
                  : player.speed * 0.707106781188095 * 1.1;

@BrianCheung1
Copy link
Contributor Author

Yes that was the solution I initially came up with. I believe it currently only affects speeds when energy greater than 50% so you’ll have to add in the logic for energy under 50%

@hpatel292-seneca
Copy link
Contributor

Yea, it's checking if energy is greater than 50 and if it is then it multiplies speed by 1.25 else it multiple speed by 1.1 (10%).

Thats what you asked right is energy 50-100, 25% increase and if energy 0-50, 10% increase.

@BrianCheung1
Copy link
Contributor Author

Oh yes sorry I missed that, looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Hacktoberfest label for 2024
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants