Need help with the game in Lesson 8.

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
WwortelHD
Posts: 34
Joined: January 6th, 2012, 7:01 pm
Location: Lochem
Contact:

Need help with the game in Lesson 8.

Post by WwortelHD » January 19th, 2012, 7:31 pm

Hey guys it's me again, :roll:

I've tried and tried, but I can't fix some stuff to get the game working. I had a problem at around 25 minutes in the video, but I managed to fix that after a hour or 2. Now, I'm stuck at some stuff, because I just did what Chili did and it just don't freaking works! :evil:
Here's my game.cpp:

#include "Game.h"

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


void Game::Go()
{
gfx.BeginFrame();
ComposeFrame();
gfx.EndFrame();
}

void Game::DrawFace( int x,int y )
void Game::DrawPoo( int x, int y )
void Game::DrawGameOver( int x,int y )


void Game::ComposeFrame()
{
int speed;
speed = 3;

// adjust speed

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

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

// move cursor

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

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

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

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

// clamp to window

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 && poo2IsEaten && poo3IsEaten ) )
{

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 );
}
}
else
{
DrawGameOver( 375,275 );
}
DrawFace( faceX,faceY );
}


game.h:

Code: Select all

/****************************************************************************************** 
 *	Chili DirectX Framework Version 11.12.17											  *	
 *	Game.h																				  *
 *	Copyright 2011 PlanetChili.net														  *
 *																						  *
 *	This file is part of The Chili DirectX Framework.									  *
 *																						  *
 *	The Chili DirectX Framework is free software: you can redistribute it and/or modify	  *
 *	it under the terms of the GNU General Public License as published by				  *
 *	the Free Software Foundation, either version 3 of the License, or					  *
 *	(at your option) any later version.													  *
 *																						  *
 *	The Chili DirectX Framework is distributed in the hope that it will be useful,		  *
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of						  *
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the						  *
 *	GNU General Public License for more details.										  *
 *																						  *
 *	You should have received a copy of the GNU General Public License					  *
 *	along with The Chili DirectX Framework.  If not, see <http://www.gnu.org/licenses/>.  *
 ******************************************************************************************/
#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 x,int y );
	void DrawPoo(int x,int y );
	void DrawGameOver(int x,int y );

	/********************************/
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;

	/********************************/
};
this is the error I get:
1>------ Build started: Project: Chili DirectX Framework, Configuration: Release Win32 ------
1>Build started 19-1-2012 20:40:51.
1>InitializeBuildStatus:
1> Touching "Release\Chili DirectX Framework.unsuccessfulbuild".
1>ClCompile:
1> Game.cpp
1>..\Assets\Game.cpp(23): error C2146: syntax error : missing ')' before identifier 'hWnd'
1>..\Assets\Game.cpp(23): error C2146: syntax error : missing ';' before identifier 'hWnd'
1>..\Assets\Game.cpp(23): error C2377: 'HWND' : redefinition; typedef cannot be overloaded with any other symbol
1> C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\windef.h(208) : see declaration of 'HWND'
1>..\Assets\Game.cpp(23): error C2512: 'Game' : no appropriate default constructor available
1>..\Assets\Game.cpp(23): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(23): error C2143: syntax error : missing ';' before '&'
1>..\Assets\Game.cpp(23): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(23): warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
1>..\Assets\Game.cpp(23): error C2059: syntax error : ')'
1>..\Assets\Game.cpp(23): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(23): error C2530: 'kServer' : references must be initialized
1>..\Assets\Game.cpp(24): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(26): error C2146: syntax error : missing ';' before identifier 'faceX'
1>..\Assets\Game.cpp(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(28): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(29): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(31): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(32): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(33): error C2374: 'poo1IsEaten' : redefinition; multiple initialization
1> ..\Assets\Game.cpp(30) : see declaration of 'poo1IsEaten'
1>..\Assets\Game.cpp(34): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(35): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(37): error C2448: 'poo1IsEaten' : function-style initializer appears to be a function definition
1>..\Assets\Game.cpp(2757): error C2065: 'poo2IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2757): error C2065: 'poo3IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2773): error C2065: 'poo2IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2780): error C2065: 'poo2IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2786): error C2065: 'poo3IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2793): error C2065: 'poo3IsEaten' : undeclared identifier
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.91
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


if you could only help a little bit to fix 1/60 errors I get, I would love to see what I did wrong.

Thanks :geek:

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

Re: Need help with the game in Lesson 8.

Post by chili » January 20th, 2012, 1:42 am

You wound me, sir. You wound me deeply.
WwortelHD wrote:I just did what Chili did and it just don't freaking works!
From a cursory inspection of your code, I can see that you have not done what I demonstrated in my video. You have multiple syntax errors in the Game constructor alone, and you appear to have rewritten portions that you had no reason to touch. Tsk, tsk. Consider yourself thoroughly chastened.

Here is what it should look like:

Game::Game( HWND hWnd,const KeyboardServer& kServer ); <-- delete this semicolon! do not want!
: gfx ( hWnd ),
kbd( kServer ),
faceX( 390 ),
faceY( 290 ),
poo1X( 100 ),
poo1Y( 100 ),
poo1IsEaten( false ),
poo2X( 650 ),
poo2Y( 200 ),
poo1IsEaten( false ),
poo3X( 300 ),
poo3Y( 510 ),
poo1IsEaten( false )
{}

I suppose you may have other errors too, but this is a start at least. Time to train those eyes wortel! :P
Chili

WwortelHD
Posts: 34
Joined: January 6th, 2012, 7:01 pm
Location: Lochem
Contact:

