Beginner C++ Lesson 8 Help

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
rhn94
Posts: 5
Joined: July 20th, 2012, 6:22 pm

Beginner C++ Lesson 8 Help

Post by rhn94 » July 20th, 2012, 6:28 pm

So i've been following and doing the *Poo collecting game* in the lesson and for some reason the poo doesn't disappear after the face eats it .. i tried it again with the same exact code in the video (Since i have some prior knowledge to C++ i have been doing some of my own code during the lessons) and it still doesn't work.

Could someone help me? Here's the code i tried to copy exactly from the video.
I'm pretty sure I've just made a stupid mistake. :oops:

Thank You :D


:ugeek:

Header File (Game.h)

Code: Select all

#pragma once

#include "D3DGraphics.h"
#include "Keyboard.h"

class Game
{
public:
	Game( HWND hWnd,const KeyboardServer& kServer );
	void Go();
private:
	void ComposeFrame();
	/********************************/
	/*  User Functions              */

	void DrawFace( int dx, int dy );
	void Drawpoo(int dx, int dy );

	/********************************/
private:
	D3DGraphics gfx;
	KeyboardClient kbd;
	/********************************/
	/*  User Variables              */
	
	int faceX;
	int faceY;
	
	int poo1X;
	int poo1Y;
	bool poo1IsEaten;

	int poo2X;
	int poo2Y;
	bool poo2IsEaten;

	int poo3X;
	int poo3Y;
	bool poo3IsEaten;

	/********************************/
};

Source File (Game.cpp)

Code: Select all

#include "Game.h"

Game::Game( HWND hWnd,const KeyboardServer& kServer )
:	gfx ( hWnd ),
	kbd( kServer ),
	faceX(390),
	faceY(290),
	poo1X(100),
	poo1Y(100),
	poo1IsEaten(false),
	poo2X(650),
	poo2Y(200),
	poo2IsEaten(false),
	poo3X(300),
	poo3Y(510),
	poo3IsEaten(false)
{}

void Game::Go()
{
	gfx.BeginFrame();
	ComposeFrame();
	gfx.EndFrame();
}
void Game::DrawFace(int dx,int dy )
{ ALL THE PIXEL CODE}
	
void Game::Drawpoo(int dx, int dy)
{ ALL THE PIXEL CODE}


void Game::ComposeFrame()
{
	int r = 255;
	int g = 255;
	int b = 255;
	int s = 3;

	if (kbd.SpaceIsPressed())
	{
		s = 1;
	}

	if (kbd.EnterIsPressed())
	{
		s = 8;
	}

	if (kbd.RightIsPressed())
	{
		faceX = faceX + s;
	}

	if (kbd.LeftIsPressed())
	{
		faceX = faceX - s;
	}

	if (kbd.UpIsPressed())
	{
		faceY = faceY - s;
	}

	if (kbd.DownIsPressed())
	{
		faceY = faceY + s;
	}

	if (kbd.SpaceIsPressed())
	{
		s = 1;
	}

	if (kbd.EnterIsPressed())
	{
		s = 8;
	}

	if ( faceX < 0){faceX=0;}
	if ( faceX +20 > 799){faceX=799 - 20;}
	if ( faceY < 0){faceY=0;}
	if ( faceY + 20 > 599){faceY=599 - 20;}

	if (!poo1IsEaten)
	{
		if( faceX + 20 > poo1X &&
			faceX < poo1X + 24 &&
			faceY + 20 > poo1Y &&
			faceY < poo1Y + 24 )
		{
			poo1IsEaten = true;
		}

		Drawpoo( poo1X,poo1Y);
	}


	if (!poo2IsEaten)
	{
		if( faceX + 20 > poo2X &&
			faceX < poo2X + 24 &&
			faceY + 20 > poo2Y &&
			faceY < poo2Y + 24 )
		{
			poo2IsEaten = true;
		}

		Drawpoo( poo2X,poo2Y);
	}


	if (!poo3IsEaten)
	{
		if( faceX + 20 > poo3X &&
			faceX < poo3X + 24 &&
			faceY + 20 > poo3Y &&
			faceY < poo3Y + 24 )
		{
			poo3IsEaten = true;
		}

		Drawpoo( poo3X,poo3Y);
	}

	DrawFace( faceX, faceY);
	Drawpoo(poo1X,poo1Y);
	Drawpoo(poo2X,poo2Y);
	Drawpoo(poo3X,poo3Y);
}
:ugeek:

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

Re: Beginner C++ Lesson 8 Help

Post by LuX » July 20th, 2012, 6:33 pm

Maybe you shouldn't redraw the poos at the bottom of the code? : -D
ʕ •ᴥ•ʔ

User avatar
codinitup
Posts: 112
Joined: June 27th, 2012, 7:43 am

Re: Beginner C++ Lesson 8 Help

Post by codinitup » July 20th, 2012, 6:58 pm

Maybe you should also check out the forum rules bro ;). A quick tip, if you have logic in the Compose Frame, then you should put it in its own function. For example, the keyboard pressed could easily be put into their own function. LuX is right as well, you are testing to see if the poo is eaten, and then it evaluates that to true if it is. When they go away the compiler instantly re-draws them to the screen because they are constantly being drawn in the Compose Frame function.

Good Luck :)
MOOOOOO

rhn94
Posts: 5
Joined: July 20th, 2012, 6:22 pm

Re: Beginner C++ Lesson 8 Help

Post by rhn94 » July 21st, 2012, 1:42 am

I derped so bad it ain't even funny. I just hit my head on the table and now i have a brain hemorrhage.

Thanks for your help guys and yes i should have read the rules first and zipped up the files.

Thanks anyways :D

Post Reply