#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_image.h>
int szer = 1366, wys = 766, rozm = 1000;
double kat = 0, s1 = 0.1, o1 = 1;
#define PI 3.14
int main()
{
al_init();
al_install_keyboard();
al_init_font_addon();
al_init_image_addon();
ALLEGRO_KEYBOARD_STATE klawiatura;
ALLEGRO_DISPLAY * okno = al_create_display( szer, wys );
al_set_window_title( okno, "Allegro5 klawiatura i czas" );
ALLEGRO_BITMAP * kwadrat = al_create_bitmap( rozm, rozm );
ALLEGRO_FONT * font8 = al_create_builtin_font();
al_set_target_bitmap( kwadrat );
al_clear_to_color( al_map_rgb( 0, 0, 0 ) );
al_set_target_bitmap( al_get_backbuffer( okno ) );
ALLEGRO_BITMAP * drzewo1 = al_load_bitmap( "Files/drzewo1.png" );
ALLEGRO_BITMAP * pilka = al_load_bitmap( "Files/pilka.png" );
al_convert_mask_to_alpha( pilka, al_map_rgb( 255, 0, 255 ) );
ALLEGRO_BITMAP * bmp = al_get_backbuffer( okno );
ALLEGRO_LOCKED_REGION * lock = al_lock_bitmap( bmp, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE );
int r, g, b;
int x = 140, y = 100;
double czas = al_get_time();
while( !al_key_down( & klawiatura, ALLEGRO_KEY_ESCAPE ) )
{
ALLEGRO_COLOR color = al_get_pixel( bmp, x, y );
al_unmap_rgb( color,( unsigned char * ) & r,( unsigned char * ) & g,( unsigned char * ) & b );
al_get_keyboard_state( & klawiatura );
if( al_get_time() > czas + 0.0001 )
{
if( al_key_down( & klawiatura, ALLEGRO_KEY_RIGHT ) && x < szer -( rozm * s1 / 2 ) ) x = x + 1;
if( al_key_down( & klawiatura, ALLEGRO_KEY_LEFT ) && x -( rozm * s1 / 2 ) > 0 ) x = x - 1;
if( al_key_down( & klawiatura, ALLEGRO_KEY_DOWN ) && y < wys -( rozm * s1 / 2 ) ) y = y + 1;
if( al_key_down( & klawiatura, ALLEGRO_KEY_UP ) && y -( rozm * s1 / 2 ) > 0 ) y = y - 1;
if( y -( rozm * s1 / 2 ) < 0 ) y++;
if( y > wys -( rozm * s1 / 2 ) ) y--;
if( x -( rozm * s1 / 2 ) < 0 ) x++;
if( x > szer -( rozm * s1 / 2 ) ) x--;
if( al_key_down( & klawiatura, ALLEGRO_KEY_W ) ) kat += 1;
if( al_key_down( & klawiatura, ALLEGRO_KEY_S ) ) kat -= 1;
if( al_key_down( & klawiatura, ALLEGRO_KEY_R ) && s1 < 1 ) s1 += 0.001;
if( al_key_down( & klawiatura, ALLEGRO_KEY_F ) && s1 > 0.1 ) s1 -= 0.001;
if( al_key_down( & klawiatura, ALLEGRO_KEY_E ) ) o1 += 0.5;
if( al_key_down( & klawiatura, ALLEGRO_KEY_D ) ) o1 -= 0.5;
czas = al_get_time();
}
al_draw_tinted_scaled_rotated_bitmap( drzewo1, al_map_rgba_f( 1.0, 1.0, 1.0, 1 ), 0, 0, 0, 0, 1.71, 1.3, 0, 0 );
al_draw_tinted_scaled_rotated_bitmap( pilka, al_map_rgba( 255, 255, 255, o1 ), rozm / 2, rozm / 2, x, y, s1, s1, PI * kat / 180, 0 );
al_draw_textf( font8, al_map_rgb( 255, 255, 0 ), 10, 10, 0, "x=%d , y=%d", x, y );
al_draw_textf( font8, al_map_rgb( 255, 255, 0 ), 10, 20, 0, "kat=%g , s1=%g", kat, s1 );
al_draw_textf( font8, al_map_rgb( 255, 255, 0 ), 10, 30, 0, "o1=%g ", o1 );
al_draw_textf( font8, al_map_rgb( 255, 255, 0 ), 10, 40, 0, "r=%d , g=%d , b=%d", r, g, b );
al_draw_textf( font8, al_map_rgb( 255, 255, 0 ), 10, 50, 0, "x=%d , y=%d", x, y );
if( r == 0, g == 194, b == 254 )
{
al_draw_textf( font8, al_map_rgb( 0, 0, 0 ), 50, 80, 0, "Bla, bla działa bla, bla" );
}
if( kat > 360 ) kat = 0;
if( o1 > 255 ) o1 = 255;
if( kat < - 360 ) kat = 0;
if( o1 < 0 ) o1 = 0;
al_draw_pixel( x, y, al_map_rgb( 0, 0, 0 ) );
al_unlock_bitmap( bmp );
al_flip_display();
}
al_destroy_bitmap( drzewo1 );
al_destroy_bitmap( kwadrat );
al_destroy_display( okno );
return 0;
}