-- Exercise scripting a bit in our test-level

-- write out that we loaded sucessfully (mor or less, anyway)
io.write("Starting script for Level0 in BlinkenLUA / ",_VERSION,"!\n")

-- declare some global variables
-- GFX_HUNTINGSEASON = -1;
-- OBJ_HUNTINGSEASON = -1;

FLOCKS = {};

FLOCKS.gfxwait = 1;
FLOCKS.objwait = 1;
FLOCKS.maxx = 2528;
FLOCKS.maxy = 768;


-- Required function: Initializing the level
function initLevel ()
    -- preload all gfx (on-the-fly loading is NOT recommended)
    -- GFX_HUNTINGSEASON = LoadGFX("fg_huntingseason.bmp");

    -- create sign
    -- OBJ_HUNTINGSEASON = AddObject(GFX_HUNTINGSEASON, 30, 30, 0, 1, 0);

	SetLockedBG(1);

	--FLOCKS.snd = LoadSoundFX("collectGeschenk.ogg");

	FLOCKS.gfxs = {};

	count = 0;
   for k = 1, 2 do 
	   for j = 1, 3 do 
		   FLOCKS.gfxs[count] = {};
		  fname = "Schneeflo" .. j;
			if k == 1 then
				fname = fname .. "k";
			else
				fname = fname .. "g";
			end
			fname = fname .. "_";
			basename = fname;
		   for i = 0, 59, 1 do
				fname = basename;
			  if i < 10 then
				fname = fname .. "000" .. i .. ".png";
			  else
				fname = fname .. "00" .. i .. ".png";
			  end

			  FLOCKS.gfxs[count][i] = LoadGFX(fname);
		   end
			count = count + 1;
		end
	end

	for j = 0, 4, 1 do
		FLOCKS.gfxs[count] = {};
		for i = 0, 59, 1 do
			fname = "";
			if j == 0 then
				fname = "geschenk1_";
			elseif j == 1 then
				fname = "geschenk2_";
				FLOCKS.minpixelnum = count;
			elseif j == 2 then
				fname = "geschenk3_";
			elseif j == 3 then
				fname = "geschenk3_2_";
			elseif j == 4 then
				fname = "geschenk3_3_";
				FLOCKS.maxpixelnum = count;
			end

			if i < 10 then
				fname = fname .. "000" .. i .. ".png";
			else
				fname = fname .. "00" .. i .. ".png";
			end
			--io.write(fname,"\n");

			FLOCKS.gfxs[count][i] = LoadGFX(fname);
	   	end
		count = count + 1;
	end
	
	for j = 0, 2, 1 do
		FLOCKS.gfxs[count] = {};
		for i = 0, 59, 1 do
			fname = "";
			if j == 0 then
				fname = "Baum1_";
				FLOCKS.minbaumnum = count;
			elseif j == 1 then
				fname = "Baum2_";
			elseif j == 2 then
				fname = "Baum3_";
				FLOCKS.maxbaumnum = count;
			end

			if i < 10 then
				fname = fname .. "000" .. i .. ".png";
			else
				fname = fname .. "00" .. i .. ".png";
			end
			--io.write(fname,"\n");

			FLOCKS.gfxs[count][i] = LoadGFX(fname);
	   	end
		count = count + 1;
	end


	FLOCKS.obj = {};
   for k = 1, 300 do 
		FLOCKS.obj[k] = {};
		FLOCKS.obj[k].gfxnum = math.random(0, 59);
		type = math.random(0, 2);
		speed = math.random(2, 4);
		if k < 20 then
			type = 6;
			 FLOCKS.obj[k].wind = 1;
		elseif k < 90 then
			type = type + 2;
			speed = speed * 2;
			 FLOCKS.obj[k].wind = 1;
		else
			 FLOCKS.obj[k].wind = 2;
		end
		FLOCKS.obj[k].type = type;
		FLOCKS.obj[k].speed = speed;
		if FLOCKS.obj[k].type < 3 then
			FLOCKS.obj[k].x = math.random(-600, FLOCKS.maxx);
		else
			FLOCKS.obj[k].x = math.random(0, FLOCKS.maxx);
		end
		FLOCKS.obj[k].y = math.random(0, FLOCKS.maxy);

		if FLOCKS.obj[k].type == 6 then
			 FLOCKS.obj[k].obj = AddFGTrigger(FLOCKS.gfxs[FLOCKS.obj[k].type][FLOCKS.obj[k].gfxnum],
											0,0, "HandleGeschenk", 1, 1);
			SetOnTop(FLOCKS.obj[k].obj, 1);
		else
			ontop = 1;
			if FLOCKS.obj[k].type < 3 then
				ontop = 0;
			end
			FLOCKS.obj[k].obj = AddObject(FLOCKS.gfxs[FLOCKS.obj[k].type][FLOCKS.obj[k].gfxnum], 
											0,0, 0, 1, ontop, 0);
		end

	end

	FLOCKS.maxobjcount = 300;

	-- AUTOPIXELINSERTHERE --
