Original Post
Hi! I'm new at this forum and i'm quite new to game programming to. I'm currently making a 2d two player shooting game and so far everything has gone great. I have builded the whole game engine by my self and it is based on SDL. But so far i have only been testing with one character on the screen and i have already run in to some input problems. I'm only using the keystates func for input and it sems to me that this method have some limitations. This is the basic input code: As you can see, the code is not clean at all and you all might laugh at this, but this is my first time and i have figured out everything by my own. I hope that you can make some sence out of it :S The problem is that when i'm holding down the shooting button (with by the way is SDLK_c), moving right and try to jump, the character doesn't jump. But when im shooting, moving left and try to jump, it works... What is wrong? I think this is wery confusing! Another problem: When i'm gonna implement the other player, with way is the best way of getting the character class to use other keys? I meen how to a change "keystates[SDLK_RIGHT]" to "keystates[SDLK_d]" in the best and moast effective way? Edit: a simple question, is the keystates func limited to a sertant number of keypresses simultaneously? If so, how meny and what other option to a got to make this two player game work?
//Makes the player release the jump button before jumping again
if(!jumpBegin && !keystates[SDLK_SPACE])
jumpBegin = true;
//makes the first jump
if(keystates[SDLK_SPACE] && (cords.yPos == (groundLevel - spriteClips[currentClip].h)) && (jumpState == 0) && jumpBegin){
cords.yVel -= (20 -weight);
jumpState = 1;
jumpBegin = false;
}
//pulls the char down if jump is not pressed down
if(((!keystates[SDLK_SPACE]) && (jumpState == 1)) && cords.yVel < 0){
cords.yVel += 2;
}
//pulls the char up if jump i pressed
else if(((keystates[SDLK_SPACE]) && (jumpState == 1)) && (cords.yVel < 0) && timeSpace(4)){
cords.yVel -= 1;
}
//makes the second jump
else if((jumpState == 1 && keystates[SDLK_SPACE]) && jumpBegin){
cords.yVel = ((-17) + weight);
jumpState = 2;
}
//pulls the char down when down is pressed
if(keystates[SDLK_DOWN] && cords.yPos != (groundLevel - spriteClips[currentClip].h))
cords.yVel += 3;
//Makes the char go left of right depending on it's pos
if(keystates[SDLK_LEFT] && cords.yPos == (groundLevel - spriteClips[currentClip].h)){
charPointRight = false;
if(cords.xVel > -walkingSpeed)
cords.xVel -= acceleration;
}
if(keystates[SDLK_RIGHT] && cords.yPos == (groundLevel - spriteClips[currentClip].h)){
charPointRight = true;
if(cords.xVel < walkingSpeed)
cords.xVel += acceleration;
}
if(keystates[SDLK_LEFT] && cords.yPos != (groundLevel - spriteClips[currentClip].h)){
charPointRight = false;
if(cords.xVel > -walkingSpeed)
cords.xVel -= acceleration;
}
if(keystates[SDLK_RIGHT] && cords.yPos != (groundLevel - spriteClips[currentClip].h)){
charPointRight = true;
if(cords.xVel < walkingSpeed)
cords.xVel += acceleration;
}
//end of sida movements