
screenShakeAngle = 0;
screenShakeMag = 0;
mainPlayer = nil;
baddieCount = 0;
playerScore = 0;

-- Graphical-only niceness.
include("shadow.lua");
include("explosion.lua");
include("smoke.lua");

-- Projectiles.
include("shot.lua");
include("badshot.lua");
include("playershot.lua");

-- Things with a brain.
include("player.lua");
include("enemy.lua");

-- Other things we can shoot at.
include("building.lua");

-- User interface.
include("ui.lua");

writeConsole("Shmuptest!\n");


-- Controls
setControlName(0, "Shoot");


function worldUpdate()

   local skipSpawn = false;

   if baddieCount > 10 then
	  skipSpawn = true;
   end

   baddieCount = 0;



   screenShakeAngle = screenShakeAngle + 1;
   screenShakeMag = screenShakeMag * 0.5;

   -- Handle spawning enemies off-screen.
   if not skipSpawn and not (mainPlayer == nil) and not (mainPlayer:getDead()) then
	  if math.random() < 0.1 then
		 
		 local newBaddie = BadGuy:create();
         newBaddie:setLayer(3);

		 local x,y = mainPlayer:getPos();

		 local baddieAngle = math.random() * 6.28;

		 x = x + math.cos(baddieAngle) * 1000;
		 y = y + math.sin(baddieAngle) * 1000;

		 newBaddie:setPos(x, y);
		 newBaddie.angle = (baddieAngle + 180) * 180 / 3.14159;

	  end
   end

   updateGamePlayUI();

end


function worldPostUpdate()

end

function handleMouseMotion(x, y)

   --writeConsole("Mouse moved! "..x.." "..y.."\n");

end

function handleMouseDown(x, y, button)

   --writeConsole("Mouse down! "..x.." "..y.." "..button.."\n");

end

function handleMouseUp(x, y, button)

   --writeConsole("Mouse up! "..x.." "..y.." "..button.."\n");

end

-- Toss us into an initial world.
loadTiles("start.xml.tiles.rle");
loadEntities("start.xml");
player = Player:create();
player:setLayer(3);

