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 / Making a 2d jump?

Author
Message
someguy99
16
Years of Service
User Offline
Joined: 7th Dec 2008
Location:
Posted: 8th Dec 2008 18:43
Okay,i tryed to think of this myself,but i just cant.
What i want to do is to make a Mario-like jump.
The code should consist of the following parts:
1)mario jumps untill a specified time is over,or earlyer if the jump button is unpressed(keystate is 0).
2)then he falls down untill he hits another sprite.
The problem for me is how to count the time.Is there a command that can count the time after an event(pressing a button) has occured?
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Dec 2008 20:14
Hello,

Timer() is probably the command you want. That keeps a system time count of milliseconds that have passed.

If you set a variable equal to timer(), later you can subtract that variable from timer() and you'll get the number of ms that have passed:




Enjoy your day.
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 8th Dec 2008 22:56
What you can do is have it so that in every iteration, if mario is jumping, you subtract 1 from his vertical velocity. When you press the jump button, it sets the vertical velocity to some positive number. You then position him at his current position - his vertical velocity (note that you use minus because y increases from top to bottom, so a positive value which would make the character go up must be subtracted)

As far as the collision goes, you can use the sprite collision commands, though platformers present certain problems.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
someguy99
16
Years of Service
User Offline
Joined: 7th Dec 2008
Location:
Posted: 10th Dec 2008 15:14
OK,that 'timer()' is pretty weird to me.It starts counting from the place it stopped in the final execution(even if its compiled).
So how on earth can i set its value to 0??
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 13th Dec 2008 01:24
You can't "set" the value of timer() to a value, you just read off of its values. (it's one of those things that DB reads)

~QJ
Visigoth
20
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 13th Dec 2008 04:57 Edited at: 13th Dec 2008 05:34
I'm not sure if this will work with DBClassic, but, I wrote a snippet and put it in the codebase a while back for timer based jumping, its here:

http://www.thegamecreators.com/?m=codebase_view&i=8e05ed0bb5db30baad3eaa493c4c5037



hope it helps

someguy99
16
Years of Service
User Offline
Joined: 7th Dec 2008
Location:
Posted: 13th Dec 2008 08:02
Interesting...
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 13th Dec 2008 08:07
globals don't work in dbc.

Also, if you want a jump that is based off of the time spent in the air, there IS always physics equations.

X=.5*a*t^2+V*t+Xinit

Essentially: The position equals 1/2 times the acceleration (gravity-make sure it is negative) times the time it has been in the air squared plus its initial velocity times time plus its initial location.

Use it to plot your y location and you can either use the arrow keys to control movement left or right or you can use the same equation for the X direction (note that there is NO acceleration in the x direction, so the equation is X=V*t+Xinit)

Let me know if you need any clarifications.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Dec 2008 12:37
I think going with BN2's velocity idea is the best option; you could also use the vertical velocity for when "Mario" is falling too.
If you wanted to use timer() but starting from 0 you can store the initial value of timer() in a variable and then subract from this when you need the time. e.g.


A small program that works is better than a large one that doesn't.

DBC Challenge Rank: Rookie

Login to post a reply

Server time is: 2025-06-07 20:51:58
Your offset time is: 2025-06-07 20:51:58