Skip to content

Instantly share code, notes, and snippets.

@kcbanner
Created February 17, 2014 22:15
Show Gist options
  • Save kcbanner/9060332 to your computer and use it in GitHub Desktop.
Save kcbanner/9060332 to your computer and use it in GitHub Desktop.
DroneComponent = class(nil, {});
function DroneComponent:OnInit(parentComponent)
self.uptime = 0;
self.parentComponent = parentComponent;
entity = self.parentComponent:getParent();
self.position = _G['caracal::ScriptUtil']:getPositionComponent(entity):getPosition();
self.lightComponent = _G['caracal::ScriptUtil']:getLightComponent(entity);
self.lightComponent:setBrightness(0);
-- Get a reference to the player's position
local playerEntity = _G['caracal::EntityManager']:getInstance():getEntity(
_G['caracal::Name'].new("player"))
self.playerPosition = _G['caracal::ScriptUtil'].getPositionComponent(playerEntity):getPosition();
end
function DroneComponent:OnPreUpdate(dt)
self.uptime = self.uptime + dt;
local xDelta = self.playerPosition:get_x() - self.position:get_x();
local yDelta = self.playerPosition:get_y() - self.position:get_y();
if (xDelta*xDelta + yDelta*yDelta) < 20000 then
self.lightComponent:setBrightness(0.3);
local y = self.position:get_y();
self.position:set_y(y + math.sin(2 * math.pi * self.uptime) / 10);
else
self.lightComponent:setBrightness(0);
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment