program alegro7;
(*
allegro5 -> biblioteca alegro
al5image -> biblioteca para imagenes
*)
uses
allegro5,al5image;
var
ventana: ALLEGRO_DISPLAYptr = nil;
evento: ALLEGRO_EVENT;
cola_de_eventos: ALLEGRO_EVENT_QUEUEptr = nil;
tiempo: ALLEGRO_TIMERptr = nil;
imagen: ALLEGRO_BITMAPptr = nil;
transformacion: ALLEGRO_TRANSFORM;
ejecutar: Boolean;
posicionX,posicionY: Single;
begin
//iniciar allegro
al_init();
//instalar teclado
al_install_keyboard();
//iniciar imagen
al_init_image_addon();
//configurar ventana en modo ventana
al_set_new_display_flags(ALLEGRO_WINDOWED);
//crear ventana(ancho,alto)
ventana := al_create_display(640,480);
//poner titulo a la ventana
al_set_window_title(ventana,'transformaciones');
//ocultar raton
al_hide_mouse_cursor(ventana);
//crear cola de eventos
cola_de_eventos := al_create_event_queue();
//crear tiempo para fps
tiempo := al_create_timer(1/60);
//cargamos imagen
imagen := al_load_bitmap('alien.png');
//registrar eventos
al_register_event_source(cola_de_eventos,al_get_keyboard_event_source());
al_register_event_source(cola_de_eventos,al_get_display_event_source(ventana));
al_register_event_source(cola_de_eventos,al_get_timer_event_source(tiempo));
//inicio de variables
ejecutar := true;
posicionX := 150;
posicionY := 50;
//iniciamos el tiempo
al_start_timer(tiempo);
while (ejecutar = true) do
begin
//esperamos a la cola de eventos
al_wait_for_event(cola_de_eventos,@evento);
case evento.ftype of
//manejo de fps
ALLEGRO_EVENT_TIMER: begin
//limpiar pantalla con un color cualquiera
al_clear_to_color(al_map_rgb(0,0,160));
//transformacion por aceleraccion
al_identity_transform(transformacion);
al_scale_transform(transformacion,1.5,1.5);
al_rotate_transform(transformacion,al_get_time/5);
al_translate_transform(transformacion,posicionY,posicionY);
al_use_transform(transformacion);
//pintamos imagen(imagen,x,y,voltear)
al_draw_bitmap(imagen,posicionX,posicionY,0);
posicionY += 0.5;
//actualizar pantalla
al_flip_display();
end;
//mover imagen
ALLEGRO_EVENT_KEY_CHAR: begin
if (evento.keyboard.unichar = ord('a')) then
posicionX := posicionX - 3
else if (evento.keyboard.unichar = ord('d')) then
posicionX := posicionX + 3;
end;
//si pulso escape salgo del bucle
ALLEGRO_EVENT_KEY_DOWN: begin
if (evento.keyboard.keycode = ALLEGRO_KEY_ESCAPE) then
begin
ejecutar := false;
end;
end;
ALLEGRO_EVENT_KEY_UP: begin
if(evento.keyboard.keycode = ALLEGRO_KEY_Z) then
al_stop_timer(tiempo) //parar timer
else if(evento.keyboard.keycode = ALLEGRO_KEY_X) then
al_resume_timer(tiempo) //activar timer
else if(evento.keyboard.keycode = ALLEGRO_KEY_C) then
al_set_timer_speed(tiempo,1/15) //poner velocidad
else if(evento.keyboard.keycode = ALLEGRO_KEY_V) then
al_set_timer_speed(tiempo,1/60);
end;
end; //fin case
end; //fin bucle while
al_destroy_display(ventana); //destruir ventana
ventana := nil;
al_destroy_event_queue(cola_de_eventos); //destruir cola
cola_de_eventos := nil;
al_destroy_bitmap(imagen); //destruir imagen
imagen := nil;
al_destroy_timer(tiempo); //destruir tiempo
tiempo := nil;
al_uninstall_keyboard(); //desinstalar teclado
end. //fin programa