Log In  

I am playing around with the wander demo so I can experiment with y axis movement to make a beat em up style game but i still want to be able to jump (in cases to dodge and platform in certain sections)

Here is the code if any of you are wondering:

function _init()

x=24 y=24 -- position (in tiles)
dx=0 dy=0 -- velocity
f=0 -- frame number
d=1 -- direction (-1, 1)
acc=0.5
boost=.5
end

function _draw()
cls(1)

-- move camera to current room
room_x = flr(x/16)
room_y = flr(y/16)
camera(room_x*128,room_y*128)

-- draw the whole map (128⁙32)
map()

-- draw the player
spr(65+f,      -- frame index
 x*8-4,y*8-4, -- x,y (pixels)
 1,1,d==-1    -- w,h, flip
)

end

function _update()

ac=0.1 -- acceleration

if (btn(⬅️)) dx-= ac d=-1
if (btn(➡️)) dx+= ac d= 1
if (btn(⬆️)) dy-= ac
if (btn(⬇️)) dy+= ac

-- move (add velocity)
x+=dx y+=dy

-- friction (lower for more)
dx *=.7
dy *=.7

-- advance animation according
-- to speed (or reset when
-- standing almost still)
spd=sqrt(dx*dx+dy*dy)
f= (f+spd*2) % 4 -- 4 frames
if (spd < 0.05) f=0

-- collect apple
if (mget(x,y)==10) then
    mset(x,y,14)
    sfx(0)
end

end

I wanted to add something along the lines of
--jump
if (btnp(x)) then
player.dy=player.boost

Am I missing something?

P#107581 2022-02-24 05:30

1

Putting aside how the graphics work, how many axes of movement are you going to be using? The wander demo is 2 for a top-view ability to walk around, and you've mentioned the ability to jump. That sounds like 3. If so, you'd be better off using a third axis of movement.

That's not to say it's impossible to do it with only 2 axes. It's just that it would feel more like a dash rather than a jump. If you do go with that, then you'll need some way to keep track of when the jump ends so that you can hold off on any interactions with the environment or other characters. That could be done by just having a variable called "airtime" or something similar that counts down the number of frames in the air. You'll also need to decide if the player can jump through enemies and, if so, what happens when the player lands on an enemy.

If you use a third axis, the usual name would be z (following x and y). The way to keep track of the movement would be to set dz the same way you would set dy, but use a variable for gravity instead of acceleration that keeps the character going less up and more down each frame. From there, the z would then need to be clamped to 0 or where ever the current floor is. Then you could have the effects of the environment or other characters only occur when z is back to floor level. Lastly, to show both on a 2d plane, you simply add or subtract z from y when drawing the player character (depending on whether you have z going up or down).

P#107586 2022-02-24 08:34

I didn't think about adding/implementing a third axis of movement, I didn't know it was possible. Do you have an example of how to write the statement? I only used the wander demo to figure out how to walk along the y axis as in my own title I can only jump but not walk. Imagine the style of final fight but with a sonic or megaman jump. If player lands on enemy it equals a hit point

P#107588 2022-02-24 09:16

Using the previous code as a base, here's how you'd add a third axis to the movement:

function _init()

x=24 y=24 -- position (in tiles)
dx=0 dy=0 -- velocity
f=0 -- frame number
d=1 -- direction (-1, 1)
acc=0.5
boost=.5

-- z axis variables
z=0 dz=0
grav=.03

end

function _draw()
cls(1)

-- move camera to current room
room_x = flr(x/16)
room_y = flr(y/16)
camera(room_x*128,room_y*128)

-- draw the whole map (128⁙32)
map()

-- drop shadow
rectfill(x*8-2,y*8+2,x*8+2,y*8+3,1)

-- draw the player
spr(65+f,      -- frame index
 x*8-4,y*8-4-z*8, -- x,y (pixels) --adding the z as an offset 
 1,1,d==-1    -- w,h, flip
)
end

function _update()

ac=0.1 -- acceleration

if (btn(⬅️)) dx-= ac d=-1
if (btn(➡️)) dx+= ac d= 1
if (btn(⬆️)) dy-= ac
if (btn(⬇️)) dy+= ac
if (btn(❎) and z==0) dz=boost
dz-=grav    -- gravity is a constant acceleration regardless of speed

-- move (add velocity)
x+=dx y+=dy 

-- move in the z direction too
z+=dz

-- keep z at a minimum so the character doesn't fall infinitely
if (z<0) z=0

-- friction (lower for more)
dx *=.7
dy *=.7

-- advance animation according
-- to speed (or reset when
-- standing almost still)
spd=sqrt(dx*dx+dy*dy)
f= (f+spd*2) % 4 -- 4 frames
if (spd < 0.05) f=0

-- collect apple
if (mget(x,y)==10) then
    mset(x,y,14)
    sfx(0)
end
end

The drop shadow is important because otherwise it can be really hard to tell where the player character is mid-jump. It doesn't have to be a rectangle though. This code would get you a non-variable jump similar to what most isometric games had back when 3d wasn't popular. A more platformer-ish jump would also need to vary the amount that dz decreases based on whether the jump button is being held down.

P#107589 2022-02-24 10:06

[Please log in to post a comment]