Jump to content


Help needed in C++


2 replies to this topic

#1 Nickwel96

    New Member

  • Members
  • Pip
  • 4 posts

Posted 14 November 2012 - 08:23 PM

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 Reedbeta

    DevMaster Staff

  • Administrators
  • 5311 posts
  • LocationSanta Clara, CA

Posted 14 November 2012 - 09:14 PM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Nickwel96

    New Member

  • Members
  • Pip
  • 4 posts

Posted 15 November 2012 - 05:17 PM

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users