Lesson 5 help.
Lesson 5 help.
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.
Thanks in advance.
Sand.
-
- Posts: 8
- Joined: July 14th, 2012, 8:54 am
- Location: Leeds, UK
- Contact:
Re: Lesson 5 help.
Hi Sand
Can you upload your code please?
Ty
Can you upload your code please?
Ty
Re: Lesson 5 help.
game.cpp:
Game.h:
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 );
}
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;
/********************************/
};
Re: Lesson 5 help.
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.
(look at your Game::Game section again)
Might be something else too. It helps uudles if you upload the whole project package.
ʕ •ᴥ•ʔ
Re: Lesson 5 help.
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
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
Re: Lesson 5 help.
Broseph, read the forum rules and then try again. You need to clean your solution.
Chili
Re: Lesson 5 help.
Oh, sorry for that. I feel stupid now
- Attachments
-
- C++lesson5problem.rar
- (32.11 KiB) Downloaded 151 times
Re: Lesson 5 help.
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...
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...
ʕ •ᴥ•ʔ
Re: Lesson 5 help.
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.
Sorry for this 'unless' topic.