2 #include <SDL/SDL_image.h>
10 const int SCREEN_WIDTH
= 640;
11 const int SCREEN_HEIGHT
= 480;
12 const int SCREEN_BPP
= 32;
15 SDL_Surface
*screen
= NULL
;
16 SDL_Surface
*actor
= NULL
;
17 SDL_Surface
*background
= NULL
;
25 int init(char *title
){
27 if( SDL_Init( SDL_INIT_EVERYTHING
) == -1)
30 screen
= SDL_SetVideoMode( SCREEN_WIDTH
, SCREEN_HEIGHT
, SCREEN_BPP
, SDL_SWSURFACE
);
37 SDL_WM_SetCaption(title
, NULL
);
43 SDL_Surface
*load_image( char *filename
){
45 SDL_Surface
* loadedImage
= NULL
;
48 SDL_Surface
* optimizedImage
= NULL
;
51 loadedImage
= IMG_Load( filename
);
56 optimizedImage = SDL_DisplayFormat( loadedImage );
59 SDL_FreeSurface( loadedImage );
64 Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0xFF, 0, 0xFF );
67 SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );
73 void move(Uint8
*keystates
, int *x
, int *y
){
77 if( keystates
[SDLK_UP
] )
79 if( keystates
[SDLK_DOWN
] )
81 if( keystates
[SDLK_LEFT
] )
83 if( keystates
[SDLK_RIGHT
] )
87 void is_out(int *x
, int *y
){
92 if(*x
+ 49 > SCREEN_WIDTH
)
93 *x
= SCREEN_WIDTH
- 49;
98 if(*y
+ 104 > SCREEN_HEIGHT
)
99 *y
= SCREEN_HEIGHT
- 104;
102 void apply_surface( int x
, int y
, SDL_Surface
* source
, SDL_Surface
* destination
){
111 SDL_BlitSurface( source
, NULL
, destination
, &offset
);
116 background
= load_image( "background.png" );
123 actor
= load_image( "actor.png" );
137 SDL_FreeSurface( actor
);
138 SDL_FreeSurface( background
);
142 if (init("MUAMUAMUAMAMAMA")){
143 printf("Error al Iniciar");
148 int x
= 100, y
= 100;
156 Uint8
*keystates
= SDL_GetKeyState( NULL
);
157 if( keystates
[ SDLK_ESCAPE
] )
161 while( SDL_PollEvent( &event
) ){
163 if( event
.type
== SDL_QUIT
){
169 move(keystates
, &x
, &y
);
172 apply_surface( 0, 0, background
, screen
);
173 apply_surface( x
, y
, actor
, screen
);