-- a new experiment in exercise, generating a grid background with quads
-- using code. also, it works.

-- don't put this number below 16 or else you'll get fucked, especially on
-- widescreen. even 16 can be bad on screens like SelectMusic. it could also
-- just be the banner wheel sucking up memory too.
local squaresize = 72;

local numTilesH = math.ceil(SCREEN_WIDTH*4/squaresize);
local numTilesV = math.ceil(SCREEN_HEIGHT/squaresize);

local t = Def.ActorFrame {};

local square = Def.ActorFrame{
    LoadActor( THEME:GetPathG("Common","Button"),"Start","PRESS" ) .. {
        Condition = GAMESTATE:GetCoinMode() == "CoinMode_Free";
        TweenCommand=cmd(finishtweening;smooth,numTilesH/4;addx,-SCREEN_WIDTH+(squaresize/2);smooth,numTilesH/4;addx,SCREEN_WIDTH-(squaresize/2);queuecommand,"Tween");
    };
};

for i=0,numTilesH do
	for j=0,4 do
        t[#t+1] = square..{
            InitCommand=function(self)
                local x = i*squaresize-(SCREEN_WIDTH/2);
                local y = (16*j)-16;
                self:x(x);
                self:y(SCREEN_BOTTOM-60+y);
                self:propagate(true);
                self:diffusealpha(1-(0.75/j));
                self:zoom(j/4);
                self:playcommand("Tween");
            end;
            TweenCommand=cmd(finishtweening;smooth,numTilesH/4;addx,-SCREEN_WIDTH/2+(squaresize/2);smooth,numTilesH/4;addx,SCREEN_WIDTH-(squaresize/2);queuecommand,"Tween");
            ResetCommand=cmd(smooth,numTilesH/4;addx,SCREEN_WIDTH/2-(squaresize/2);queuecommand,"Tween");
        };
    end;
end;

return t;