Sign in to follow this  
Amnesty2

2D movement trouble

Recommended Posts

Amnesty2    203
Hello, im working a game. I've been programming for a long time but this is the first time doing graphics programming.
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
[code]
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

}

[size="3"][font="Calibri"]}[/font][/size]

[/code]

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.
[code]
[font="Calibri"][size="3"] [/size][/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() );

}





}



[/code]


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!

Share this post


Link to post
Share on other sites
Try playing with the x movement variables, to see if you can get a more fluid movement. i.e. try making it move a shorter distance per frame.

If this movement becomes too slow, you could always increase the frame rate, which is just a tweak to a const int if you are using Lazy Foo's refresh method.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this