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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <iostream>
#include <string>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
SDL_Rect clip[18];
SDL_Event event;
bool directionL2R = true;
SDL_Surface *source1 = NULL;
SDL_Surface *source2 = NULL;
SDL_Surface *screen = NULL;
SDL_Surface*load_image(std::string filename)
{
SDL_Surface *loadedimage = NULL;
SDL_Surface *optimizedimage=NULL;
loadedimage = IMG_Load(filename.c_str());
if (loadedimage!=NULL)
{
optimizedimage = SDL_DisplayFormat(loadedimage);
SDL_FreeSurface(loadedimage);
if(optimizedimage!=NULL)
{
SDL_SetColorKey(optimizedimage,SDL_SRCCOLORKEY,SDL_MapRGB(optimizedimage->format,25,25,25));
}
}
return optimizedimage;
}
bool load_files ()
{
source1 = load_image("L2Rgameclips.jpg");
source2 = load_image("R2Lgameclips.jpg");
screen = load_image ("newZ.jpg");
if(source1||source2 == NULL)
{
return false;
}
return true;
}
void apply_surface (int x,int y, SDL_Surface *source, SDL_Surface *destination,SDL_Rect *clip = NULL)
{
SDL_Rect offset;
offset.x = y;
offset.y = y;
SDL_BlitSurface (source,clip,destination, &offset);
}
void cleanup()
{
SDL_FreeSurface(source1);
SDL_FreeSurface(source2);
SDL_QUIT;
}
bool init()
{
if(SDL_Init(SDL_INIT_EVERYTHING)==-1)
{
return false;
}
screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE);
if (screen==NULL)
{
return false;
}
SDL_WM_SetCaption("how far will I get with this??",NULL);
return true;
}
int main(int argc,char* args[])
{
bool quit = false;
if(init()==false)
{
return 1;
}
if (load_files()==false)
{
return 1;
}
//-------------------------------------------------------------------
clip[0].x = 0;
clip[0].y = 600;
clip[0].w = 240;
clip[0].h = 600;
//-------------------------------------------------------------------
apply_surface(200,200,source1,screen,&clip[0]);
SDL_Flip (screen);
SDL_Delay(1000);
while(quit == false)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
quit = true;
}
}
}
cleanup();
return 0;
}
|