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
|
local dirs = {'left', 'right', 'up', 'down'}
Clone = Fill:extend {
fill = {255,0,0},
width = 16, height = 16,
queue = deque.new(),
onNew = function(self)
self.direction = dirs[math.random(1,4)]
end,
doMove = function(self)
if math.random(1,4) == 1 then -- change direction ~25%
self.direction = dirs[math.random(1,4)]
end
if self.direction == 'left' then
self.x = self.x - self.width
elseif self.direction == 'right' then
self.x = self.x + self.width
elseif self.direction == 'up' then
self.y = self.y - self.height
elseif self.direction == 'down' then
self.y = self.y + self.height
end
end,
onCollide = function(self, other)
if other ~= the.view.map then
--print('collision')
other:displaceDir(self,
util.dirToXY(self.direction),
- util.dirToPosNeg(self.direction))
end
end
}
|