Help needed in C++

F42c9d64cb71fca115ce0e1da589c6ab
0
Nickwel96 101 Nov 14, 2012 at 20:23

I’m currently doing a C++ tutorial on the site.
But im kinda stuck on this part of the tutorial: http://devmaster.net…art-3-variables

I’ve done everything it says, but at the bottom you see the assignments. There i’m stuck at getting fat I to move.
The code I currently have is:

#include “string.h”
#include “surface.h”
#include “stdlib.h”
#include “template.h”
#include “game.h”

using namespace Tmpl8;

void Game::Init()
{
// put your initialization code here; will be executed once
}
int x = 100;
int y = 0;
void Game::Tick( float a_DT )
{
// render a single frame here
m_Screen->Clear( 80 );
DrawFatI( 100 + x , 0 + y);
x = x + 1;
}
void Game::DrawI( int x, int y )
{
// render a single frame here
m_Screen->Line( 100 + x, 50 + y, 200 + x, 50 + y, 0xffffff );
m_Screen->Line( 150 + x, 50 + y, 150 + x, 300 + y, 0xffffff );
m_Screen->Line( 100 + x, 300 + y, 200 + x, 300 + y, 0xffffff );
}
void Game::DrawFatI( int x, int y )
{
DrawI( 0, 0 );
DrawI( 1, 0 );
DrawI( 0, 1 );
DrawI( 1, 1 );
x++;
}

__________________________________________________________________
Also I’ve made a - void DrawFatI(int x, int y); - in game.h
Can someone tell me what i’m doind wrong here?
Already much thanks for your time!

2 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Nov 14, 2012 at 21:14

It looks like you’re trying to pass the x and y values to draw at into DrawFatI() and from there into DrawI(). Trouble is, inside DrawFatI() you’re not using the passed-in x and y at all. You’re always passing 0 or 1 when you call DrawI(). Probably what you really want is to add 0 or 1 to x or y in the four calls to DrawI().

Remember that whenever you write a function that accepts (int x, int y) as parameters, the x and y inside that function are whatever the caller passed in - not the global x and y.

F42c9d64cb71fca115ce0e1da589c6ab
0
Nickwel96 101 Nov 15, 2012 at 17:17

And thank you, indeed i had to made
DrawI( 0, 0 );
DrawI( 1, 0 );
DrawI( 0, 1 );
DrawI( 1, 1 );
into
DrawI( 0 + x, 0 );
DrawI( 1 + x, 0 );
DrawI( 0 + x, 1 );
DrawI( 1 + x, 1 );

I’m new to the C++, so sometimes I don’t see things like this.
thanks!