#include <allegro.h>
BITMAP*buf;
BITMAP*fondo;
BITMAP*nave;
int x,y;
void init(){
allegro_init();
set_color_depth(24);
set_window_title("Star Wars Invaders v. 1.0");
set_gfx_mode(GFX_AUTODETECT_WINDOWED,320,240,0,0);
install_timer();
install_keyboard();
install_mouse();
}
void juego_raton(){
show_mouse(screen);
buf=create_bitmap(320,240);
fondo=load_bmp("fondo.bmp",0);
nave=load_bmp("nave.bmp",0);
set_mouse_range(0,0,320,240);
set_mouse_speed(2,2);
set_mouse_sprite(nave);
while(!key[KEY_ESC]){
blit(buf, screen,0,0,0,0,320,240);
clear(buf);
draw_sprite(buf, fondo,0,0);
}
}
void juego_teclado(){
x=140;
y=195;
char*w="x";
char*z="y";
buf=create_bitmap(320,240);
fondo=load_bmp("fondo.bmp",0);
nave=load_bmp("nave.bmp",0);
while(!key[KEY_ESC]){
//movimiento de la nave
if(key[KEY_LEFT]){
x=x-4;
}
if(key[KEY_RIGHT]){
x=x+4;
}
if(key[KEY_UP]){
y=y-4;
}
if(key[KEY_DOWN]){
y=y+4;
}
//Universo donuts
if(x<=0){
x=0;
}
if(x>=280){
x=280;
}
if(y<=0){
y=0;
}
if(y>=195){
y=195;
}
blit(buf, screen,0,0,0,0,320,240);
clear(buf);
draw_sprite(buf, fondo,0,0);
draw_sprite(buf, nave, x,y);
}
textout_ex(screen, font,10, 230, makecol(255,255,255),-1,"%s,%d",w,x);
}
void intro(){
textout_ex(screen, font, "Star Wars invaders", 90, 100, makecol(255, 255, 255), -1);
textout_ex(screen, font, "Selecciona teclado (t) o raton (r)", 70, 170, makecol(255, 255, 255), -1);
textout_ex(screen, font, "Para salir pulsa Esc", 87, 190, makecol(255, 255, 255), -1);
while(!key[KEY_ESC]){
if(key[KEY_T]){
juego_teclado();
}
if(key[KEY_R]){
juego_raton();
}
}
}
int main(){
init();
intro();
}
END_OF_MAIN()