need help on my first game

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
lloganm
Posts: 87
Joined: August 10th, 2012, 11:26 pm

need help on my first game

Post by lloganm » October 9th, 2012, 2:28 am

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
Attachments
Fighter2000 - Copy.rar
Fighter Game
(46.53 KiB) Downloaded 199 times

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: need help on my first game

Post by LuX » October 9th, 2012, 9:39 am

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; }
ʕ •ᴥ•ʔ

lloganm
Posts: 87
Joined: August 10th, 2012, 11:26 pm

Re: need help on my first game

Post by lloganm » October 9th, 2012, 8:49 pm

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

User avatar
XxWalKaxX
Posts: 244
Joined: June 11th, 2012, 7:15 pm

Re: need help on my first game

Post by XxWalKaxX » October 9th, 2012, 9:37 pm

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!

User avatar
XxWalKaxX
Posts: 244
Joined: June 11th, 2012, 7:15 pm

Re: need help on my first game

Post by XxWalKaxX » October 10th, 2012, 4:30 am

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;
	}
Sorry my last was sloppy, I was running late for work. This should pretty much do it for you.
What you call a bug...I call a new feature!

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: need help on my first game

Post by chili » October 10th, 2012, 12:56 pm

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

lloganm
Posts: 87
Joined: August 10th, 2012, 11:26 pm

Re: need help on my first game

Post by lloganm » October 10th, 2012, 1:16 pm

yes that's what happened :( are counters hard to make?

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: need help on my first game

Post by viruskiller » October 10th, 2012, 7:24 pm

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.

lloganm
Posts: 87
Joined: August 10th, 2012, 11:26 pm

Re: need help on my first game

Post by lloganm » October 11th, 2012, 12:17 am

wow that sounds really easy viruskiller! Thanks for the help everyone! :D

lloganm
Posts: 87
Joined: August 10th, 2012, 11:26 pm

Re: need help on my first game

Post by lloganm » October 12th, 2012, 10:34 pm

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? :(

Post Reply