


ActivateIndicator = Entity:createSubClass();

function ActivateIndicator:init()

	self:setTexture("bonuses.tga");
	self:setSpriteFrame(224, 0, 256, 32);
	self:setSize(32, 32);
    self:setDepth(2);

end

-- All activatables waiting for the player to lift up the button
-- before responding to it being pressed so we don't spam activations.
activatableWaitingForButtonRelease = false;

Activatable = Entity:createSubClass();

function Activatable:init()

   self.playerOnMe = false;
   self.playerWasOnMe = false;
   self.activateIndicator = nil;

   -- Generally, this is going to be something the player stands in
   -- front of and activates.
   self:setDepth(-0.1);

end

function Activatable:update()

   if self.playerWasOnMe then

      -- Create an indicator letting the player know they can activate
      -- this.
      if not self.activateIndicator then
         local x, y = self:getPos();
         self.activateIndicator = ActivateIndicator:create();
         self.activateIndicator:setLayer(self:getLayer());
         self.activateIndicator:setPos(x, y + 64);
      end

      -- React to activation.
      local activatePressed = getControlBoolValue(7);

      if activatePressed then

         if not activatableWaitingForButtonRelease then
            
            activatableWaitingForButtonRelease = true;

            -- DO SOMETHING AWESOME.

            --writeConsole("Activatable activated: "..self:getName().."\n");
            self:activated();

         end

      else

         activatableWaitingForButtonRelease = false;

      end

   else

      if self.activateIndicator then

         self.activateIndicator:die();
         self.activateIndicator = nil;

      end

   end

end

function Activatable:postUpdate()

   if self.playerOnMe then
      self.playerWasOnMe = true;
   else
      self.playerWasOnMe = false;
   end

   self.playerOnMe = false;

end

function Activatable:collided(otherEnt)

   if otherEnt == "player" or otherEnt == "worldPlayer" then
      self.playerOnMe = true;
   end

end

function Activatable:activated()

   writeConsole("Error: You're supposed to override activated() for an Activatable.\n");

end


