More stupid tests
[hammerdown.git] / muamua / main.c
blob0df05bb029e0744c8b6c1443919d0812eba6d51d
1 #include <SDL/SDL.h>
2 #include <SDL/SDL_image.h>
3 #include <stdio.h>
4 #include <string.h>
6 #define true 1;
7 #define false 0;
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;
20 SDL_Event event;
23 int quit = true;
25 int init(char *title){
27 if( SDL_Init( SDL_INIT_EVERYTHING ) == -1)
28 return true;
30 screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
33 if(!screen)
34 return true;
37 SDL_WM_SetCaption(title, NULL);
40 return false;
43 SDL_Surface *load_image( char *filename ){
45 SDL_Surface* loadedImage = NULL;
48 SDL_Surface* optimizedImage = NULL;
51 loadedImage = IMG_Load( filename );
54 /* if( loadedImage ){
56 optimizedImage = SDL_DisplayFormat( loadedImage );
59 SDL_FreeSurface( loadedImage );
62 if( optimizedImage ){
64 Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0xFF, 0, 0xFF );
67 SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );
69 }*/
71 return loadedImage;
73 void move(Uint8 *keystates, int *x, int *y){
75 int speed = 2;
77 if( keystates[SDLK_UP] )
78 *y -= speed;
79 if( keystates[SDLK_DOWN] )
80 *y += speed;
81 if( keystates[SDLK_LEFT] )
82 *x -= speed;
83 if( keystates[SDLK_RIGHT] )
84 *x += speed;
87 void is_out(int *x, int *y){
89 if(*x < 0)
90 *x = 0;
92 if(*x + 49 > SCREEN_WIDTH)
93 *x = SCREEN_WIDTH - 49;
95 if(*y < 0)
96 *y = 0;
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 ){
104 SDL_Rect offset;
107 offset.x = x;
108 offset.y = y;
111 SDL_BlitSurface( source, NULL, destination, &offset );
114 int load_files(){
116 background = load_image( "background.png" );
119 if(!background)
120 return true;
123 actor = load_image( "actor.png" );
126 if(!actor)
127 return true;
129 return false;
132 void clean_up(){
134 SDL_Quit();
137 SDL_FreeSurface( actor );
138 SDL_FreeSurface( background );
141 int main(){
142 if (init("MUAMUAMUAMAMAMA")){
143 printf("Error al Iniciar");
144 return 1;
148 int x = 100, y = 100;
150 if(load_files())
151 return 1;
154 while(quit){
156 Uint8 *keystates = SDL_GetKeyState( NULL );
157 if( keystates[ SDLK_ESCAPE ] )
158 break;
161 while( SDL_PollEvent( &event ) ){
163 if( event.type == SDL_QUIT ){
165 quit = false;
169 move(keystates, &x, &y);
171 is_out(&x, &y);
172 apply_surface( 0, 0, background, screen );
173 apply_surface( x, y, actor, screen );
174 SDL_Flip( screen );
176 clean_up();
177 return 0;