#include <allegro.h> #include <cstdio> #include <cmath> #define RES_W 800 #define RES_H 600 #define DLZKA 512 struct XY{ int x,y; }; volatile int close_button_pressed = FALSE; void close_button_handler(void) { close_button_pressed = TRUE; } END_OF_FUNCTION(close_button_handler) void main_koniec(int ret,const char *str) { set_gfx_mode(GFX_TEXT,0,0,0,0); if(ret>0){ allegro_message("CHYBA %d: %s\n",ret,str); } allegro_exit(); exit(ret); } void main_koniec(void) { main_koniec(0,""); } void main_koniec(int ret) { main_koniec(ret,"Neznama chyba"); } int main(void) { if(allegro_init()!=0){ fputs("Inicializacia allegra zlyhala!\n",stderr); return 1; } if(install_timer()!=0){ fputs("Inicializacia timeru zlyhala!\n",stderr); return 1; } int depth=0; if((depth=desktop_color_depth())==0){ depth=32; } if(depth<16){ main_koniec(2,"Je potrebna aspon 16-bitova farebna hlbka!"); } LOCK_FUNCTION(close_button_handler); set_close_button_callback(close_button_handler); set_window_title("Packoban"); set_color_depth(depth); if(set_gfx_mode(GFX_AUTODETECT_WINDOWED,RES_W,RES_H,0,0)!=0){ if(set_gfx_mode(GFX_AUTODETECT,RES_W,RES_H,0,0)!=0){ main_koniec(3,"Nepodarilo sa inicializovat graficky rezim!"); } } BITMAP *actual=create_bitmap(screen->w,screen->h); if(actual==NULL) main_koniec(3,"Napodarilo sa naalokovat pamat pre bitmap!"); clear(actual); int x=screen->w/2; int y=screen->h/2; XY xy[DLZKA],a; float uhol=0; for(int i=0;i<DLZKA;i++){ xy[i].x=x; xy[i].y=y; } int pos=0; while(!close_button_pressed){ for(int i=0;i<DLZKA;i++){ a=xy[(pos+i)%DLZKA]; if(i+pos>=DLZKA){ circlefill(actual,a.x,a.y,10,makecol((i+1)*255/DLZKA,0,0)); } } a.x+=(int)(cos(uhol)*8); a.y+=(int)(sin(uhol)*8); uhol+=(float)(rand()%101-50)/100; if(a.x<0||a.y<0||a.x>=screen->w||a.y>=screen->h) uhol+=1; xy[(pos++)%DLZKA]=a; blit(actual,screen,0,0,0,0,actual->w,actual->h); rest(20); } destroy_bitmap(actual); main_koniec(); return 0; } END_OF_MAIN()