#include <allegro5/allegro5.h>
#include <allegro5/a5_iio.h>
#include <iostream>
#undef main

using namespace std;

int Plansza[640][480];

class CWoda
{
	private:
		float x;
		float y;

	public:
		CWoda(float xx, float yy) { x=xx; y=yy; Plansza[(int)x][(int)y]=1; }
		~CWoda() { Plansza[(int)x][(int)y]=0; }

		void Steep() 
		{ 
			if( x >=0 && y+1 >=0 && x < 640 && y+1 < 480 )
			{
				if ( Plansza[(int)x][(int)y+1]==0 )
				{ 
					Plansza[(int)x][(int)y]=0;
					y+=1;
					Plansza[(int)x][(int)y]=1;
				}
				else if ( Plansza[(int)x+1][(int)y]==0 )
				{ 
					Plansza[(int)x][(int)y]=0;
					x+=1;
					Plansza[(int)x][(int)y]=1;
				}
				else if ( Plansza[(int)x-1][(int)y]==0 )
				{ 
					Plansza[(int)x][(int)y]=0;
					x-=1;
					Plansza[(int)x][(int)y]=1;
				}
			}

			al_draw_pixel( x, y, al_map_rgb(0,0,255) );
		}
};

void main()
{
	al_init();
	al_init_iio_addon();
	al_install_keyboard();

	if ( !al_create_display(640, 480) )
	{
		cout << "Nie udalo sie utworzyc okna!" << endl;
		getchar();
		return;
	}

	CWoda *O_woda[1000];
	O_woda[0] = new CWoda(100, 100);


	ALLEGRO_KEYBOARD_STATE KEY_STATE;
	al_get_keyboard_state(&KEY_STATE);

	while ( !al_key_down(&KEY_STATE, ALLEGRO_KEY_ESCAPE) )
	{
		al_get_keyboard_state(&KEY_STATE);
		al_clear_to_color( al_map_rgb(255,255,255) );

		for(int i=0; i<1000; i++)
		{
			if ( O_woda[i]!=NULL ) O_woda[i]->Steep(); else break;
		}

		al_flip_display();
	}

	for(int i=0; i<1000; i++)
	{
		if ( O_woda[i]!=NULL ) {delete O_woda[i];} else break;
	}
}