Skip to content
Browse files

Added turret powerup

  • Loading branch information...
1 parent 2fda599 commit 1bb5c973f61311cddebb2489a652691e89b2b01f @Textmode Textmode committed Aug 28, 2012
Showing with 51 additions and 1 deletion.
  1. +46 −0 hull/turret.lua
  2. +5 −1 powerup.lua
View
46 hull/turret.lua
@@ -0,0 +1,46 @@
+-------------------------------------------------------------------------
+-- [turret.lua]
+-- hull.turret
+-------------------------------------------------------------------------
+local ship = require "ship"
+
+local _M = {_NAME = "turret", _TYPE = 'module'}
+local _MT = {__index = _M}
+local _MMT = {__index = ship}
+setmetatable(_M, _MMT)
+-------------------------------------------------------------------------
+
+function _M.new(t)
+ t = t or {}
+ e = ship.new(t)
+
+ e.shooting = true
+ e.owner = t.owner or nil
+ e.facing = (e.owner and e.owner.facing) or math.random()*math.pi*2
+ e.shooting = false
+
+ return setmetatable(e, _MT)
+end
+
+function _M:think(dt)
+ if e.owner then
+ self.facing = e.owner.facing
+ self.shooting = e.owner.shooting
+
+ self.pos_x = e.owner.pos_x - 10
+ self.pos_y = e.owner.pos_y - 10
+ else
+ self.facing = math.random
+ self.shooting = true
+ end
+end
+
+
+function _M:docollision()
+
+end
+-------------------------------------------------------------------------
+if _VERSION == "Lua 5.1" then _G[_M._NAME] = _M end
+
+return _M
+
View
6 powerup.lua
@@ -3,6 +3,7 @@
-- powerup
-------------------------------------------------------------------------
local entity = require "entity"
+local turret = require "hull.turret"
local _M = {_NAME = "powerup", _TYPE = 'module'}
local _MT = {__index = _M}
@@ -16,13 +17,14 @@ icons = {
heal30 = Image "gfx/RepairPack2.png";
heal60 = Image "gfx/RepairPack3.png";
heal100 = Image "gfx/RepairPack4.png";
+ turret = Image "gfx/AutoTurret.png";
}
-------------------------------------------------------------------------
function _M.getRandomPowerup(t)
local p = _M.new(t)
- local set = {'heal10', 'heal30', 'heal60', 'heal100'}
+ local set = {'heal10', 'heal30', 'heal60', 'heal100', 'turret'}
p.effect = set[math.random(#set)]
return _M.new(p)
end
@@ -70,6 +72,8 @@ function _M:doeffect(e)
e:heal(e.shieldmax*.6*impact)
elseif self.effect == 'heal100' then
e:heal(e.shieldmax*impact)
+ elseif self.effect == 'turret' then
+ e:addentity(turret.new{owner = e})
else
print("Unknown powerup effect", self.effect)
end

0 comments on commit 1bb5c97

Please sign in to comment.
Something went wrong with that request. Please try again.