
Light_Basic = Entity:createSubClass();
registerSpawn("Light_Basic");

function Light_Basic:init()

   self:setTexture("lightblobs1.tga");
   self:setSpriteFrame(0, 0, 64, 64);
   self:setSpriteScale(8);
   self:setIsLight(true);

   self:setFullbright(true);
   self:setLayer(2);

end

function Light_Basic:save()
   return {};
end

function Light_Basic:initFromSave(saveData)
end


function Light_Basic:postUpdate()

   local target = self:getLinkTarget();

   if target and not(target == "") then

      local ent = entitiesByName[target];

      if ent then
         self:setPos(ent:getPos());
      else
         self:die();
      end

   end
end


Light_Cone = Light_Basic:createSubClass();
registerSpawn("Light_Cone");

function Light_Cone:init()

   Light_Basic.init(self);

   self:setTexture("light_cone1.tga");
   self:setSpriteFrame(0, 0, 256, 256);
   self:setSpriteOffset(0, -128);
   self:setSpriteScale(2);

end




-------------------------------------------------------------------------------
-- Player flashlight
-------------------------------------------------------------------------------

-- FIXME: Make this suck less.

Light_Flashlight = Light_Cone:createSubClass();
registerSpawn("Light_Flashlight");

function Light_Flashlight:update()

   --Light_Cone.update(self);

   local target = self:getLinkTarget();

   -- Now get the offset from the player.

   local tx = 0;
   local ty = 0;

   if target and not(target == "") then

      local ent = entitiesByName[target];

      if ent then
         tx, ty = ent:getPos();
      end

      local mx, my = getMousePos();
      local dx = tx - mx;
      local dy = my - ty;

      local angle = math.atan2(dx, dy);

      self:setSpriteAngle(angle * 180.0 / 3.14159);

   end

end





