• Advertisement
Sign in to follow this  

Help with jumping

This topic is 2282 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[quote name='szecs' timestamp='1318584062' post='4872457']
then you'll have to [b]pay[/b] for it. Either in nature or with hard cash.
[/quote]
So, like with pinecones, rocks and shit? ;)

[quote]
EDIT: maybe you are just on the wrong track. Wrong track = learning from others' code as a beginner. I'm sure someone can link to articles that carefully explain why this is not good (for a beginner). Learn by doing on your own. (Well, I'm against learning from tutarials too, but that's a different matter).
[/quote]

I am somewhat against tutorials that just show how instead of why. However, I think in writing [url="http://http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition.aspx"]my own tutorial[/url] I hit on the right balance. I try to take the user through the actual process, so that at points the tutorial actually goes back an reworks previous code so the user actually understands *why* you do something. Plus, its half tutorial and half instruction. Granted, someone could jump to the last chapter, grab the sample code and run from there but that's their choice.

We all learn differently and we all need to learn from something. My beef is tutorials that simply say do this then that then this, which sadly is the majority. A person isn't really learning anything from this, other than brushing up their typing skills. Now the downside is, in order to explain the why with the how, the tutorial writer needs to spend a lot more effort and the tutorials tend to be much longer.

Share this post


Link to post
Share on other sites
Advertisement
Like ive said, I knew this was going to happen, I knew you werent just going to help me with code. You are are riddles and stuff.[u] I learn by studying, you may learn differently, I don't[/u]. I don't have the personal time to invest in learning something complex, im sure you were the same (you learned in a classroom). You are all beyond that point that you are 1337.

Now asI said in my very first post on this thread, I would have liked down right help, but nope.avi, you just proxied away at the conversation. If you want to help me how I like to be helped (and stop assuming things differently, I dont want a game, I want a player), thats fine.

Thanks

Share this post


Link to post
Share on other sites
Ok, printf debugging help ahead.

Dump the offsets right before the apply_surface call, like
[code]
printf("x_offSet=%d,y_offSet=%d\n", x_offSet, y_offSet);
[/code]

Then put another one within apply_surface dumping the parameters, like:
[code]
printf("x=%d, y=%d\n", x, y);
[/code]

Run your app and study the console output.

Share this post


Link to post
Share on other sites
[quote name='DrNicholas' timestamp='1318607487' post='4872551']
Like ive said, I knew this was going to happen, I knew you werent just going to help me with code. You are are riddles and stuff.[u] I learn by studying, you may learn differently, I don't[/u]. I don't have the personal time to invest in learning something complex, im sure you were the same (you learned in a classroom). You are all beyond that point that you are 1337.

Now asI said in my very first post on this thread, I would have liked down right help, but nope.avi, you just proxied away at the conversation. If you want to help me how I like to be helped (and stop assuming things differently, I dont want a game, I want a player), thats fine.

Thanks
[/quote]

Whelp, good luck having someone make you a player who jumps, because, if you can't do that, then you won't be able to program a game either.

If you don't know what wrong with:
[code]
apply_surface( x_offSet && y_offSet, SCREEN_HEIGHT - PLAYER_HEIGHT && SCREEN_WIDTH - PLAYER_WIDTH, player, screen, &clipsRight[ frame ] );
[/code]
when the prototype for apply_surface is:
[code]void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL );
[/code]

Then, go back to the basics.

Share this post


Link to post
Share on other sites
EDIT: sigh
Dunno why I'm so upset of these spoiled brats, most newbies here on Gamedev have good attitude actually, but these few guys totally get me down

Share this post


Link to post
Share on other sites
Well, i should not be doing this, but uh, it makes me mad how people learn to program games when they dont even know basics of c++ or whatever language it might be, copying and pasting code doesnt get you anywhere, if you have to become a game programmer then you gotta work for it. Asking for help is not bad but asking others to write code for you is totally annoying especially in programming.
[code]
#include <sdl.h>
#include <iostream>
#include <sdl_image.h>
#include <string>
#include <cstdlib>
#include <ctime>