-- BAUM
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1184;
FLOCKS.obj[FLOCKS.maxobjcount].y = 64;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = FLOCKS.minbaumnum + 1;
FLOCKS.obj[FLOCKS.maxobjcount].obj = AddObject(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum], 0,0, 0, 1, 0, 0);
-- BAUM
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 960;
FLOCKS.obj[FLOCKS.maxobjcount].y = 96;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = FLOCKS.minbaumnum;
FLOCKS.obj[FLOCKS.maxobjcount].obj = AddObject(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum], 0,0, 0, 1, 0, 0);
-- BAUM
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1632;
FLOCKS.obj[FLOCKS.maxobjcount].y = 96;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = FLOCKS.minbaumnum;
FLOCKS.obj[FLOCKS.maxobjcount].obj = AddObject(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum], 0,0, 0, 1, 0, 0);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1824;
FLOCKS.obj[FLOCKS.maxobjcount].y = 96;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- BAUM
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 2016;
FLOCKS.obj[FLOCKS.maxobjcount].y = 96;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = FLOCKS.minbaumnum;
FLOCKS.obj[FLOCKS.maxobjcount].obj = AddObject(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum], 0,0, 0, 1, 0, 0);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 2176;
FLOCKS.obj[FLOCKS.maxobjcount].y = 96;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 512;
FLOCKS.obj[FLOCKS.maxobjcount].y = 128;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 864;
FLOCKS.obj[FLOCKS.maxobjcount].y = 128;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1088;
FLOCKS.obj[FLOCKS.maxobjcount].y = 128;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1280;
FLOCKS.obj[FLOCKS.maxobjcount].y = 128;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1568;
FLOCKS.obj[FLOCKS.maxobjcount].y = 256;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- BAUM
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1664;
FLOCKS.obj[FLOCKS.maxobjcount].y = 288;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = FLOCKS.minbaumnum;
FLOCKS.obj[FLOCKS.maxobjcount].obj = AddObject(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum], 0,0, 0, 1, 0, 0);
-- BAUM
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 2048;
FLOCKS.obj[FLOCKS.maxobjcount].y = 288;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = FLOCKS.minbaumnum + 1;
FLOCKS.obj[FLOCKS.maxobjcount].obj = AddObject(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum], 0,0, 0, 1, 0, 0);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 2336;
FLOCKS.obj[FLOCKS.maxobjcount].y = 288;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1728;
FLOCKS.obj[FLOCKS.maxobjcount].y = 320;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1536;
FLOCKS.obj[FLOCKS.maxobjcount].y = 352;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1984;
FLOCKS.obj[FLOCKS.maxobjcount].y = 352;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 2144;
FLOCKS.obj[FLOCKS.maxobjcount].y = 352;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 2272;
FLOCKS.obj[FLOCKS.maxobjcount].y = 352;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1376;
FLOCKS.obj[FLOCKS.maxobjcount].y = 384;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 992;
FLOCKS.obj[FLOCKS.maxobjcount].y = 416;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1216;
FLOCKS.obj[FLOCKS.maxobjcount].y = 416;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- BAUM
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 160;
FLOCKS.obj[FLOCKS.maxobjcount].y = 448;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = FLOCKS.minbaumnum + 2;
FLOCKS.obj[FLOCKS.maxobjcount].obj = AddObject(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum], 0,0, 0, 1, 0, 0);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 864;
FLOCKS.obj[FLOCKS.maxobjcount].y = 480;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 800;
FLOCKS.obj[FLOCKS.maxobjcount].y = 544;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1216;
FLOCKS.obj[FLOCKS.maxobjcount].y = 544;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- BAUM
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 2208;
FLOCKS.obj[FLOCKS.maxobjcount].y = 576;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = FLOCKS.minbaumnum + 2;
FLOCKS.obj[FLOCKS.maxobjcount].obj = AddObject(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum], 0,0, 0, 1, 0, 0);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 640;
FLOCKS.obj[FLOCKS.maxobjcount].y = 608;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1312;
FLOCKS.obj[FLOCKS.maxobjcount].y = 608;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- BAUM
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 256;
FLOCKS.obj[FLOCKS.maxobjcount].y = 640;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = FLOCKS.minbaumnum;
FLOCKS.obj[FLOCKS.maxobjcount].obj = AddObject(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum], 0,0, 0, 1, 0, 0);
-- BAUM
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 768;
FLOCKS.obj[FLOCKS.maxobjcount].y = 640;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = FLOCKS.minbaumnum;
FLOCKS.obj[FLOCKS.maxobjcount].obj = AddObject(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum], 0,0, 0, 1, 0, 0);
-- BAUM
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1568;
FLOCKS.obj[FLOCKS.maxobjcount].y = 640;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = FLOCKS.minbaumnum;
FLOCKS.obj[FLOCKS.maxobjcount].obj = AddObject(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum], 0,0, 0, 1, 0, 0);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 480;
FLOCKS.obj[FLOCKS.maxobjcount].y = 672;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 864;
FLOCKS.obj[FLOCKS.maxobjcount].y = 672;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 1504;
FLOCKS.obj[FLOCKS.maxobjcount].y = 672;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 2208;
FLOCKS.obj[FLOCKS.maxobjcount].y = 672;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 2240;
FLOCKS.obj[FLOCKS.maxobjcount].y = 672;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 2272;
FLOCKS.obj[FLOCKS.maxobjcount].y = 672;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 2304;
FLOCKS.obj[FLOCKS.maxobjcount].y = 672;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
-- GESCHENK
FLOCKS.maxobjcount = FLOCKS.maxobjcount + 1;
FLOCKS.obj[FLOCKS.maxobjcount] = {};
FLOCKS.obj[FLOCKS.maxobjcount].x = 2336;
FLOCKS.obj[FLOCKS.maxobjcount].y = 672;
FLOCKS.obj[FLOCKS.maxobjcount].gfxnum = math.random(0, 59);
FLOCKS.obj[FLOCKS.maxobjcount].speed = 0;
FLOCKS.obj[FLOCKS.maxobjcount].wind = 0;
FLOCKS.obj[FLOCKS.maxobjcount].type = math.random(FLOCKS.minpixelnum,FLOCKS.maxpixelnum);
FLOCKS.obj[FLOCKS.maxobjcount].obj = 
    AddGFXPixel(FLOCKS.gfxs[FLOCKS.obj[FLOCKS.maxobjcount].type][FLOCKS.obj[FLOCKS.maxobjcount].gfxnum],
           0,0, 1);
	-- AUTOPIXELINSERTHERE --

