Trying to set it up so an image rotate based on a key command with
SDL_gfx. I have the bitmap image on a surface and rotate it based on the
left or right key. Should I be using SDL_Rect with the rotated image? How
should I have it set up to draw this rotated image within the window with
sdl_gfx?
-Jamie
code:
#include <SDL/SDL.h>
#include <SDL/SDL_rotozoom.h>
#include
SDL_Surface *turret;
int InitImages()
{
turret = SDL_LoadBMP(“images/turret.bmp”);
SDL_SetColorKey(turret, SDL_SRCCOLORKEY, SDL_MapRGB(turret->format, 255,
255, 255));
return 0;
}
void DrawIMG(SDL_Surface *img, int x, int y)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(img, NULL, screen, &dest);
}
void DrawScene()
{
DrawIMG(turret, 205, 339);
SDL_Flip(screen);
}
int main(int argc, char argv[])
{
Uint8 keys;
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0 )
{
printf(“Unable to init SDL: %s\n”, SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen=SDL_SetVideoMode(630,394,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
InitImages();
int done=0;
while(done == 0)
{
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { done = 1; }
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
}
}
keys = SDL_GetKeyState(NULL);
if ( keys[SDLK_LEFT] )
{
turret = rotozoomSurface(turret, 5.0, 0.0, 0);
}
if ( keys[SDLK_RIGHT] )
{
turret = rotozoomSurface(turret, 0.0, 0.0, 0);
}
DrawScene();
return 0;
}