1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <SDL.h>
SDL_Surface *screen = NULL;
SDL_Surface *background = NULL;
SDL_Surface *sprite = NULL;
void Apply_Surface(int x, int y, SDL_Surface * source, SDL_Surface * destination)
{
SDL_Rect rect;
rect.x = x;
rect.y = y;
SDL_BlitSurface(source, NULL, destination, &rect);
}
void Draw_Sprite (int srcx, int srcy, int dstx, int dsty, int width, int height, SDL_Surface *source, SDL_Surface *destination)
{
/*==================================================================================*/
//This is where I put the tut creators transparancy function
SDL_SetColorKey(source, SDL_SRCCOLORKEY, SDL_MapRGB(source->format, 255, 0, 255));
SDL_Rect src;
src.x = srcx;
src.y = srcy;
src.w = width;
src.h = height;
SDL_Rect dst;
dst.x = dstx;
dst.y = dsty;
dst.w = width;
dst.h = height;
}
int main ( int argc, char* argv[] )
{
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(600, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("YouTube Tut 01", NULL);
background = SDL_LoadBMP("grid.bmp");
sprite = SDL_LoadBMP("ship.bmp");
/*=====================================================================================*/
//This is where the tut creator, originally, placed the transparency function.
//SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, SDL_MapRGB(sprite->format, 255, 0, 255));
bool running = true;
while(running)
{
SDL_Event event;
if(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
running = false;
}
}
Apply_Surface(0,0, background, screen);
Apply_Surface(240, 240, sprite, screen);
SDL_Flip(screen);
}
SDL_Quit();
return 0;
}
|