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

function BonusItem:init()

   self:setGravityInfluence(0.5);
   self:setBlockable(true);

   self.firstFrame = true;

   self:setSpriteScale(2);
   self:setSize(32, 32);

   self:setLayer(3);
end

function BonusItem:update()

   -- Screen wrapping.

   local x, y = self:getPos();
   
   if x < -512 then
      x = 512;
   end

   if x > 512 then
      x = -512;
   end

   self:setPos(x, y);

   if y < screenBottom then
      self:die();
   end

   -- Friction

   local dx, dy = self:getVel();

   dx = dx * 0.9;
   dy = dy * 0.9;
   
   self:setVel(dx, dy);

end

function BonusItem:postUpdate()

   self.firstFrame = false;

end

function BonusItem:collided(otherEnt)

   local ent = entitiesByName[otherEnt];

   if ent then
      if ent.isPlayer and not self.firstFrame then
         self:die();
      end
   end

end

