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
|
#include "SDL/SDL.h"
#include <vector>
class Entity
{
public:
SDL_Surface *image;
SDL_Rect loc;
bool operator!= (Entity otherent);
bool operator== (Entity otherent);
bool anim;
Entity()
{
SDL_Rect locx = { 0 , 0 , 0 , 0 };
image = NULL;
loc = locx;
anim = false;
}
~Entity()
{
}
void E_Set(SDL_Surface *img, SDL_Rect bbox, bool isanim)
{
image = img;
loc = bbox;
anim = isanim;
}
void live(){}
};
int main( int argc , char* args[] )
{
SDL_Init( SDL_INIT_EVERYTHING );
SDL_Surface *screen = NULL;
screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
std::vector<Entity> test;
SDL_Surface *one = NULL;
one = SDL_LoadBMP( "grass.bmp" );
SDL_Rect rect = {10,10};
Entity tmp;
tmp.E_Set( one , rect , false );
test.push_back( tmp );
SDL_BlitSurface( one , NULL , screen , &rect );
rect.x = 50;
SDL_BlitSurface( test[0].image , NULL , screen , &rect );
SDL_Flip( screen );
SDL_Delay( 3000 );
SDL_FreeSurface ( screen );
SDL_FreeSurface ( one );
//SDL_FreeSurface ( test[0].image ); <-- link to image one
SDL_Quit();
return 0;
}
|