Log In  

Cart #test60fps2-0 | 2020-11-26 | Code ▽ | Embed ▽ | No License

Heya! I decided to look at my old (well a few months) game and update it to work with 60fps. One problem I've been having is the jump. It's super simple code which means when you jump in the game you jump up super fast. I'd like its acceleration to be slightly slower, and if possible, have a variable jump height. Does anyone have any code examples that could fit within my game code as it stands and make it work better/any variables that could help?

P#84706 2020-11-26 10:28

:: jmsnsh

@optimusprime i am still interested in figuring this out, if you know what to do let me know!

P#87932 2021-02-20 16:12
:: Snow_

If you take a look at the code in my game: https://www.lexaloffle.com/bbs/?tid=41585 you can see how I do jumping.

I do mario style variable height jumping and use look up tables for my vertical and horizontal speeds.

So for jumping I would do something like this:

jumpspeed={-4,-2,-1,-1,0,1,1,2,4}

So when doing a jump, I would add jumpspeed[counter] to my characters y position. The counter would start at 1 and count till 9 - effectively making the sprite move up, level off, and then fall back down.

For variable jump height, I use a boost variable. Holding the jump button increases boost. As long as boost is above 0, jumpspeed[1] is added to player's y position.

I can post some code later or I have a barebones platformer project that uses this jump code.

P#87950 2021-02-20 21:13
:: Snow_

So here's my example. It's the most simplest way to do Mario-like movement and variable jumping. It also has friction and velocity. It's based on using a look up table to determine speed rather than using division and multiplication to determine speed/friction/velocity.

--player variables
x=64
y=8
xdir=false

--movement variables
hv=5 --horizontal velocity
vv=5 --vertical velocity
boost=0 --boost is used for variable jumping
speed={-4,-2,-1,-1,0,1,1,2,4}

-->8
function _update()
    input()
    move()
    --animate()
end

function input()
    if btn(0) then --left
        xdir=true
        if(hv>1) hv-=1
    elseif btn(1) then --right
        xdir=false
        if(hv<9) hv+=1
    else
        if(hv<5) hv+=1
        if(hv>5) hv-=1
    end
    if btn(5) then --X
        if boost < 6 then
            boost+=1
            vv=1
        end
    else
        boost = 6
    end
end

function move()
    x+=speed[hv] 
    y+=speed[vv]
    if(vv<9) vv+=1
    --collision()
end

I have a barebones platformer demo that I'm just cleaning up and adding comments to. It's where the above code comes from. It includes a collision system that works with the speed values and also a simple animation function to animate a 5 frame sprite that consists of 1 frame for standing, 3 for running, and 1 for jumping. I'll be making a separate tutorial post for it this week. It's the code that I built Bullet Ball on.

P#87966 2021-02-21 08:11

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2022-07-02 01:40:56 | 0.022s | Q:15