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.

Dark GDK / Jumping sprites, 2d

Author
Message
Netjack
15
Years of Service
User Offline
Joined: 18th May 2009
Location:
Posted: 18th May 2009 20:58 Edited at: 19th May 2009 17:39
Ok, so first off, I would like to say that Dark GDK seems pretty useful from my initial experience. It seems to be simpler then attempting to do everything raw.

I have taken several programming classes at my college, but none of them when very deep, or complex. The most difficult thing we made was a text based adventure.

A few questions have raised, first, I am using visual Studio express C++
http://gdk.thegamecreators.com/?f=downloads everything from that page. So would this count as Dark GDK, Dark GDK .net, or even something else?

Next, I looked with the Search bar, but everything was for 3d based programs, or it was for another language. I am attempting to make a 2d one for c++.

I had thought to do something simple such as




but that does not work well at all, since the sleep function would freeze the entire program. I wanted to basically delay the it so that you would return to where you started.

I also noticed that even if it did what I wanted it to, you could press rapidly on the up key, you would continue fly upwards.

I also haven't taken into account how platforms on different heights would even work.



Sorry for the bad grammar.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 19th May 2009 09:12 Edited at: 19th May 2009 09:14
Your first question: what you downloaded from that page is DarkGDK. For the .NET version see the info here: http://gdk.thegamecreators.com/?f=dgdk_net

Second question: Jump is usually implemented (either 2D or 3D) by giving the character (sprite) a starting vertical speed, then decreasing that every frame by a certain value, which represents gravity. The result is that the sprite will move upwards but with decreasing speed, then start to fall when the vertical speed changes into the negative range. Then you need a condition to check when the sprite hits the ground level again, which can be either a collision check or just a simple coordinate check. Another flag is needed to check if the sprite is currently in a jump, because then if the player hits the jump key again, you don't want to do anything. (Unless your game allows an even higher jump by pressing the key again while in the air - some games do that.)

So the code structure would be something like this, roughly:



You can fine-tune this. Beware, it won't work as it is, because it will be so fast that the whole jump is a split second. For testing, you can try to insert dbWait command just before dbSync, to make the program wait half a second at least in every loop. That is only a testing method and does not make up for a better code. In the end, instead of frame-based movement (which will give you a different speed on each computer) you will want to implement timer-based movement, by making use of the dbTimer function. Then your speed and gravity values can be exactly measured in "pixels per second" or whatever the measurement unit of your game is. Also, I used integers here but actually coordinate and speed values should be floats, since the movement during one frame can be very small.
Netjack
15
Years of Service
User Offline
Joined: 18th May 2009
Location:
Posted: 19th May 2009 17:42
Thank you very much, I will try this when I get home later. If anyone else have any other suggestions I would be happy to see them.
infinite people
16
Years of Service
User Offline
Joined: 20th May 2008
Location:
Posted: 20th May 2009 06:22
What NetJack said is all you need to get the jump function to run.
The idea is that, the game implements a unending loop while it is running. You can take advantage of this loop to create animations and similar task.

Like in the case of the jump, what you simply do is to change the Y-coordinate of your character (image) by a specified value within a number of loops to take it to its maximum height and bring it back to a reference.

In the case of the sleep(..), it is not the right way to implement such routines you should use booleans and counters to produce delay effects when it is desired.

Finally avoid creating iterations in the main update loop, since it is already and iteration. Good luck

is there a witness in the house?
good people
Netjack
15
Years of Service
User Offline
Joined: 18th May 2009
Location:
Posted: 20th May 2009 16:31
Ok, it worked like a charm.

Quote: "What NetJack said is all you need to get the jump function to run.
The idea is that, the game implements a unending loop while it is running. You can take advantage of this loop to create animations and similar task.

Like in the case of the jump, what you simply do is to change the Y-coordinate of your character (image) by a specified value within a number of loops to take it to its maximum height and bring it back to a reference.

In the case of the sleep(..), it is not the right way to implement such routines you should use booleans and counters to produce delay effects when it is desired.

Finally avoid creating iterations in the main update loop, since it is already and iteration. Good luck"


Indeed, booleans work very well.

Now I need to figure out a way to make each platform have a different elevation on the Y-axis. I am not to sure who I would approach this. Should I make the different platforms be as different sprites, and if the main sprite comes into contact with it, it stops moving on the Y-axis. If I do that, then you could no longer jump while touching the platform.

Login to post a reply

Server time is: 2024-11-05 18:53:14
Your offset time is: 2024-11-05 18:53:14