Lesson 5 help.

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
sandbiter
Posts: 5
Joined: July 19th, 2012, 7:05 pm

Lesson 5 help.

Post by sandbiter » July 19th, 2012, 7:15 pm

Hey, I just started watching the tutorials today and I like them very well. But now I'm at the 5th tutorial and I have a problem. After I put the int x; and int y; in de game.h file and go back to the game.cpp and delete the int x; and int y;. Then I build the solution, its fine... same as in the tutorial then I start debugging and I just can 'play' with it but the crosshair is on the right, almost off my screen. Then i close that, start debugging again and i get an error, but not that the value's of x and y are wrong but 'this' is red.. Don't know what to do now. Can someone help me?
Thanks in advance.
Sand.

TheEliteMaker
Posts: 8
Joined: July 14th, 2012, 8:54 am
Location: Leeds, UK
Contact:

Re: Lesson 5 help.

Post by TheEliteMaker » July 19th, 2012, 8:31 pm

Hi Sand

Can you upload your code please?

Ty :)

sandbiter
Posts: 5
Joined: July 19th, 2012, 7:05 pm

Re: Lesson 5 help.

Post by sandbiter » July 19th, 2012, 8:42 pm

game.cpp:

Code: Select all

#include "Game.h"

Game::Game( HWND hWnd,const KeyboardServer& kServer )
:	gfx( hWnd ),
	kbd( kServer )
	x( 400 ),
	y( 300 )
{}

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

void Game::ComposeFrame()
{
	int gb;
	gb = 255;

	if( kbd.LeftIsPressed() )
	{
		x = x - 1;
	}

	if( kbd.RightIsPressed() )
	{
		x = x + 1;
	}

	if( kbd.UpIsPressed() )
	{
		y = y - 1;
	}

	if( kbd.DownIsPressed() )
	{
		y = y + 1;
	}

	if( kbd.SpaceIsPressed() )
	{
		gb = 0;
	}

	gfx.PutPixel(	    x,	   y,255,gb,gb );
	gfx.PutPixel( -5 +  x,	   y,255,gb,gb );
	gfx.PutPixel( -4 +  x,	   y,255,gb,gb );
	gfx.PutPixel( -3 +  x,	   y,255,gb,gb );
	gfx.PutPixel(  3 +  x,	   y,255,gb,gb );
	gfx.PutPixel(  4 +  x,	   y,255,gb,gb );
	gfx.PutPixel(  5 +  x,	   y,255,gb,gb );
	gfx.PutPixel(       x,-5 + y,255,gb,gb );
	gfx.PutPixel(       x,-4 + y,255,gb,gb );
	gfx.PutPixel(       x,-3 + y,255,gb,gb );
	gfx.PutPixel(       x, 3 + y,255,gb,gb );
	gfx.PutPixel(       x, 4 + y,255,gb,gb );
	gfx.PutPixel(       x, 5 + y,255,gb,gb );
}
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              */

	// TODO: User functions go here

	/********************************/
private:
	D3DGraphics gfx;
	KeyboardClient kbd;
	/********************************/
	/*  User Variables              */
	
	int x;
	int y;

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

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

Re: Lesson 5 help.

Post by LuX » July 19th, 2012, 9:03 pm

At a quick glance, I see you messed up a comma at your class initialization. When you initialize variables there, each has to be separated with a comma, except the last one.

(look at your Game::Game section again)

Might be something else too. It helps uudles if you upload the whole project package.
ʕ •ᴥ•ʔ

sandbiter
Posts: 5
Joined: July 19th, 2012, 7:05 pm

Re: Lesson 5 help.

Post by sandbiter » July 19th, 2012, 9:43 pm

Thanks for the reply's guys!
LuX I added a comma there where I didn't had one, and chili had, and I still get an error, but thanks!

Hm I can't add the files.. it says its too big. And mediafire laggs like hell, I'm gonna upload a link when I got one! ;)

Edit--
Ok, here's the link!
http://www.2shared.com/file/Em4PP4kk/Cg ... orial.html

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

Re: Lesson 5 help.

Post by chili » July 20th, 2012, 3:19 am

Broseph, read the forum rules and then try again. You need to clean your solution.
Chili

sandbiter
Posts: 5
Joined: July 19th, 2012, 7:05 pm

Re: Lesson 5 help.

Post by sandbiter » July 20th, 2012, 10:05 am

Oh, sorry for that. I feel stupid now :oops:
Attachments
C++lesson5problem.rar
(32.11 KiB) Downloaded 151 times

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

Re: Lesson 5 help.

Post by LuX » July 20th, 2012, 12:41 pm

So, um... What was the problem again?
There's nothing wrong in your code.

Just remember that if you don't initialize your variables, they will get a random number. Second thing to remember is that when you try to draw out of the screen, it will cause an error, because you are trying to access memory that doesn't exist.

So combining a random number and a program that doesn't check out-of-screen pixels is never a good thing. But this is a matter for later. Right now the code looks good to go. That is, unless I completely missed what the problem was...
ʕ •ᴥ•ʔ

sandbiter
Posts: 5
Joined: July 19th, 2012, 7:05 pm

Re: Lesson 5 help.

Post by sandbiter » July 20th, 2012, 1:07 pm

This is the strangest thing I've ever had on pc's. Now it works good, probarly I made a type misstake that I saw and that I changed it and didn't test it anymore after I made the topic. For now it works good again. Thanks for your help.

Sorry for this 'unless' topic. :oops:

Post Reply