I'm having trouble with the assignment of Part 5:Conditions
I managed to make the tank move to the right and to left, just like they wanted it to.
But now I will also have to make it move up and down, and when it goes down it needs to turn invisible.
This is the code for just right and left:
#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
}
Sprite theSprite( new Surface("assets/ctankbase.tga"), 16 );
int SpriteX = 0;
int SpriteY = 100;
bool Visible = true;
bool Direction = true;
void Game::Tick( float a_DT )
{
// render a single frame here
m_Screen->Clear( 0 );
if (Visible == true) theSprite.Draw( SpriteX, SpriteY, m_Screen );
if (Direction == true)
{
SpriteX += 1;
if (SpriteX > 500) Direction = false;
}
else
{
SpriteX -= 1;
if (SpriteX < 100) Direction = true;
}
}
And this is the code I made that should also make it move and down, it does.. but in a diagonal line and the movement keeps getting smaller and finally the tank goes out of the screen..
#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
}
Sprite theSprite( new Surface("assets/ctankbase.tga"), 16 );
int SpriteX = 0;
int SpriteY = 100;
bool Visible = true;
bool Direction = true;
void Game::Tick( float a_DT )
{
// render a single frame here
m_Screen->Clear( 0 );
if (Visible == true) theSprite.Draw( SpriteX, SpriteY, m_Screen );
if (Direction == true)
{
SpriteY += 1;
if (SpriteY > 450) Direction = false;
}
else
{
SpriteY -= 1;
if (SpriteY < 10) Direction = true;
}
if (Direction == true)
{
SpriteX += 1;
if (SpriteX > 500) Direction = false;
}
else
{
SpriteX -= 1;
if (SpriteX < 100) Direction = true;
}
}
Could someone please give a hint or tell me what I'm doing wrong?
Much appreciated !