Re: Need help with the game in Lesson 8.

Post by WwortelHD » January 20th, 2012, 6:47 am

Ok thanks Chili! I fixed that stuff, but it still says some errors about illegal member initialization and error c2065.. :?

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

Re: Need help with the game in Lesson 8.

Post by chili » January 20th, 2012, 6:57 am

Too little info bro. :|
Chili

WwortelHD
Posts: 34
Joined: January 6th, 2012, 7:01 pm
Location: Lochem
Contact:

Re: Need help with the game in Lesson 8.

Post by WwortelHD » January 20th, 2012, 2:08 pm

oh sorry ;P

1>------ Build started: Project: Chili DirectX Framework, Configuration: Release Win32 ------
1>Build started 20-1-2012 15:06:11.
1>InitializeBuildStatus:
1> Touching "Release\Chili DirectX Framework.unsuccessfulbuild".
1>ClCompile:
1> Game.cpp
1>..\Assets\Game.cpp(37): error C2614: 'Game' : illegal member initialization: 'poo1IsEaten' is not a base or member
1>..\Assets\Game.cpp(37): error C2614: 'Game' : illegal member initialization: 'poo1IsEaten' is not a base or member
1>..\Assets\Game.cpp(37): error C2614: 'Game' : illegal member initialization: 'poo1IsEaten' is not a base or member
1>..\Assets\Game.cpp(2757): error C2065: 'poo1IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2757): error C2065: 'poo2IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2757): error C2065: 'poo3IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2760): error C2065: 'poo1IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2767): error C2065: 'poo1IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2773): error C2065: 'poo2IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2780): error C2065: 'poo2IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2786): error C2065: 'poo3IsEaten' : undeclared identifier
1>..\Assets\Game.cpp(2793): error C2065: 'poo3IsEaten' : undeclared identifier
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.33
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


that better :?:

Ooh, When you are doing a lesson, show us your full code sometimes in a video! that way we can see if we do it right, and not get any errors because I had a hard time pauzing on the right times for seeing your code :(

Thanks :DD

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

Re: Need help with the game in Lesson 8.

Post by chili » January 20th, 2012, 5:43 pm

You use different capitalization of your bool variables in your .h file than you do in your .cpp file. Also, you initialize poo1IsEaten 3 time in your Game constructor, but you don't initialize numbers 2 or 3.
Chili

WwortelHD
Posts: 34
Joined: January 6th, 2012, 7:01 pm
Location: Lochem
Contact:

Re: Need help with the game in Lesson 8.

Post by WwortelHD » January 20th, 2012, 6:08 pm

Thanks It's all working now :D Thanks Chili! To show some love I'll like all of your video's! (if I didn't do that 100 times already :mrgreen: )

Thread can be closed :D (when is next lesson comming out? :D)

Scruffy Nerfherder
Posts: 1
Joined: July 18th, 2012, 5:57 am

Re: Need help with the game in Lesson 8.

Post by Scruffy Nerfherder » July 18th, 2012, 5:59 am

I know i have messed up somewhere and just can not put my finger on it. this is the errors i get.

1>------ Build started: Project: Chili DirectX Framework, Configuration: Release Win32 ------
1> Game.cpp
1>..\Assets\Game.cpp(29): error C2059: syntax error : '{'
1> Windows.cpp
1>..\Assets\Windows.cpp(26): warning C4091: 'static ' : ignored on left of 'KeyboardServer' when no variable is declared
1>..\Assets\Windows.cpp(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Windows.cpp(39): error C2228: left of '.OnUpPressed' must have class/struct/union
1> type is 'int'
1>..\Assets\Windows.cpp(42): error C2228: left of '.OnDownPressed' must have class/struct/union
1> type is 'int'
1>..\Assets\Windows.cpp(45): error C2228: left of '.OnLeftPressed' must have class/struct/union
1> type is 'int'
1>..\Assets\Windows.cpp(48): error C2228: left of '.OnRightPressed' must have class/struct/union
1> type is 'int'
1>..\Assets\Windows.cpp(51): error C2228: left of '.OnSpacePressed' must have class/struct/union
1> type is 'int'
1>..\Assets\Windows.cpp(54): error C2228: left of '.OnEnterPressed' must have class/struct/union
1> type is 'int'
1>..\Assets\Windows.cpp(62): error C2228: left of '.OnUpReleased' must have class/struct/union
1> type is 'int'
1>..\Assets\Windows.cpp(65): error C2228: left of '.OnDownReleased' must have class/struct/union
1> type is 'int'
1>..\Assets\Windows.cpp(68): error C2228: left of '.OnLeftReleased' must have class/struct/union
1> type is 'int'
1>..\Assets\Windows.cpp(71): error C2228: left of '.OnRightReleased' must have class/struct/union
1> type is 'int'
1>..\Assets\Windows.cpp(74): error C2228: left of '.OnSpaceReleased' must have class/struct/union
1> type is 'int'
1>..\Assets\Windows.cpp(77): error C2228: left of '.OnEnterReleased' must have class/struct/union
1> type is 'int'
1>..\Assets\Windows.cpp(108): error C2664: 'Game::Game(HWND,const KeyboardServer &)' : cannot convert parameter 2 from 'int' to 'const KeyboardServer &'
1> Reason: cannot convert from 'int' to 'const KeyboardServer'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



any suggestions??

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

Re: Need help with the game in Lesson 8.

Post by chili » July 18th, 2012, 9:13 am

I have a suggestion: read the forum rules. ;)
Chili

Post Reply