Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Damn You, Gravity!

Touch the Skies Edge
Years of Service
User Offline
Joined: 9th Oct 2013
Posted: 15th Oct 2013 23:32
So, I've done some serious upgrades to my last code, but I still don't have the ability to jump. I'm making a beat 'em up, and the best I can do is to make a "fake jump". Some help on making a working jump would be nice.
Here's the code:

Media is attatched.

We all come to a time when we look at the entire picture and think... "Oh dear God, what horrible abomination of a code have I made?"


Login to view attachments
The Zoq2
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 17th Oct 2013 21:56
This is the wrong board for this kind of posts, its mainly for 2d graphics and not programming. Try posting in the Dark basic boards instead, you will get a lot more and better replies. I can't really help with your issue though as I havn't used DBP in years

Say ONE stupid thing and it ends up as a forum signature forever. - Neuro Fuzzy
Van B
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th Oct 2013 11:07
I think your approach to it is a bit off, that's some damn complicated code for what it has to do.

I always use velocities. Like say you have px# and py# for the players position, this is where you'd position the player sprite. Along with that, you would have pxs# and pys#, to represent the players velocity. When pressing left or right, the pxs# variable is changed, and pys# in incremented constantly to provide gravity...


inc pys#,0.1
inc px#,pxs#
inc py#,pys#

'Floor collision
if py#>400
if upkey()=1 then pys#=-3.0

sprite 1,px#,py#,1

Very basic I know, it's just there to give you an idea of one way to handle jumping and gravity. The numbers are guesswork, but if you do something like that you should be able to adjust things to suit. With this though, it's easy to do things like adding inertia to player movement, like increase or decrease pxs# rather than setting it to -1,0,1 and have it reduce or increase to 0 when the player isn't moving.

I'd also suggest making a type for this sort of movement...

Type standard
x# y# a# xs# ys# as#
Global Player as standard

Then you use Player.x#, set the sprite number to Player.spr - then this can also be used for enemies, particles, that sort of thing:

Dim Enemy(32) as standard

It's a good way to keep code neat and readable, and it makes things a lot easier to keep track off.

I am the one who knocks...

Login to post a reply

Server time is: 2024-03-03 12:04:55
Your offset time is: 2024-03-03 12:04:55