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.

DarkBASIC Discussion / Please help me with jumping

Author
Message
Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 19th Feb 2005 05:01



Okay so this is part of my code that I've been making for an engine to create a platformer in DBC. And now I want to add jumping. However I can't get jumping to work and I've looked at other code. However none of it works. One code I could jump but I couldn't move forward when I jumped which is essential so the player can jump onto the platforms. (Will add collision for those once I get jumping down.) I looked at Tifu's jumping code but couldn'e implement into my game so now I've had enough. I've tried creating my own jumping engine but only the camera would move up and down, so can anyone provide a jumping code that will alow the player to move while jumping that works with this code. Please help me as it is an essential part to the engine. Thankyou for your time.

Have a heart and join my message board.And now my messageboards work again!Woot!
Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 19th Feb 2005 09:41
Sorry for the double post but I really am in need of help.

If the code looks similar to some of the monster hunt code because I didn't know of any way to stop the character from walking off the matrix. And I altered the camera to a way I liked. Please help as I really can't add anything I want to add without jumping!

Have a heart and join my message board.And now my messageboards work again!Woot!
blueselah
20
Years of Service
User Offline
Joined: 15th Dec 2004
Location: TN, USA
Posted: 19th Feb 2005 10:50 Edited at: 23rd Feb 2005 07:46
i don't know if this will help.....but ..... this is what i would do...

first... i would have an Update() function. This function would update all objects, calculate values, and (of course) Sync.

Then i would add..

at the top of the program set these variables up...

jump=0
jumpstep=50 ` how many steps
jumpmax=500 ` maximum jump height


if keystate(57)=1
jump=1
jumpvalue=1
endif

then change the way you calculate the correct position... insted of

Position object 1,X#,Y#+12.5,Z#

use

Position object 1,x#,y#+12.5+jumpvalue,z#


then ....


if jump=1

