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
|
#include <SDL/SDL.h>
#include "SDL/SDL_image.h"
#include <string>
using namespace std;
const int FPS=30;
const int FENSTER_HOEHE=640;
const int FENSTER_BREITE=480;
const int FENSTER_FARBTIEFE=32;
SDL_Surface* screen,*image,*optimizedImage,*background;
class object
{
public:
SDL_Rect body;
int objgroup;
int collisiongroup;
SDL_Rect make(int rx, int ry, int rw, int rh)
{
SDL_Rect body;
body.x=rx;
body.y=ry;
body.w=rw;
body.h=rh;
return body;
}
};
SDL_Surface *optimage(string filename);
int main(int argc, char** argv)
{
//initialisierung der elemente
SDL_Init(SDL_INIT_EVERYTHING);
screen=SDL_SetVideoMode(FENSTER_HOEHE,FENSTER_BREITE,FENSTER_FARBTIEFE,SDL_SWSURFACE);
SDL_WM_SetCaption("Test", NULL);
image=optimage("16sprite.png");
object obj;
obj.body=object::make(10,10,20,20);
Uint32 white=SDL_MapRGB(screen->format,0xff,0xff,0xff);
Uint32 start;
bool running=true;
while(running)
{
start=SDL_GetTicks();
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
running=false;
break;
}
}
SDL_BlitSurface(image,NULL,screen,NULL);
SDL_FillRect(screen,&obj.body,white);
SDL_Flip(screen);
if(1000/FPS>SDL_GetTicks()-start)
SDL_Delay(1000/FPS-(SDL_GetTicks()-start));
}
SDL_FreeSurface(image);
SDL_Quit();
return 0;
}
SDL_Surface *optimage(string filename)
{
SDL_Surface* loadedImage=NULL;
optimizedImage=NULL;
loadedImage=IMG_Load(filename.c_str());
if(loadedImage!=NULL )
{
optimizedImage=SDL_DisplayFormat(loadedImage);
SDL_FreeSurface(loadedImage);
}
return optimizedImage;
}
|