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! / OMG this is how you jump!

Author
Message
Phoenix Software
20
Years of Service
User Offline
Joined: 14th Nov 2005
Location: The Game Daemon Testing Labs :)
Posted: 5th Dec 2005 19:44
Thanks to X_MEN I modded some of his code for the jumping. So flamers you can't say I didn't say where I got some code from!

`Basic Jumping Demo
`Programmed By: **Name Erased**
`Version: 1.0 - Bulit in Graphics


`Declare variables used
`variables for cords
xpos = 100
ypos = 350

`Setup the framerate and window

`Intalize the window setup
set window on
set window title "Basic Jumping Demo - DBC - **Insert Your Name Here**"
set window layout 1,1,1
set window position 100,200
set window size 640,480

`Configurate the framerate
sync on
sync rate 30

`Hide the mouse pointer
hide mouse

`Start a new loop
do

`Clear screen so no flicker
cls

`Disable the escape key
disable escapekey

`You can show the pointer by clicking
`This is to avoid frustration to our player
if mouseclick() = 1 or mouseclick() = 2 then show mouse

`You can hide it again by pressing the enterkey
if returnkey() = 1 then hide mouse

`Draw the main character a green circle
ink rgb(0,255,0),1
circle xpos,ypos-jumping,10

`Configurate controls
if leftkey() = 1 then xpos = xpos - 7
if rightkey() = 1 then xpos = xpos + 7

`Jumping
if spacekey()=1 and jumping=0 then jump=1

if jump=1 then jumping=jumping+20
if jump=0 and jumping>0 then jumping=jumping-20

if jumping>60 then jump=0

if spacekey() = 0 then jump = 0

if rightkey() = 1 and jump = 1 then xpos = xpos + 4
if leftkey() = 1 and jump = 1 then xpos = xpos - 4

`Collision
if xpos <= 1 then xpos = xpos + 7

`Refresh the screen
sync

loop

Visit My Pointless Blog http://programmersblogjonman.blogspot.com/
Upcoming Software: Phoenix RPG Creation Kit Release Date: February 2006 Using: DarkBASIC Classic
Tapewormz
23
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 5th Dec 2005 20:35 Edited at: 5th Dec 2005 20:36
Erm...There's a little code window down there or even the code tag button for stuff like this. It makes it easier to read the post when you use those features, when including code.



ie:



Dexter
20
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Ohio
Posted: 6th Dec 2005 18:37
Credit goes to Tapewormz...

Who Dey Bengals
Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 6th Dec 2005 23:06 Edited at: 6th Dec 2005 23:07
Do you really jump like that? When I jump, I don't move at a constant speed upwards, then suddenly switch direction and travel at the same constant speed downwards. The world would be a very odd place indeed if that were the case.

Physics 101: In the world we live in, you are constantly accelerating towards the centre of the Earth (acceleration due to gravity), but this can be approximated as downwards in a simulation on this scale. The reason you jump is because you apply a force on the ground you are standing on. When you apply a force, the Earth applys an equal and opposite force against you. This force causes you to accelerate upwards and leave the ground. Since this force is applied for such a short amount of time, it can simple be simulated as a single increase in vertical velocity (an impulse). Once you have left the ground, you can no longer apply a force on the Earth, and so the only force acting on you is the gravitational force. This force causes your vertical velocity to steadily decrease to 0, this point is the peak of your jump. Your velocity will then start to increase the opposite way (this can be simulated as a negative velocity), as you accelerate towards the Earth. When you hit the ground again, a force is applied which stops your acceleration, and keeps you steady. It would be easier in the simulation just to set the vertical position to the ground level, and vertical velocity to 0 if you are below the ground.

This is actually how jumping should be simulated:



Takeshii
22
Years of Service
User Offline
Joined: 15th Feb 2004
Location:
Posted: 7th Dec 2005 19:17 Edited at: 7th Dec 2005 19:19
Well then, if you want to be specific, there is wind resistance, and you cannot change direction while in motion unless acted upon from another force...



Dark
TDK I Love you...... And yes, you should be scared
Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 7th Dec 2005 23:09
Yeah yeah, you could get as complicated as you like, and admittedly in a real game you would not have your character suddenly changing direction in mid-air. However, many games do allow you to have some control over the movement of your characters while they are in the air, just for the playability factor. However, proper vertical jumping motion is included in most games. Jerky up and down is so easy to correct, and actually makes things harder to handle in the long term.

Takeshii
22
Years of Service
User Offline
Joined: 15th Feb 2004
Location:
Posted: 8th Dec 2005 01:06
"many games do allow you to have some control over the movement of your characters while they are in the air"

Hehe...ya. Some even let you double-jump .

In my early days I had lots of problems with jerky motions, as I added more and more laws of motion. Then I got smart did all the math with solver variables and then the amount stored in those vars are added subtracted devided and whatnot from/to the acutual movement vars.

MMMmmm...

Dark
TDK I Love you...... And yes, you should be scared

Login to post a reply

Server time is: 2026-07-06 17:11:57
Your offset time is: 2026-07-06 17:11:57