2 Nov 2019, 14:29

@waldron Gotcha'! The kids are with grandma today, so I'm going to see how far I can get-- then I can just share my whole project, and you can copy out what you need! My "engine" is done, all I need to do is draw some more tiles, and put together a nice demo map.

But the gist of it is like this: I have a variable declared on the player sprite indicating which foot the player needs to use next, and which is initially set to "either". Then when I grab their input, I just toggle that variable from "left" to "right".

player.nextFoot = "either"

...

if shouldReadInput and joy.zl and !joy.zr and (player.nextFoot == "left" or "player.nextFoot == "either") then
    player.speed += 1.5
    player.nextFoot = "right"
    resetInput() // This is for my input filtering, as is "shouldReadInput"
endif

if shouldReadInput and joy.zr and !joy.zl and (player.nextFoot == "right" or "player.nextFoot == "either") then
    player.speed += 1.5
    player.nextFoot = "left"
    resetInput()
endif

// If they are going slow, let them push with either foot
if player.speed < .25 then
    player.nextFoot = "either"
endif

You could also make "player.nextFoot" "strongly-typed" by making enum-style variables, instead of using a magic string like me.

Then I handle the player rotation in a speed-dependent way, like this:

if joy.lx != 0 then
    if player.speed == 0 then
        player.rotation += joy.lx * 2
    else
        player.rotation += (joy.lx * player.speed) / 1.25
    endf
endif

The actual sprite drawing happens later on in the frame, like this:

setSpriteSpeed(player, {sin(player.rotation), -cos(player.rotation)} * player.speed * 100)

I also have lots of code to handle crashing, playing music/sfx, animation, moving the camera around to follow the player, and so forth. Once I share the whole thing, it'll make a lot more sense-- but hopefully this can at least get you going.

I don't know if you're going for a "Tony Hawk's Pro Skater"-style game, but it'd be awesome if you figured out a way to let the player "grind" on objects, like rails or steps!