need help on my first game
need help on my first game
So I just finished lesson 14, and I've been attempting to make my own game for the past week or so. However, I've hit a bit of a wall. The game is a basic 2d fighting game, where you can play with two players, move left or right, and punch or block. My first problem is that there's a bug where, if you just hold down the punch button, the arm sticks straight out and the health goes straight down. I tried the keysPressedLastFrame attempt from lesson 9, and a few other modifications to it, but none worked! D: so if any one has any ideas on how to fix that, that'd be great. Thanks guys! The controls are as follows: To control the blue guy, A moves left, S moves right, W punches, and Q blocks. For the red girl, K moves left, L moves right, P punches, and O blocks. If one charactor wins, press R to restart.
P.S The graphics are all drawn with drawline or drawcircle functions, so don't diss :p
P.S The graphics are all drawn with drawline or drawcircle functions, so don't diss :p
- Attachments
-
- Fighter2000 - Copy.rar
- Fighter Game
- (46.53 KiB) Downloaded 199 times
Re: need help on my first game
Hey Iloganm!
I like the idea of the game, tho I see parts that you could've done differently. But I think you got some nice game idea going here and should improve on it. For more keys and possibly even single inputs etc, you will find in tutorial 6 of intermediate I think.
Maybe a more simple idea of a single input of a key would be: Have a boolean that is false, When a key is pressed this will become true and what ever the key does will only be done if the boolean is false. Then while the key is not pressed, this boolean will become false again. In short:
if ( kbd.WIsPressed() ) { if (!Pressed) { Pressed = true; /* Do Stuff */} } else { Pressed = false; }
I like the idea of the game, tho I see parts that you could've done differently. But I think you got some nice game idea going here and should improve on it. For more keys and possibly even single inputs etc, you will find in tutorial 6 of intermediate I think.
Maybe a more simple idea of a single input of a key would be: Have a boolean that is false, When a key is pressed this will become true and what ever the key does will only be done if the boolean is false. Then while the key is not pressed, this boolean will become false again. In short:
if ( kbd.WIsPressed() ) { if (!Pressed) { Pressed = true; /* Do Stuff */} } else { Pressed = false; }
ʕ •ᴥ•ʔ
Re: need help on my first game
Thanks man! I see what you are saying, but one problem. Wouldn't that still make it so if I hold Down W to punch, his arm will just stick straight out and the health will continue to go down?
Edit* I tried it, but the fighter just disappears, and no damage is done to the other player
Edit* I tried it, but the fighter just disappears, and no damage is done to the other player
Re: need help on my first game
keyPressedLastFrame = false;
if( !keyPressedLastFrame)
{
if( kbd.wIsPressed)
{ doSomething;
keyPressedLastFrame = true;
}
else
{
keyPressedLastFrame = false
}
}
else if (!kbd.wIsPressed() )
{
keyPressedLastFrame = false;
}
if( !keyPressedLastFrame)
{
if( kbd.wIsPressed)
{ doSomething;
keyPressedLastFrame = true;
}
else
{
keyPressedLastFrame = false
}
}
else if (!kbd.wIsPressed() )
{
keyPressedLastFrame = false;
}
What you call a bug...I call a new feature!
Re: need help on my first game
Code: Select all
//delclare the following in game.h bool keyPressedLastFrame
//game.cpp, in Game::Game set keyPressedLastFrame( false )
if( !keyPressedLastFrame )
{
if( kbd.LeftIsPressed() )
{
doSomeShit();
keyPressedLastFrame = true;
}
else
{
keyPressedLastFrame = false;
}
}
else if( !( kbd.LeftIsPressed() ) )
{
keyPressedLastFrame = false;
}
What you call a bug...I call a new feature!
Re: need help on my first game
That's close, but the animation will probably last for 1 frame then. You need to have a state variable or a counter or someting that keeps the arm extended for some time whenever the button is pressed.
Chili
Re: need help on my first game
yes that's what happened are counters hard to make?
- viruskiller
- Posts: 399
- Joined: June 14th, 2012, 5:07 pm
Re: need help on my first game
nope, just make a global variable,initialize it as 0;
then increase it by 1 each frame and then when it reaches a certain value(maybe the number of frames u want to count for) reset it to 0
so if for example u want something to happen every 5 frames or so u could reset counter at 5 and only do the action when it will be equal to 1 or any number between 0 and 5,if u want to use 0 or 5 you have to be careful where u reset the counter for it to work properly.
then increase it by 1 each frame and then when it reaches a certain value(maybe the number of frames u want to count for) reset it to 0
so if for example u want something to happen every 5 frames or so u could reset counter at 5 and only do the action when it will be equal to 1 or any number between 0 and 5,if u want to use 0 or 5 you have to be careful where u reset the counter for it to work properly.
Re: need help on my first game
wow that sounds really easy viruskiller! Thanks for the help everyone!
Re: need help on my first game
ok so i have this:
if(!kbd.QIsPressed())
{
if( !keyPressedLastFrame )
{
if( kbd.WIsPressed() )
{
while(mPunchCount <= 100)
{
DrawManPuch(manX,manY);
ManPunches = true;
ManBlocks = false;
keyPressedLastFrame = true;
mPunchCount += 1;
}
}
else
{
keyPressedLastFrame = false;
}
}
else if( !( kbd.WIsPressed() ) )
{
keyPressedLastFrame = false;
}
if(mPunchCount >= 100)
{
mPunchCount = 0;
}
}
but everytime I click W, the charactor dissapears and the health goes still if I just hold it down. Why?
if(!kbd.QIsPressed())
{
if( !keyPressedLastFrame )
{
if( kbd.WIsPressed() )
{
while(mPunchCount <= 100)
{
DrawManPuch(manX,manY);
ManPunches = true;
ManBlocks = false;
keyPressedLastFrame = true;
mPunchCount += 1;
}
}
else
{
keyPressedLastFrame = false;
}
}
else if( !( kbd.WIsPressed() ) )
{
keyPressedLastFrame = false;
}
if(mPunchCount >= 100)
{
mPunchCount = 0;
}
}
but everytime I click W, the charactor dissapears and the health goes still if I just hold it down. Why?