Ok, so I've been following a tutorial about floats, and making a sprite move at a speed lower than 1 pixel per frame. Pretty easy. Now, I get the following assignment:
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.
How would I make this gravity thing? I only learned how to add to the x and y... Simply adding to the y value every frame doesn't work well, of course, and isn't really gravity. I don't really get what I'm expected to do here.
To get an idea of the short tutorial, here's the link. It's easy. http://www.devmaster.net/articles/intro-to-c++-with-game-dev/part6.php
Here's my bad code for making the tank move in four directions and making it invisible when going down. I added floats because of the tutorial.
Sprite theSprite( new Surface("assets/ctankbase.tga"), 16 );
float SpriteX = 50;
float SpriteY = 0; //the sprite starts at the top of the screen (2D coords system)
float screenBottom = 400; //I'm assuming your screen is 200 pixels high, change to your size
float speedY = 0.01; //the initial speed of the sprite
float accelY = 0.01; //the change in speed with each tick
bool Bottom = false;
void Game::Tick( float a_DT )
{
m_Screen->Clear( 0 );
theSprite.Draw(SpriteX, SpriteY, m_Screen ); // Draws sprite
if(SpriteY >= screenBottom) //when we hit bottom we change the direction of speed and slow it
{
speedY = -speedY/2;
Bottom = true;
}
if(Bottom == false)
{
SpriteY += speedY;
}
speedY += accelY;
}
So how would I make this tank bounce around the screen with 'gravity', in less retarded code? Thanks. Sorry if this is a stupid question, but I'm not seeing it.