/
turret.lua
57 lines (45 loc) · 1.33 KB
/
turret.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-------------------------------------------------------------------------
-- [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
local own = e.owner
self.facing = own.facing
self.shooting = own.shooting
self.shot_rate = own.shot_rate/.66 -- thats 2/3 the firing rate
local theta, d = self.hardpoint, 16
self.pos_x = own.pos_x + math.cos(theta) * d
self.pos_y = own.pos_y + math.sin(theta) * d
else
self.shooting = true
end
end
function _M:draw(...)
local own = self.owner
if own then
love.graphics.setColor(0,0,127)
love.graphics.line(self.pos_x, self.pos_y, own.pos_x, own.pos_y)
ship.draw(self, ...)
end
end
function _M:docollision()
end
-------------------------------------------------------------------------
if _VERSION == "Lua 5.1" then _G[_M._NAME] = _M end
return _M