int main( int argc, char* argv[] )
{
std::srand( std::time(0) );

if( SDL_Init( SDL_INIT_VIDEO ) == -1 )
{
std::cout << "Failed to initialize" << SDL_GetError() << "\n";
return false;
}
std::atexit(&SDL_Quit);

SDL_Surface *screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
if( screen == NULL )
{
std::cout << " Failed to set video " << SDL_GetError() << "\n";
return false;
}

SDL_Surface *square = IMG_Load( "square.bmp" );
if( square == NULL )
{
std::cout << "Failed to open square" << SDL_GetError() << "\n";
return false;
}

int x = 20;
int y = 460;
int vx = 0;
int vy = 20;
int ay = 2;
bool jumping = false;
bool quit = false;
while( !quit )
{
SDL_Event event;
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_KEYDOWN )
{
switch( event.key.keysym.sym )
{
case SDLK_RIGHT: vx += square->w /3; break;
case SDLK_LEFT: vx -= square->w/3; break;
case SDLK_SPACE:
vy = 20;
jumping = true;
}

}
else if( event.type == SDL_KEYUP )
{
switch( event.key.keysym.sym )
{
case SDLK_RIGHT: vx -= square->w /3; break;
case SDLK_LEFT: vx += square->w /3; break;
if( jumping )
{
if( vy >= -20 )
{
vy = vy - ay;
y = y + vy;
}
}
if( y + square->h > screen->h )
{
y = 460;
}
}
}
if( event.type == SDL_QUIT)
{
quit = true;
}
}
SDL_Rect rect = {x, y, square->w, square->h };

x += vx;

if( jumping )
{
y -= vy;
}
if( vy >= -20 )
{
vy = vy - ay;
}
if( y + square->h > screen->h )
{
y = 460;
}
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF,0xFF,0xFF ) );
SDL_BlitSurface( square, 0, screen, &rect );

SDL_Flip(screen);
}
SDL_FreeSurface( square );
return 0;
}
[/code]

I have given you the entire code on how to make a square jump, Learn from it and see what you can do it with your game, Atleast go through some of the code and learn what it does, learn from it, DONT copy paste.
Peace.

Share this post


Link to post
Share on other sites
Justin, your code still isn't quite right. What happens when u hold down space?

Also, if holding left or right, you're going to apply double the gravity (ay) twice in one frame.

Jump velocity should be negative when 1st hitting space (moving up screen).

And, finally, as you hold down LEFT )or RIGHT) you're going to constantly increase the velocity. So, just set vx= (whatever), not vx += or vx -= when checking keys.

As I said in my 1st post, just check for space on key up, and only apply gravity when moving. Just set the velocity when checking key presses, don't apply it to x or y then.
[quote name='JustinDaniel' timestamp='1318650655' post='4872744']
Well, i should not be doing this, but uh, it makes me mad how people learn to program games when they dont even know basics of c++ or whatever language it might be, copying and pasting code doesnt get you anywhere, if you have to become a game programmer then you gotta work for it. Asking for help is not bad but asking others to write code for you is totally annoying especially in programming.
[code]
#include <sdl.h>
#include <iostream>
#include <sdl_image.h>
#include <string>
#include <cstdlib>
#include <ctime>