jumpvalue=jumpvalue+jumpstep
if jumpvalue>=jumpmax then jumpstep=-jumpstep
if jumpvalue<=get ground height(1,x#,z#)
jump=0
jumpstep=-jumpstep
goto main_loop
endif

update()

endif


this would not cover collision with other objects, like your cubes in the air...... this might give you something to try....
I haven't tried this code yet.... but i hope it at least gives you some ideas.....

Good Luck!!

blueselah

Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 19th Feb 2005 10:52 Edited at: 19th Feb 2005 11:05
Well, I'll give it a try and see if it works.

OKay that code was very ahrd to work with, as was your explantion. What would I be putting in the update() function?? why would I goto loop when the code would be in the loop??

I'm confused, does anyone else have a solution? I've still attempted it but failed miserably.

Have a heart and join my message board.And now my messageboards work again!Woot!
blueselah
20
Years of Service
User Offline
Joined: 15th Dec 2004
Location: TN, USA
Posted: 19th Feb 2005 11:13
`Urbia Rising
`Main Engine
Sync On
Sync rate 60
backdrop on
fog on
fog distance 4000
global x#,y#,z#,angley#,jumpvalue,speed

jump=0
jumpstep=20
jumpmax=500
jumpvalue=0

`Variables
Vitality = 100
`Make Hero
make object cube 1,20
Color object 1,RGB(200,0,50)
Position Object 1,400,0,500
Set object collision to boxes 1
`Make Rhino Tranq
Make object sphere 2,10
position object 2,700,12.5,600
Ghost object on 2
Set object collision to spheres 2
Make matrix 1,20000,20000,20,20
`Make platforms
For C= 3 to 10
Make object cube C,40
Color object C,RGB(0,0,100)
Next C
Position object 3,400,25,800
Position object 4,400,100,1000
Position object 5,440,100,1000
Position object 6,440,100,1040
Position object 7,440,100,1130
Position object 8,440,150,1130
Position object 9,540,100,1130
Position object 10,480,100,1160

` give the ball a torchlight
make light 1
Color light 1,RGB(50,50,50)
make object sphere 11,5
color object 11,RGB(100,100,100)
hide object 11


main_loop:

Do

If keystate(17)=1 and Speed < 50
Inc Speed
XTest# = Newxvalue(X#,AngleY#,20)
ZTest# = Newzvalue(Z#,AngleY#,20)
If XTest#>0 and XTest#<20000 and ZTest#>0 and ZTest#<20000
Move object 1,2
Endif
Endif

If keystate(17)=1 and Speed >= 50
Inc Speed
XTest# = Newxvalue(X#,AngleY#,20)
ZTest# = Newzvalue(Z#,AngleY#,20)
If XTest#>0 and XTest#<20000 and ZTest#>0 and ZTest#<20000
Move object 1,4
Endif
Endif

If keystate(17)=1 and Speed >= 100
Inc Speed
XTest# = Newxvalue(X#,AngleY#,20)
ZTest# = Newzvalue(Z#,AngleY#,20)
If XTest#>0 and XTest#<20000 and ZTest#>0 and ZTest#<20000
Move object 1,6
Endif
Endif


If keystate(17)=0
Dec Speed
Endif
If Speed < 0
Speed = 0
Endif
If Speed > 100
Speed = 100
Endif

If keystate(30)=1
Yrotate object 1,Wrapvalue(AngleY#-2.5)
Endif
If keystate(32)=1
Yrotate object 1,Wrapvalue(AngleY#+2.5)
Endif


` rem ---- jumping ----
`
`
if keystate(57)=1
jump=1
endif


if jump=1

jumpvalue=jumpvalue+jumpstep
if jumpvalue>=jumpmax then jumpstep=-jumpstep
if jumpvalue<=get ground height(1,x#,z#)
jump=0
jumpstep=-jumpstep
update()
goto main_loop
endif

endif


update()



Loop

function update()
draw to front

`Huds
Ink RGB(0,0,0),0
Box 30,65,Vitality+2,85
Ink RGB(125,0,0),0
Box 31,66,Vitality+1,84
Set text font "arial"
Set text size 12
Ink RGB(255,255,255),0
text 35,53,"Vitality"


`Positioning

X# = Object position x(1)
Z# = Object position z(1)
Y# = Get Ground Height(1,X#,Z#)
Position object 1,X#,Y#+12.5+jumpvalue,Z#
objectY# = Object Position Y(1)

RX# = Object position x(2)
RZ# = Object position z(2)
RY# = Get Ground Height(1,RX#,RZ#)
Position object 2,RX#,RY#+12.5,RZ#
`Controls
AngleY# = object angle Y(1)


`Camera Positioning

`Camera
CameraZ# = Newzvalue(Z#,AngleY#-180,200)
CameraX# = Newxvalue(X#,AngleY#-180,100)
CameraY# = objecty#+75

Position camera CameraX#,CameraY#+60,CameraZ#

Point camera X#,Y#+25,Z#



`light
lightangle#=wrapvalue(lightangle#+5)
lightx#=newxvalue(x#,lightangle#,75)
lightz#=newzvalue(z#,lightangle#,75)
lighty#=y#
position object 11,lightx#,lighty#,lightz#
position light 1,lightx#,lighty#,lightz#

Sync

endfunction

Function distance(obj1,obj2)
dist=sqrt(((object position x(obj1)-object position x(obj2))*(object position x(obj1)-object position x(obj2)))+((object position z(obj1)-object position z(obj2))*(object position z(obj1)-object position z(obj2))))
endfunction dist







here this code works for me .... i am not to good with cameras....

sorry..... i tried....
Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 19th Feb 2005 11:17
Doesn't work for me in DBC because of the global line at the top. Says it's an unknown command.

Have a heart and join my message board.And now my messageboards work again!Woot!
blueselah
20
Years of Service
User Offline
Joined: 15th Dec 2004
Location: TN, USA
Posted: 19th Feb 2005 11:22 Edited at: 19th Feb 2005 11:29
`Urbia Rising
`Main Engine
Sync On
Sync rate 60
backdrop on
fog on
fog distance 4000

jump=0
jumpstep=20
jumpmax=500
jumpvalue=0

`Variables
Vitality = 100
`Make Hero
make object cube 1,20
Color object 1,RGB(200,0,50)
Position Object 1,400,0,500
Set object collision to boxes 1
`Make Rhino Tranq
Make object sphere 2,10
position object 2,700,12.5,600
Ghost object on 2
Set object collision to spheres 2
Make matrix 1,20000,20000,20,20
`Make platforms
For C= 3 to 10
Make object cube C,40
Color object C,RGB(0,0,100)
Next C
Position object 3,400,25,800
Position object 4,400,100,1000
Position object 5,440,100,1000
Position object 6,440,100,1040
Position object 7,440,100,1130
Position object 8,440,150,1130
Position object 9,540,100,1130
Position object 10,480,100,1160

` give the ball a torchlight
make light 1
Color light 1,RGB(50,50,50)
make object sphere 11,5
color object 11,RGB(100,100,100)
hide object 11


main_loop:

Do

If keystate(17)=1 and Speed < 50
Inc Speed
XTest# = Newxvalue(X#,AngleY#,20)
ZTest# = Newzvalue(Z#,AngleY#,20)
If XTest#>0 and XTest#<20000 and ZTest#>0 and ZTest#<20000
Move object 1,2
Endif
Endif

If keystate(17)=1 and Speed >= 50
Inc Speed
XTest# = Newxvalue(X#,AngleY#,20)
ZTest# = Newzvalue(Z#,AngleY#,20)
If XTest#>0 and XTest#<20000 and ZTest#>0 and ZTest#<20000
Move object 1,4
Endif
Endif

If keystate(17)=1 and Speed >= 100
Inc Speed
XTest# = Newxvalue(X#,AngleY#,20)
ZTest# = Newzvalue(Z#,AngleY#,20)
If XTest#>0 and XTest#<20000 and ZTest#>0 and ZTest#<20000
Move object 1,6
Endif
Endif


If keystate(17)=0
Dec Speed
Endif
If Speed < 0
Speed = 0
Endif
If Speed > 100
Speed = 100
Endif

If keystate(30)=1
Yrotate object 1,Wrapvalue(AngleY#-2.5)
Endif
If keystate(32)=1
Yrotate object 1,Wrapvalue(AngleY#+2.5)
Endif


` rem ---- jumping ----
`
`
if keystate(57)=1
jump=1
endif


if jump=1

jumpvalue=jumpvalue+jumpstep
if jumpvalue>=jumpmax then jumpstep=-jumpstep
if jumpvalue<=get ground height(1,x#,z#)
jump=0
jumpstep=-jumpstep
gosub update
goto main_loop
endif

endif

gosub update



Loop

end

update:
draw to front

`Huds
Ink RGB(0,0,0),0
Box 30,65,Vitality+2,85
Ink RGB(125,0,0),0
Box 31,66,Vitality+1,84
Set text font "arial"
Set text size 12
Ink RGB(255,255,255),0
text 35,53,"Vitality"


`Positioning

X# = Object position x(1)
Z# = Object position z(1)
Y# = Get Ground Height(1,X#,Z#)
Position object 1,X#,Y#+12.5+jumpvalue,Z#
objectY# = Object Position Y(1)

RX# = Object position x(2)
RZ# = Object position z(2)
RY# = Get Ground Height(1,RX#,RZ#)
Position object 2,RX#,RY#+12.5,RZ#
`Controls
AngleY# = object angle Y(1)


`Camera Positioning

`Camera
CameraZ# = Newzvalue(Z#,AngleY#-180,200)
CameraX# = Newxvalue(X#,AngleY#-180,100)
CameraY# = objecty#+75

Position camera CameraX#,CameraY#+60,CameraZ#

Point camera X#,Y#+25,Z#



`light
lightangle#=wrapvalue(lightangle#+5)
lightx#=newxvalue(x#,lightangle#,75)
lightz#=newzvalue(z#,lightangle#,75)
lighty#=y#
position object 11,lightx#,lighty#,lightz#
position light 1,lightx#,lighty#,lightz#

Sync

return


Function distance(obj1,obj2)
dist=sqrt(((object position x(obj1)-object position x(obj2))*(object position x(obj1)-object position x(obj2)))+((object position z(obj1)-object position z(obj2))*(object position z(obj1)-object position z(obj2))))
endfunction dist




sorry ... i forgot ... didn't know if globals was supported in DarkBasic Classic.... hope this helps....


if it does or don't let me know.... ok?
Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 19th Feb 2005 11:29
Ugh, I get an error at this line:
if jumpvalue>=jumpmax then jumpstep=-jumpstep
it's line 110 and it says unrecognised parameter.

Have a heart and join my message board.And now my messageboards work again!Woot!
blueselah
20
Years of Service
User Offline
Joined: 15th Dec 2004
Location: TN, USA
Posted: 19th Feb 2005 11:31
hold on...ok...i am going to install my darkbasic classic and see what is wrong...
Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 19th Feb 2005 11:33
Okay thanks, I can see your really working hard to help me and I appreciate that and I know my partner will too!

Have a heart and join my message board.And now my messageboards work again!Woot!
blueselah
20
Years of Service
User Offline
Joined: 15th Dec 2004
Location: TN, USA
Posted: 19th Feb 2005 11:38
ok....change that line from

if jumpvalue>=jumpmax then jumpstep=-jumpstep

to....

if jumpvalue>=jumpmax then jumpstep=jumpstep*-1

also you will have to change the line 3 lines below...

jumpvalue=-jumpvalue

to....

jumpvalue=jumpvalue*-1



this surely works.....i tried it in my own darkbasic classic...


Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 19th Feb 2005 11:39
Okay hold on and I'll try it.

Have a heart and join my message board.And now my messageboards work again!Woot!
blueselah
20
Years of Service
User Offline
Joined: 15th Dec 2004
Location: TN, USA
Posted: 19th Feb 2005 11:39 Edited at: 27th Feb 2005 22:35


Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 19th Feb 2005 11:43
So I tried it and well there was a problem, it jumped the first time but it was just straight up which I had already manged to do, but I couldn't jump forward. Then when I tried to jump a second time the screen was all jittery because of the camera and it wouldn't jump, any explanation for this?

Have a heart and join my message board.And now my messageboards work again!Woot!
blueselah
20
Years of Service
User Offline
Joined: 15th Dec 2004
Location: TN, USA
Posted: 19th Feb 2005 11:46
i don't know then.... are you holding down the 'w' button while you are jumping? did you cut and paste the code i put in the snippet? let me know ..... i'll keep checking....
Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 19th Feb 2005 11:49
Tried again and it worked! Thank you sooo much Bluselah you are my idol!
Do you happen to want an avatar other than that one cuz I'll make you one as a thankyou.

Have a heart and join my message board.And now my messageboards work again!Woot!
blueselah
20
Years of Service
User Offline
Joined: 15th Dec 2004
Location: TN, USA
Posted: 19th Feb 2005 11:51
if you want... that would be cool.... thanks... how long have you been programming?
Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 19th Feb 2005 11:52
Since June. I had a jump thing that worked in some other code but it just didn't translate once I had all the ground height stuff in there...

Please describe the look of the avatar so I can make it.

Have a heart and join my message board.And now my messageboards work again!Woot!
blueselah
20
Years of Service
User Offline
Joined: 15th Dec 2004
Location: TN, USA
Posted: 19th Feb 2005 11:55
i like blue... and ... i don't know... make anything... something jumping perhaps?.... lol
Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 19th Feb 2005 12:01
How about this?:

Just please upload it to your own service so you don't use up my bandwith. Thanks.

Have a heart and join my message board.And now my messageboards work again!Woot!
blueselah
20
Years of Service
User Offline
Joined: 15th Dec 2004
Location: TN, USA
Posted: 19th Feb 2005 12:12
thanks!!! cool!!!! WOW!!! YOU ROCK!!!!
Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 19th Feb 2005 12:16
Uh, thanks. Please tell me when you've uploaded it to an image hosting service like imageshack or something so I can delete it on my photobucket account.

Have a heart and join my message board.And now my messageboards work again!Woot!
blueselah
20
Years of Service
User Offline
Joined: 15th Dec 2004
Location: TN, USA
Posted: 19th Feb 2005 12:20
thanks again!!! wow!!! i am cool now...
hyrichter
21
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 20th Feb 2005 03:31
Hey, I started a 2d platform game in DBC some time ago. I kindof abandoned the project, so I'll be happy to give you the code and media I had for it. I got the movement, jumping, and most of the platform and enemy collisions done.

Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 20th Feb 2005 04:31
Thanks for the offer but I don't need it anymore because I've got the jumping dealt with.

Have a heart and join my message board.And now my messageboards work again!Woot!

Login to post a reply

Server time is: 2025-05-23 21:00:23
Your offset time is: 2025-05-23 21:00:23