end

-- Required function: Physics-loop for scripting part
function scriptPhysics ()
	FLOCKS.gfxwait = FLOCKS.gfxwait - 1;
	if FLOCKS.gfxwait == 0 then
		FLOCKS.gfxwait = 5;
	    for k = 1, FLOCKS.maxobjcount do 
			FLOCKS.obj[k].gfxnum = FLOCKS.obj[k].gfxnum + 1;
			if FLOCKS.obj[k].gfxnum == 60 then
				FLOCKS.obj[k].gfxnum = 0;
			end
			SetGFX( FLOCKS.obj[k].obj, FLOCKS.gfxs[FLOCKS.obj[k].type][FLOCKS.obj[k].gfxnum]);
		end
	end	
	FLOCKS.objwait = FLOCKS.objwait - 1;
	if FLOCKS.objwait == 0 then
		FLOCKS.objwait = 4;
	    for k = 1, FLOCKS.maxobjcount do 
			FLOCKS.obj[k].y = FLOCKS.obj[k].y + FLOCKS.obj[k].speed;
			FLOCKS.obj[k].x = FLOCKS.obj[k].x +  FLOCKS.obj[k].wind;
			if FLOCKS.obj[k].y > FLOCKS.maxy then
				FLOCKS.obj[k].y = 0;
				if FLOCKS.obj[k].type < 3 then
					FLOCKS.obj[k].x = math.random(-600, FLOCKS.maxx);
				else
					FLOCKS.obj[k].x = math.random(0, FLOCKS.maxx);
				end
			end
			if FLOCKS.obj[k].x >= 0 then
				SetObjPos(FLOCKS.obj[k].obj, FLOCKS.obj[k].x, FLOCKS.obj[k].y);
			else
				SetObjPos(FLOCKS.obj[k].obj, 99999, 99999);
			end
		end
	end
end

-- Required function: Callback on "Action"-Button on FG-Objects
function handleAction (obj_id)
    -- NOTHING TO DO
end

function HandleGeschenk(objid)
	--SetTriggerActive(objid, 0);
	--SetVisible(objid, 0);
	--PlaySoundFX(FLOCKS.snd);
	SetTriggerActive(objid, 0);
	SetPixel(objid, 1);
	IncMaxPixels(1);
end
