Need help with a small code

Hi, i started to dev a small 2D game but i have a little problem.
I display a bmp and move it with my keyboard. Next i’ve try to use the mouse instead of the keyboard and it work a half.
I want to say that when i push my mouse’s button my bmp gose directly to the position i just clic
without doing the traject. It will be easier if you look at the code------------------------------------------------------------------------------------------------------------------------------------------------------------------

void GetMousePosition()
{
SDL_PumpEvents();

SDL_GetMouseState(&iMouseX, &iMouseY);

return;

}

// Quand la souris bouge on met la position du curseur a jour via GetMousePosition(); puis on rafraichi les
// coordonn?es du curseur
case SDL_MOUSEMOTION:
GetMousePosition();
curseur_x = iMouseX;
curseur_y = iMouseY;
break;

// Quand un bouton de la souris est enfonc? on met a jour la position du perso
case SDL_MOUSEBUTTONDOWN:
rond_x = iMouseX;
rond_y = iMouseY;
break;


rond_x and rond_y are the current position for my BMP and iMouseX and iMouseY are the “futur” position.
I would like to “animate” the traject of my BMP.
If try many thing but i don’t know how to do.

Please help me if you have an idea.

Thomas LAURO.

This is more an algorithmic problem than a SDL problem.
You must write your own routine that will “animate” your bmp
from the first position to the second position.On Thu, Feb 12, 2004 at 12:12:36AM +0100, tocx wrote:

Hi, i started to dev a small 2D game but i have a little problem.
I display a bmp and move it with my keyboard. Next i’ve try to use the mouse instead of the keyboard and it work a half.
I want to say that when i push my mouse’s button my bmp gose directly to the position i just clic
without doing the traject. It will be easier if you look at the code


void GetMousePosition()
{
SDL_PumpEvents();

SDL_GetMouseState(&iMouseX, &iMouseY);

return;

}

// Quand la souris bouge on met la position du curseur a jour via GetMousePosition(); puis on rafraichi les
// coordonn?es du curseur
case SDL_MOUSEMOTION:
GetMousePosition();
curseur_x = iMouseX;
curseur_y = iMouseY;
break;

// Quand un bouton de la souris est enfonc? on met a jour la position du perso
case SDL_MOUSEBUTTONDOWN:
rond_x = iMouseX;
rond_y = iMouseY;
break;


rond_x and rond_y are the current position for my BMP and iMouseX and iMouseY are the “futur” position.
I would like to “animate” the traject of my BMP.
If try many thing but i don’t know how to do.

Please help me if you have an idea.


saf at http://TrashMail.net/
No more spam, free disposable email addresses.

you could calculate the vector from
rondx/y tro imousex/y and scale it to a small amount.
then every frame add the vector to rondx/y

tocx wrote:> Hi, i started to dev a small 2D game but i have a little problem.

I display a bmp and move it with my keyboard. Next i’ve try to use the
mouse instead of the keyboard and it work a half.
I want to say that when i push my mouse’s button my bmp gose directly
to the position i just clic
without doing the traject. It will be easier if you look at the code


void GetMousePosition()
{
SDL_PumpEvents();

SDL_GetMouseState(&iMouseX, &iMouseY);

return;

}

// Quand la souris bouge on met la position du curseur a jour via
GetMousePosition(); puis on rafraichi les
// coordonn?es du curseur
case SDL_MOUSEMOTION:
GetMousePosition();
curseur_x = iMouseX;
curseur_y = iMouseY;
break;

// Quand un bouton de la souris est enfonc? on met a jour la position
du perso
case SDL_MOUSEBUTTONDOWN:
rond_x = iMouseX;
rond_y = iMouseY;
break;


rond_x and rond_y are the current position for my BMP and iMouseX and
iMouseY are the “futur” position.
I would like to “animate” the traject of my BMP.
If try many thing but i don’t know how to do.

Please help me if you have an idea.

Thomas LAURO.