Jump to content


introduction to c++ with game development: part 6


  • You cannot reply to this topic
No replies to this topic

#1 Wouter-k-9

    New Member

  • Members
  • Pip
  • 3 posts

Posted 11 May 2013 - 08:14 PM

hello,

I am following the introduction to c++ with game development tutorial and I have problems with the assignment. The first part of the assignment I understand, but the second part I don't understand. you have to

Quote

Add a gravity influence to the calculation of the new tank's position, to make it come down automatically instead of bouncing against the top every time.
This is what I have so far.
// Template, major revision 3
// IGAD/NHTV - Jacco Bikker - 2006-2009
#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 );
float SpriteX = 0;
float SpriteY = 0;
bool Visible = true;
bool DirectionX = true;
bool DirectionY = 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 );
// alter our coords
if (DirectionX == true)
{ // he is moving right so add to his x
  SpriteX += 0.5;
  if (SpriteX > 600) DirectionX = false;
}

else
{ // he is moving left so sub tract from his x
  SpriteX -= 0.5;
  if (SpriteX < 0) DirectionX = true;
}

if (DirectionY == true)
{ // he is going down, so he is invisible and sub tract from his y
  SpriteY += 0.5;
  if (SpriteY > 440) DirectionY = false;
}

else
{ // he is going up, so it is visible and add to his y
  SpriteY -= 0.9;
  if (SpriteY < 0) DirectionY = true;
}
}
I hope someone can help me.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users