-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzombiegrid.lua
executable file
·53 lines (46 loc) · 1.43 KB
/
zombiegrid.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
local class = require "middleclass.middleclass"
local Zgrid = require "zgrid"
local ZombieGrid = class("ZombieGrid", Zgrid)
local global = require "global"
local Collidable = require "collidable"
function ZombieGrid:initialize(w, h, cellsize)
Zgrid.initialize(self, w, h, cellsize)
end
function ZombieGrid:compute()
self:reset()
for e, _ in pairs(global.entities) do
if e:isInstanceOf(Collidable) then
if e.w and e.h then
self:putRegion(
function (i, j)
self.pre_weights[i][j] = e:brains()
self.resistances[i][j] = e:zombieResistance()
end,
e.x, e.y, e.w, e.h
)
else
local x, y = e:center()
self:put(
function (i, j)
self.pre_weights[i][j] = e:brains()
self.resistances[i][j] = e:zombieResistance()
end,
x, y
)
end
end
end
Zgrid.compute(self)
end
function ZombieGrid:gradientAt(x, y)
local dx, dy = Zgrid.gradientAt(self, x, y)
local function isnan(x)
return x ~= x
end
if (dx == 0 and dy == 0) or isnan(dx) or isnan(dy) then
dx = love.graphics.getWidth()/2 - x
dy = love.graphics.getHeight()/2 - y
end
return dx, dy
end
return ZombieGrid