int main( int argc, char* argv[] )
{
std::srand( std::time(0) );

if( SDL_Init( SDL_INIT_VIDEO ) == -1 )
{
std::cout << "Failed to initialize" << SDL_GetError() << "\n";
return false;
}
std::atexit(&SDL_Quit);

SDL_Surface *screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
if( screen == NULL )
{
std::cout << " Failed to set video " << SDL_GetError() << "\n";
return false;
}

SDL_Surface *square = IMG_Load( "square.bmp" );
if( square == NULL )
{
std::cout << "Failed to open square" << SDL_GetError() << "\n";
return false;
}

int x = 20;
int y = 460;
int vx = 0;
int vy = 20;
int ay = 2;
bool jumping = false;
bool quit = false;
while( !quit )
{
SDL_Event event;
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_KEYDOWN )
{
switch( event.key.keysym.sym )
{
case SDLK_RIGHT: vx += square->w /3; break;
case SDLK_LEFT: vx -= square->w/3; break;
case SDLK_SPACE:
vy = 20;
jumping = true;
}

}
else if( event.type == SDL_KEYUP )
{
switch( event.key.keysym.sym )
{
case SDLK_RIGHT: vx -= square->w /3; break;
case SDLK_LEFT: vx += square->w /3; break;
if( jumping )
{
if( vy >= -20 )
{
vy = vy - ay;
y = y + vy;
}
}
if( y + square->h > screen->h )
{
y = 460;
}
}
}
if( event.type == SDL_QUIT)
{
quit = true;
}
}
SDL_Rect rect = {x, y, square->w, square->h };

x += vx;

if( jumping )
{
y -= vy;
}
if( vy >= -20 )
{
vy = vy - ay;
}
if( y + square->h > screen->h )
{
y = 460;
}
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF,0xFF,0xFF ) );
SDL_BlitSurface( square, 0, screen, &rect );

SDL_Flip(screen);
}
SDL_FreeSurface( square );
return 0;
}
[/code]

I have given you the entire code on how to make a square jump, Learn from it and see what you can do it with your game, Atleast go through some of the code and learn what it does, learn from it, DONT copy paste.
Peace.
[/quote]

Share this post


