Im having trouble making the movement of my space invaders look good.
The invaders move downward pretty nicely. But adding any movement along the x-axis is really choppy and poor. The invader will move straight down for 20 pixels smoothly and then just jump right or left; when it should be just a smooth slope.
this is the invaders update function.. It is also responsible for drawing the invader
void invader::update(Timer& time)
{
if (_time == 0)
_time = time.get_ticks();
if(is_alive)
{
_y = _y + ((time.get_ticks() - _time) * .10);
_x = _x + ((time.get_ticks() - _time) * .05);
_time = time.get_ticks();
// Apply texture
}
[font="Calibri"]}[/font]
This is my game loop.. Its very small as i've dumbed it down .. Only one invader and nothing else.. It still has the same trouble.
[font="Calibri"] [/font]
//While the user hasn't quit
while( quit == false )
{
//While there's an event to handle
while( SDL_PollEvent( &event ) )
{
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
//Increment the frame counter
frame++;
//Apply the background to the screen
apply_surface( 0, 0, background, screen );
invader_guy->update(fps);
//Update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
//If we want to cap the frame rate
if( ( cap == true ) && ( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) )
{
//Sleep the remaining frame time
SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
}
}
The timer class is lazyfoos it just makes SDL_GetTicks more useful by giving the elapsed ticks not the total.
It uses
Any ideas, thoughts or demo on proper 2D movements with velocitys and timers would be much much appreciated!