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
|
Player = Tile:extend {
image = 'data/player.png',
queue = deque.new(),
onNew = function(self)
local delay = {0,1,2}
for _ = 1, delay[the.view.level] do
self.queue:push_right(dirs[math.random(1,4)])
end
end,
onUpdate = function(self)
local keys = {the.keys:allJustPressed()}
if keys[1] then
local dirKey = false
for _, dir in ipairs(dirs) do
if dir == keys[1] then
dirKey = true
end
end
if dirKey then
--print('key: ' .. keys[1])
self.queue:push_right(keys[1])
self.direction = self.queue:pop_left()
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
self.moved = true
end
end
end,
onCollide = function(self, other)
if other ~= the.view.map and other ~= the.goalPerson then
--print('collision')
other:displaceDir(self,
util.dirToXY(self.direction),
- util.dirToPosNeg(self.direction))
end
end
}
|