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.
Thank You
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);
}