#include <allegro.h>
#include <iostream>
#include <stdlib.h>
#include <time.h>
typedef struct bitmap
{
int h,w;
};
void init();
void deinit();
BITMAP* buffer;
BITMAP* buffer2;
BITMAP* espacio;
BITMAP* nave_up;
BITMAP* rayo;
double x,y,x_anterior,y_anterior;
float x1,y1;
int main()
{
init();
while (!key[KEY_ESC])
{
x1=x+nave_up->w/2;
y1=y+nave_up->h-100;
x_anterior=x; y_anterior=y;
/* put your code here */
clear_bitmap(buffer);
draw_sprite(buffer,espacio,0,0);
rectfill(buffer,200,5,400,50,makecol(23,34,54));
draw_sprite(buffer,nave_up,x,y);
if(key[KEY_DOWN])
y+=2;
if(key[KEY_UP])
y-=2;
if(key[KEY_RIGHT])
x+=2;
if(key[KEY_LEFT])
x-=2;
if(x>SCREEN_W-nave_up->w)
x=x_anterior;
if(x<0)
x=x_anterior;
if(y>SCREEN_H-nave_up->h)
y=y_anterior;
if(y<0)
y=y_anterior;
if(key[KEY_SPACE])
{
for(y1=y+nave_up->h-100; y1>0; y1=y1-4)
{
draw_sprite(buffer,espacio,0,0);
rectfill(buffer,200,5,400,50,makecol(23,34,54));
draw_sprite(buffer,nave_up,x,y);
textout(buffer,font,"Mi primer juego",240,20,makecol(255,255,255));
blit(buffer,buffer2,0,0,0,0,SCREEN_W,SCREEN_H);
draw_sprite(buffer2,rayo,x1,y1);
circlefill(buffer2,x1,y1,5,255);
textprintf_centre(buffer2,font,60,0,makecol(255,255,255),"Rayo:%.2f",y1);
blit(buffer2,buffer,0,0,0,0,SCREEN_W,SCREEN_H);
blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
}
}
text_mode(-1);
textout(buffer,font,"Mi primer juego",240,20,makecol(255,255,255));
blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
}
deinit();
destroy_bitmap(buffer);
destroy_bitmap(espacio);
destroy_bitmap(nave_up);
destroy_bitmap(rayo);
destroy_bitmap(buffer2);
return 0;
}
END_OF_MAIN()
void init()
{
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
if (res != 0)
{
allegro_message(allegro_error);
exit(-1);
}
buffer=create_bitmap(SCREEN_W,SCREEN_H);
buffer2=create_bitmap(buffer->w,buffer->h);
espacio=load_bitmap("espacio.bmp",0);
nave_up=load_bitmap("nave_up.tga",0);
rayo=load_bitmap("rayo.tga",0);
install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}
void deinit()
{
clear_keybuf();
/* add other deinitializations here */
}