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 / What am i doing wrong?

Author
Message
BernardBlack
13
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 7th Mar 2011 18:27
Ok i need a simplest possible jump code for sprites.. yes yes i know, i've searched the forum and yet again i'm doing something wrong
so here's my little piece of code
this is in my main while(LoopGDK()) loop
a quick answer would be nice ^^ cheers


No Signature ORLY?
BernardBlack
13
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 7th Mar 2011 23:40
come on any1?

No Signature ORLY?
iSilver
13
Years of Service
User Offline
Joined: 20th Feb 2011
Location:
Posted: 8th Mar 2011 14:46
For Jump, it's a continuous animation that goes every frame (inside the While(DarkGDK()) loop. For each frame, I'd detect whether or not the object is on the ground (Height == 0). If it's not on the ground, subtract Height by a bit. If it is on the ground, then you can hit Space to jump.

I'm not too familiar with Dark GDK and don't have the references at hand, but I think it would go something like this:



Note some of the commands might be totally wrong. Again, I have no db Command reference here at work.

Hope this Helps!
BernardBlack
13
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 9th Mar 2011 14:17
i think that a problem with this code is that it will only jump on the ground level, but if i'm on a platform for example i will already be > maxHeight, however i still cannot compile it, still searching for some error or something
but still thanks a lot

No Signature ORLY?
DeadTomGC
14
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 9th Mar 2011 18:11 Edited at: 9th Mar 2011 18:55
Okay, that is not going to make a very good looking jump. I would suggest making the object accelerate as it falls. This will make it a bit more complicated to calculate the max height, but I will give you a code sample in just a few minutes, hopefully.

Edit:
OK, here it is:
methjump.h:

main.cpp

Ignore the comments in main.

This code causes sprite 1 to jump the height abs(height) and to fall the same way an object affected by gravity would. It accelerates grav per frame.

the line "vely=-dbSqrt(-2.*grav*(height));" calculates the starting velocity needed to reach the relative height given.

I hope this solves your problems. Keep in mind that you can include this header in any project and use the method in the same way.

I'll get a new signature someday.
BernardBlack
13
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 9th Mar 2011 19:53
you my good sir are a saint!!!! thanks a million!

No Signature ORLY?
BernardBlack
13
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 10th Mar 2011 00:36
i would just like to help fellow indie programmers
with this code that Dead Tom helped me with
this is basic code for any sidescroller you may need all together with jumping and moving and basic collision
cheers and i hope this helps someone


also any suggestions would be nice
and thank you Tom once again

No Signature ORLY?
BernardBlack
13
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 10th Mar 2011 14:36
ok now i have a new problem that i cannot work out -.- i've been banging my head over this since tom gave me the code...
the problem may be with me not understanding tom's equasion...
my problem is i have no collision with platforms when i hit them from BELOW when i fall on them it's fine, but from below i just jump right through them or get stuck in them...help? this is becoming insanely frustrating
tx in advance

No Signature ORLY?
DeadTomGC
14
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 11th Mar 2011 01:46
The equation that I gave you is just the physics equ. vf^2=vi^2+2a(yf-yi) manipulated to solve for vi.
It just gives the starting velocity and should not effect collisions.

Hopefully I will be able to give you a good solution to this.
A long time ago I made a pretty good 2D collision system, but for some reason the program it is running in does not work any more.

Let me see if I can extract the code for the collisions.

I'll get a new signature someday.
BernardBlack
13
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 11th Mar 2011 12:00
then i'd love you even more

No Signature ORLY?
DeadTomGC
14
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 12th Mar 2011 04:19 Edited at: 12th Mar 2011 04:19
OK! I got it! I think it is even better now than it was.
I integrated it into the code I had originally.
Now you may want to pay attention to the comments in the main.cpp.
main.cpp:


methjump.h:


This is a great Collision set up for any 2D game, but you may what to loop through a bunch of objects, some of which could be baddies. So, I would suggest using arrays with 2 or more dimensions to keep track of all the world objects and baddies along with their attributes.

Also, If you want the screen to scroll to follow the character you will need to move all other objects to in the opposite direction of travel while keeping the character still. Arrays will prove to be helpful here as well.

I hope you find this helpful!

I'll get a new signature someday.
iSilver
13
Years of Service
User Offline
Joined: 20th Feb 2011
Location:
Posted: 13th Mar 2011 16:40
You know, I started writing some collision code and object interactions in DarkGDK, then I discovered physics wrappers and collision plugins such as Sparky's Collision, matty_halewood's Fulcrum Physics (which I currently use), and _Pauli_'s QuickODE
DeadTomGC
14
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 13th Mar 2011 16:44
I've seen all those, but I thought that they can only be used on 3D objects.

Login to post a reply

Server time is: 2024-09-28 12:40:54
Your offset time is: 2024-09-28 12:40:54