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 / Programming a basic jump in a 2D game without using a physics engine.

Author
Message
99xnwreg
13
Years of Service
User Offline
Joined: 29th Jan 2011
Location:
Posted: 29th Jan 2011 22:43
Title says it all. I am very new to DarkGDK, please give me a break.

Saying that my skill with the DarkGDK library is mediocre is generous.
TheeLord
16
Years of Service
User Offline
Joined: 23rd Jan 2008
Location: Chicago
Posted: 30th Jan 2011 03:37 Edited at: 30th Jan 2011 03:45
I dont know anything about the actual 2D side of DarkGDK.. But jumping is a pretty simple thing. The object is moving fastest when it leaves the ground and will get pulled down by gravity at a constant increasing speed. so something like this..

gravity = -1;
if (dbKeyState(57) == 1) jump_vector = 20;
jump_vector = jump_vector + gravity;
object_position_y = object_position_y + jump_vector;

dbKeyState(57) == 1 would be pressing the space bar.
Make sure you check that the player is touching the ground before letting the jump_vector increase, and also check where the ground is when the player is falling so you dont go through the ground...

Hope this helps!
99xnwreg
13
Years of Service
User Offline
Joined: 29th Jan 2011
Location:
Posted: 30th Jan 2011 18:08
thanks but I don't know what you did with that last line. Where are you defining the sprite ID of the object that you want to jump? What is object_position_y?

Saying that my skill with the DarkGDK library is mediocre is generous.
TheeLord
16
Years of Service
User Offline
Joined: 23rd Jan 2008
Location: Chicago
Posted: 30th Jan 2011 18:50
object_position_y would be the verticle position of the sprite. I imagine you are doing a side scrolling type game right?
99xnwreg
13
Years of Service
User Offline
Joined: 29th Jan 2011
Location:
Posted: 30th Jan 2011 19:02
I sent you an email explaining to you all my troubles with this because I am a newbie, it takes time for my posts to get approved.

Saying that my skill with the DarkGDK library is mediocre is generous.
99xnwreg
13
Years of Service
User Offline
Joined: 29th Jan 2011
Location:
Posted: 30th Jan 2011 19:48
Hey, its 99xnwreg. Because my post is being monitored because I am new to the forum, and I want to figure this out soon, I tried you method for jumping and this is what I tried.
All what happened is that I went down about 19 pixels high, then stopped and didn't fall down. Also, in my line dbSprite(9,10,ySpriteposition9,3);, I don't know how to differentiate the x axis when jumping, so now you can only jump when you are 10 pixels across.

int gravity; //declaring gravity and jump_vector as integers
int jump_vector;
int ySpriteposition9 = 360;// the sprite ID of my character is 9. It is located default 10 pixels across, 360 pixels down( its y value); This is the equivalent to your object_position_y.




if (dbKeyState(57) == 1) //If player hits spacebar
{
gravity = -1;
jump_vector = -20; //when I set gravity at positive 20, my character went down through the floor.
jump_vector = jump_vector + gravity;
ySpriteposition9 = ySpriteposition9 + jump_vector;
dbSprite(9,10,ySpriteposition9,3);//I dont know how to differentiate the x axis please help me with that
for(int i = 2; i < 9; i++)//basic collision
{
if(dbSpriteCollision(9,i) ==1)
{
dbRotateSprite(9,180);
dbMoveSprite(9,3);
dbRotateSprite(9,0);
}
}
}
// Although the sprite will move up some pixels, it will not fall back down! Please help me.

Saying that my skill with the DarkGDK library is mediocre is generous.
Cetobasilius
14
Years of Service
User Offline
Joined: 29th Dec 2009
Location: Mexico
Posted: 31st Jan 2011 01:53
not my intention to flame anyone here, but there are tons of posts like this around the forum. as the rules suggest, you should use the search option next time.

hi
RangerEllis
13
Years of Service
User Offline
Joined: 15th Jan 2011
Location: Terrestrial Productions Current Project:
Posted: 31st Jan 2011 05:06 Edited at: 1st Feb 2011 00:52
Fellow newbs should unite. Lemme help you for a bit. Here is a code that should help you out a bit.


* That is a very basic physics engine.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 31st Jan 2011 23:37
If you don't want to use physics, you could use a simple sin() function to cause an up/down action.

The fastest code is the code never written.

Login to post a reply

Server time is: 2024-06-23 02:44:43
Your offset time is: 2024-06-23 02:44:43