Help with jumping

Started by
43 comments, last by Tom Sloper 12 years, 5 months ago

Like I said in my first post, I knew this was going to happen, I knew how asking for help from here would go?
= help

I can work on a game after I get things all set up, I always start with the player, then enemy AI should be easy, and so should everything else (until you get to level editing lol)

And I didnt have fully updated code in the .zip, it should be up to date, where y_offset is placed. All that happens is the character starts in the top left corner, and when you press space its like a tiny pixel shift jump while stuck in the jump animation.


On Computer screens, where is 0, 0? If a player wants to "jump" (move up on the screen) what should the y value do, grow larger, or smaller?

Quit being so defensive. You could debug it if you knew what you were doing. Dev-C++ has debuging capability (I used it 2005, last time it was released). Codeblocks runs on any Windows XP, Vista, or Win 7.


If you knew how to program this stuff so well, then you wouldn't be on here, struggling with these simple concepts. This isn't a "C++" thing, this would happen in any programming language.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

Advertisement
Have you tried Visual Studio?
Your going to have to help us to help you - your not making it easy for the people trying to help you. Rather than posting your code in a zip file, post it directly on the forum, most people are not going to be bothered to download and compile your source - they will just move onto the next post.

Second, you need to tell us why it isn't working. give us a walk through of what you think should be happening, then tell us what is actually happening. give us error messages.

Third, programming isn't about writing code - that is the end product, the job of a programmer is problem solving. Tell me in english how you would make the character jump. If you can't do that, then your not going to be able to tell the computer how to do it in code.
Theres one thing i have to say you.
In programming you dont learn by asking other, Make mistakes and learn from your own mistakes that's the way to learn programming, i can see a junk of code being copy pasted in your code. I just gave you an idea on how jumping works you gotta learn from it, not just blindly copy paste.
Anyhow for your code.
Lets go to your "player.h" file

#ifndef PLAYER_H
#define PLAYER_H

#include "timer.h"

//The dimmensions of the player
const int PLAYER_WIDTH = 32;
const int PLAYER_HEIGHT = 32;

//The status of the player
//standing
const int PLAYER_STAND = 0;
//walking right/left
const int PLAYER_RIGHT = 1;
const int PLAYER_LEFT = 2;
//jumping
const int PLAYER_JUMP = 3;
const int PLAYER_FALL = 4;

//Telling whether or not to use animation for the player
int PLAYER_WALKING = false; //true if walking, false if everything else

//The player
class Player
{
private:
//The offset
int x_offSet;
int y_offSet;

//Its current frame
int frame;
Timer playerTimer;

//Its animation status
int status;
int vertical_status;

enum Vertical_States
{
V_JUMPING_UP,
V_APEX_REACHED,
V_FALLING,
V_GROUNDED
};

// jumping-related stuff for now
static const int gravity = 4;
int jump_apex;

int x_pos; // horizontal position
int x_velocity; // horizontal velocity

int y_pos; // vertical position
int y_velocity; // vertical velocity
int y_acceleration;
int Jumping;

int surface_height; // last known good level to stand at

public:
//Initializes the variables
Player();

//Handles input
void handle_events();

//Moves the player
void move();

void updatePosition();

//Shows the player
void show();

//The jumping/falling/and ground with the player
void handleJumping();
void fall();
};

#endif


Thats what i call A Junk of unused codes in a class. Lets see,
You have a enum state in your class and you never use it.
static const int gravity = 4 ?? I dont see you using it anywhere
And what's int jump_apex;
There are many more errors and void's which you never call from your class and they are useless. So try to create your class in sort of a decent way and just store variables which your going to use.
The main issue is, I dont get it why it doesnt work for you, Even i follow that method to produce a jumping state,
Anyways in Line 224 try taking away that break; statement, I dont know if that might work just try it
we all just gave you an idea what jumping is and its upto you we can't help you more or Just type the code for you, You will never learn if you dont learn from your mistakes.

Tell me in english how you would make the character jump. If you can't do that, then your not going to be able to tell the computer how to do it in code.


