
BonusEgg = BonusItem:createSubClass();
registerSpawn("BonusEgg");

function BonusEgg:init()

   BonusItem.init(self);

   self:setBounciness(0.8);

   self.spawnCountdown = 5 * 30;

   self:setTexture("joust1.tga");
   setSpriteFromDef(self, 4, 1, false);

   self.angle = 0;

end

function BonusEgg:update()

   BonusItem.update(self);

   -- Apply a bit of spin to the egg.

   local dx, dy = self:getVel();

   if math.abs(dx) > 0.25 then
      self.angle = self.angle + dx * 10;
   else
      self.angle = 0;
   end

   self:setSpriteAngle(self.angle);

   -- Respawn after some time goes by.

   if self:getOnGround() then
      
      self.spawnCountdown = self.spawnCountdown - 1;

      if self.spawnCountdown <= 0 then
         
         local npc = NPC:create();

         npc:setPos(self:getPos());

         self:die();

      end

   end

end

