Hi all
I am trying my hand at a simple little lunar lander style game. I have
the background bitmap and spaceship bitmapl loaded and I am trying to
get the ship to change postions by setting the dst.x and dst.y rect
members to a temp position, say 582 and 0.
When I make the changes to the code and execute it, the ship still
appears in the upper right of the screen. I have tried the
SDL_UpdateRect function, but have read that this is not needed when
using double buffering?
Here is my code snippet.
// Lunar Rescue Version 1.0
// Copyright © 2004
// Donald Cathcart
#include <sdl.h>
#include <stdlib.h>
#include <stdio.h>
bool Running;
SDL_Surface *screen,*background,playership;
SDL_Rect src, dst;
SDL_Event event;
int SetUp();
int GameLoop();
int main( int argc, char argv[] )
{
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
//exit function
atexit ( SDL_Quit );
//create a window
screen = SDL_SetVideoMode (
1024,768,32,SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_FULLSCREEN);
if (screen == NULL)
{
printf(“Unable to set video mode: %s\n”, SDL_GetError());
return 1;
}
SetUp();
//Poll Event Loop
for(;;)
{
if(SDL_PollEvent(&event)!=0)
{
printf("inside event poll \n");
switch(event.type)
{
case SDL_KEYDOWN:
if(event.key.keysym.sym==SDLK_ESCAPE)
{
printf("escape pressed \n");
return 0;
}
break;
case SDL_QUIT:
printf("Quitting");
exit(0);
}
}
GameLoop();
}
return 0;
}
int SetUp()
{
// Load player bmp
playership=SDL_LoadBMP(“player.bmp”);
src.x=0;
src.y=0;
src.h=playership->h;
src.w=playership->w;
dst.x=512;
dst.y=0;
dst.h=playership->h;
dst.w=playership->w;
// Load background bmp
background=SDL_LoadBMP(“background.bmp”);
src.x=0;
src.y=0;
src.h=background->h;
src.w=background->w;
dst.x=0;
dst.y=0;
dst.h=background->h;
dst.w=background->w;
return 0;
}
int GameLoop()
{
SDL_BlitSurface(background,&src,screen,&dst);
SDL_BlitSurface(playership,&src,screen,&dst);
SDL_Flip(screen);
//SDL_UpdateRect(screen,0,0,0,0);
return 0;
}
Thanks