I just wanted to quote this for emphasis. If you can clearly explain the behavior what you want in detail, then you almost only have to translate that to the programming language of your choice (translation means simply mapping the expressions to the proper syntax) Shit, I'm sure that doesn't mean what I wanted...

To the OP: if you want code, and you basically want someone else to do the work (writing code is jack shit itself, debugging and problem solving is the real work), then you'll have to pay for it. Either in nature or with hard cash.
People who asked for solutions in my university (the "do it for me" kind of request, like you do) either paid in cash or in beer, and no body liked them. They were the parasites, who eventually (after 7-8 years instead of the 5) got their degree, but went nowhere from there.

Asking for ready solutions can happen from time to time, anything can happen, life is just like that, but doing the same with your own hobby is a mystery for me. Like asking someone else to do the "hard work" on your girlfriend....

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).

then you'll have to pay for it. Either in nature or with hard cash.

So, like with pinecones, rocks and shit? ;)


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 my own tutorial 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.
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. I learn by studying, you may learn differently, I don't. 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
Ok, printf debugging help ahead.

Dump the offsets right before the apply_surface call, like

printf("x_offSet=%d,y_offSet=%d\n", x_offSet, y_offSet);


Then put another one within apply_surface dumping the parameters, like:

printf("x=%d, y=%d\n", x, y);


Run your app and study the console output.

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. I learn by studying, you may learn differently, I don't. 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


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:

apply_surface( x_offSet && y_offSet, SCREEN_HEIGHT - PLAYER_HEIGHT && SCREEN_WIDTH - PLAYER_WIDTH, player, screen, &clipsRight[ frame ] );

when the prototype for apply_surface is:
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL );


Then, go back to the basics.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)


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. I learn by studying, you may learn differently, I don't.

Learning differently is fine. But being lazy is not. You haven't even tried to write any psuedocode. Here's the catch: programming and writing software are just fancy words for problem solving. Not all problems are the same. In programming, most problems are different. While they have similarities, there isn't "one solution to every problem." You need to learn how to do problem solving. That will take time and effort.



I don't have the personal time to invest in learning something complex

Then you don't have time to learn how to program. Programming is complex. It always has been and it always will be. If you don't have the time to learn how to do it, and you know you don't, you're wasting what little time you have.


im sure you were the same (you learned in a classroom).

I learned from the Internet and wonderful sites like GameDev.net. Not in a classroom, actually. In fact, I've learned very, very little about programming in any kind of formal or informal class.


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.

I'm going to pretend like I understand what that sentence is supposed to mean... You ever heard of the proverb "Give a man a fish, feed him for a day; teach a man to fish, feed him for a lifetime?"


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.

What we're trying to say is that if you can't get basic jumping down in your game, you won't get anywhere. You won't finish. You probably won't even really start. So rather than go through all the work of making a demo of how to jump, just so you can study the code and see "Ah, so that'show they made him jump," and then you realize you have no freaking clue what to do with that code now, and then you come back and say "Hai guyz, I need help making my character shoot, plz give me code." Then you come back again and say "Now I need help making my character swim, I need you to give me the code." Then you come back and say "Now I need you to give me code to make my character fly." You know what? By the time you get all the code samples you're asking for, we'll have made the dang game for you.

So I'm just going to try and tell you something:

That's not how it works.

You want code? Here:


double characterVelocityY;
double characterVelocityX;
double characterPosX;
double characterPosY;

int main()
{
while (true)
{
if (spacebar_pressed) characterVelocityY = 10;
if (left_key_pressed) characterVelocityX = -4;
if (right_key_pressed) characterVelocityX = 4;
if (characterVelocityY > 0) characterVelocityY -= 0.5;
if (characterPosY < 0) characterPosY = 0;
if (characterPosY < 0) characterVelocityY = 0;
characterPosX += characterVelocityX;
characterPosY += characterVelocityY;
print_out_to_console("Character position x: " + characterPositionX + " Character position y: " + characterPositionY);
}

}



If you aren't even going to make an honest effort to understand what I just wrote and translate it into whatever APIs/language/whatever you're using, then we've all been fooled and you're actually just an epic troll who fooled us all.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

This topic is closed to new replies.

Advertisement