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.

Newcomers DBPro Corner / Jumping is my nemesis

Author
Message
Touch the Skies Edge
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 18th Oct 2013 21:43
SO, I've been trying for ages to get this little beat 'em up game to work and jump. I need to be able to move up and down, left and right, and to also jump. I have directional movement, but jumping is a whole other story. Any help would be greatly appreciated.

Media is attached.
Also, how would I go about placing a stationary scenery sprite, like a tree?

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?"

Attachments

Login to view attachments
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 22nd Oct 2013 22:36 Edited at: 22nd Oct 2013 22:38
It looks like the sprite moves up 50 pixels all at one time. In order to have it jump more realistically, you could control the jump by using some variables. For example, you could use 'jumping' to equal 1 when the player first presses the spacebar, equal to 2 when the player is descending and 0 when the player is not jumping. In the code, you set the y3 variable when the jump is initiated. I would suggest that instead of doing that, you use a jump counter (maybe just call it JumpCounter) to track how many moves the player needs to make before the top of the jump is reached. Once the top has been reached, you could change the jumping variable to 2 (i.e. the player is coming down from the jump); the JumpCounter is set again and once it gets down to zero, the player is done jumping. To show this in code, it would be something like this



Quote: "
Also, how would I go about placing a stationary scenery sprite, like a tree?"


Not sure what you are asking here, as you would simply call the sprite at the spot you want it on the screen. You could then check collision with that sprite and the player's sprite quite easily and react to the collision appropriately.

Hope this helps,

LB

So many games to code.....so little time.
Touch the Skies Edge
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 23rd Oct 2013 08:49
I've tried that, and I must obviously be doing something wrong. I write it in, yet no tree.

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?"
Touch the Skies Edge
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 23rd Oct 2013 09:08
Nevermind, I was just using too large of an image to be displayed. Also, the jumping coding helped out a lot. I had to modify it a bit to fit, but it works much better than the nonsense I was using.

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?"
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 11th Nov 2013 02:21 Edited at: 11th Nov 2013 02:22
Welcome to the forum TTSE.
A few pointers on your coding style. If you group similar lines together and in the order INPUT > PROCESS > OUTPUT, besides making it look neater, this makes the program flow easier to follow and so fewer bugs will appear.


Now I'll just clean it up a bit more and remove the duplicates.


I don't know what's going on with this section, it contradicts itself:


I would suggest getting rid of all this sprite mirroring, it's very silly and a bit cruel on the computer to keep asking it to mirror and unmirror images for no apparent reason. Instead it would be better to store a mirrored version of the images before the main loop, that way you can just switch images instead of mirroring all the time.


Formerly OBese87.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 12th Nov 2013 16:58
Along with the excellent advice already posted, I would suggest that you try some velocities - really, trying to make a game like that without velocities/vectors/etc is like home dentistry.

Like, rather than having X1 Y1 Y2 etc... make yourself a common type that can wrap up these variables and make them more readable.

Type _Entity
x# y# xs# ys#
a# as#
Endtype

Now, you can make a player entity:

Global Player as _Entity

Or make a load of enemies as an array of entities:

Dim Enemy(32) as _Entity

The type components are accessed after a full stop with this... like:

If rightkey() then Player.xs#=1.0
if leftkey() then Player.xs#=-1.0
inc Player.x#,Player.y#

Okay - so you have Player.x# and y#, and you can position your sprite there at the end of the main loop - I hope you can see how that would make things more readable, and that makes coding more fun.

Now, left and right could be making the player move left and right, or it could affect a speed to give smoother movement:

`Decrease xs# gradually
if Player.xs#>0.0 then dec Player.xs#,0.01
if Player.xs#<0.0 then inc Player.xs#,0.01
`Increase or decrease xs# depending on keys
If rightkey()=1 then inc Player.xs#,0.1
If leftkey()=1 then dec Player.xs#,0.1
`Limit xs# to -1 to 1
if Player.xs#<-1.0 then Player.xs#=-1.0
if Player.xs#>1.0 then Player.xs#=1.0

So that would probably make the character move quite slippery, like when Mario runs over some ice - it can of course be tweaked easily.

K, so last thing - if you have Player.ys#, then you can easily (very easily) have awesome jumping, like a nice smooth round arc:

If spacekey()=1
if jumping=0
jumping=1
Player.ys#=-2.0
endif
Else
jumping=0
Endif
`and for gravity:
inc Player.ys#,0.1

Really, if you strip out the jumping variable, it's just setting the Y velocity to -2.0, which is probably enough to make it jump. By setting it to a high negative value, the velocity sends it up, and the velocity increases the whole time so gravity takes over. You would need to add in a check to make sure the player was on solid ground before letting them jump though - unless you like mid-air jumping

I am the one who knocks...
Touch the Skies Edge
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 18th Nov 2013 19:21
Wow, This evolved to so much more than jumping. Thank you all! In truth, I've been at such a loss with certain sections that I just tried to bullrush through the main sections, not bothering with groundwork. On top of that, I've been so bogged with all my other tasks that taking the time to work on those vectors just hasn't been found. Hopefully I will be able to fully fix the giant mess I have created finally with the spare time I've managed to find.

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 post a reply

Server time is: 2024-04-20 11:41:51
Your offset time is: 2024-04-20 11:41:51