Link to post
Share on other sites
[quote name='BeerNutts' timestamp='1318722151' post='4872992']
As I said in my 1st post, just check for space on key up, and only apply gravity when moving.
[/quote]
While that's a totally valid solution, usually you want to implement character actions on key down events. The reason is because that's how 99% of games do it (so they'll expect it), and especially because there is a small delay between when a key is pressed down and when it is released up. Most gamers will be upset by the delay, expecting the game to respond as soon as they hit the key down.

It can work just fine in some games, but it's something to consider. Most games only allow jumping when the character is touching the ground. That way the character can't double jump, plus it can be implemented as a key down event without worry of double-processing the event.

Share this post


Link to post
Share on other sites
this thread was quite funny to read, its the common case of someone doing a few online tutorial believing they instantly know how to program and that they know best ignoring other peoples advice

Share this post


Link to post
Share on other sites
[quote name='Cornstalks' timestamp='1318723352' post='4872995']
[quote name='BeerNutts' timestamp='1318722151' post='4872992']
As I said in my 1st post, just check for space on key up, and only apply gravity when moving.
[/quote]
While that's a totally valid solution, usually you want to implement character actions on key down events. The reason is because that's how 99% of games do it (so they'll expect it), and especially because there is a small delay between when a key is pressed down and when it is released up. Most gamers will be upset by the delay, expecting the game to respond as soon as they hit the key down.

It can work just fine in some games, but it's something to consider. Most games only allow jumping when the character is touching the ground. That way the character can't double jump, plus it can be implemented as a key down event without worry of double-processing the event.
[/quote]

Well, you can do it, but the way Justin did it isn't valid. He didn't check if (!Jumping) first, which would be the way to do it. After thinking about it, it's better to do it on down press, and check if (!Jumping).

Good point.

Share this post


Link to post
Share on other sites
[quote name='DrNicholas' timestamp='1319070559' post='4874508']
[img]http://streetknowledge.files.wordpress.com/2008/09/riddler.jpg[/img]
[/quote]

You've been given lots of code help and conceptual help, from people who have successfully coded up the behavior you're looking for on their own. At this point, I think it would be safe to say that the problem is on your end, not with the code samples you've been given. If you don't understand the help that has been provided, you're simply not ready to program something like this yet.

Posting Riddler pictures gets across that you don't understand, but you don't even appear to want to understand what's going on. Your posts in this thread have are all "Write the code for me so I can understand", and then when people have [i]written the code for you[/i], rather than working to understand it or asking for help in understanding it you just say "It doesn't work, thanks for nothing. Do it again". And even when people do [i]that[/i] , or just ask you for more information so that they can help you better, you complain and say that that's not how you like to be helped. Oh, so sorry [i]sir[/i], please grace us with another opportunity to do it for you, only better.

If you want to learn how to program games or anything else, start figuring out how you could test your code to see why what you thought would work isn't working. That's programming, that's exactly it. Programming isn't taking pre-written code and then slapping new values in with no understanding of what in that code allows you to do so. Nor is it having others code your game for you and then "studying" it (i.e. having a working game feature and then not caring about how or why it works because you don't need to, since it works). If that's really the extent of what you want to do, then pick up one of the many game maker software packages out there-- they seem like they may be more your speed. You can still make cool games and do lots of scripting and have fun doing it.

But don't come in insisting that you want to learn how to draw when all you really want to do is color inside the lines someone else has drawn, and then make whining demands that can't be satisfied when it turns out that what you said you wanted isn't what you're actually trying to do.

Share this post


Link to post
Share on other sites
He's just a troll. I doubt he ever had any intention of putting forth any effort, and rather just wanted to come piss a few people off for the lolz. Let's please just let this thread die. RIP thread.

Share this post


Link to post
Share on other sites
I wanted to put forth effort, i wanted some code to start off with, not some people just gettin angry (ON STEROIDS) with me about coding... You only gave me vague riddles, you say you gave code, but it didnt work and didnt say where it goes. id still like the help put in there, but its like non e of you could bring yourselves to do such a simple task. so i just play with my raycasting engine instead.

but i voew anytime i see someone getting picked on, i shall post a picture of the riddler, and if i can help them (when i come online), i will to the best of my ability.

Share this post


Link to post
Share on other sites
[quote]I wanted to put forth effort,[/quote]

So far as the evidence in this thread goes you've not even tried to debug the code yourself leave alone try to understand it. What exactly is meant by "effort"?

And by the way, if I were you I would show some gratitude to the people who've actually bothered to take your code and worked with it to try and get the jumping code working whether the code works or not. They've spent their valuable time and effort for no material benefit. If you cannot do so, at least avoid insulting or belittling them.

Your approach is wrong. Please understand that respect works wonders. Respecting the people who're trying to help will get you far.

Share this post


Link to post
Share on other sites
I see what you did there, took a fragment of a sentence. Not to troll or flame, but quote the whole sentence.

[quote]I wanted to put forth effort, i wanted some code to start off with, not some people just gettin angry (ON STEROIDS) with me about coding.[/quote]

you just did not want to help me with a simple task, and none of you can truly answer why you did not want to put code in. you all highly disappointed me, you really dont want to teach people or help them, looking at everything your only true answer is "look in the book". Seeing as though this is the free section I suspected as much but none of you truly are charitable or wanting to help people. I already thanked them for trying to help, but i also told them their help didnt help. im surprised you all get mad easily over this. i really dont want your help anymore, i couldnt do the thing for class.

Share this post


Link to post
Share on other sites
From where I sit, you can't even put in the effort to make a coherent forum post. You haven't even put in the effort to download a [url="http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express"]working debugger[/url]. 2 people post code showing how to implement jumping and you get bitchy that they didn't [b]do your work for you.[/b]

People, programmers in particular, hate stupid, lazy, entitled, inconsiderate, ungrateful, passive-aggressive, guilt tripping, immature children. The less you look like one, the better help you'll receive. Welcome to the internet. Hopefully you'll learn [i]something[/i] if you're not a troll.

Share this post


Link to post
Share on other sites

This topic is 2282 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement