bzr branch
http://9ix.org/bzr/ld28
2
by Josh C
basic delayed movement |
1 |
Player = Fill:extend { |
2 |
fill = {255,0,0}, |
|
3 |
width = 16, height = 16, |
|
4 |
queue = deque.new(), |
|
5 |
onNew = function(self) |
|
16
by Josh C
moving goal, clones turning green... |
6 |
for _ = 1, math.random(1,3) do |
4
by Josh C
more clones, no null movement |
7 |
self.queue:push_right(dirs[math.random(1,4)]) |
2
by Josh C
basic delayed movement |
8 |
end |
9 |
end, |
|
3
by Josh C
add a couple other clones that move randomly |
10 |
onUpdate = function(self) |
11 |
local keys = {the.keys:allJustPressed()} |
|
12 |
if keys[1] then |
|
4
by Josh C
more clones, no null movement |
13 |
local dirKey = false |
14 |
for _, dir in ipairs(dirs) do |
|
15 |
if dir == keys[1] then |
|
16 |
dirKey = true |
|
17 |
end |
|
18 |
end |
|
19 |
||
20 |
if dirKey then |
|
21 |
--print('key: ' .. keys[1]) |
|
22 |
self.queue:push_right(keys[1]) |
|
23 |
||
12
by Josh C
player collide w/ map |
24 |
self.direction = self.queue:pop_left() |
25 |
if self.direction == 'left' then |
|
4
by Josh C
more clones, no null movement |
26 |
self.x = self.x - self.width |
12
by Josh C
player collide w/ map |
27 |
elseif self.direction == 'right' then |
4
by Josh C
more clones, no null movement |
28 |
self.x = self.x + self.width |
12
by Josh C
player collide w/ map |
29 |
elseif self.direction == 'up' then |
4
by Josh C
more clones, no null movement |
30 |
self.y = self.y - self.height |
12
by Josh C
player collide w/ map |
31 |
elseif self.direction == 'down' then |
4
by Josh C
more clones, no null movement |
32 |
self.y = self.y + self.height |
33 |
end |
|
34 |
||
35 |
self.moved = true |
|
36 |
end |
|
3
by Josh C
add a couple other clones that move randomly |
37 |
end |
12
by Josh C
player collide w/ map |
38 |
end, |
39 |
onCollide = function(self, other) |
|
40 |
if other ~= the.view.map then |
|
41 |
--print('collision') |
|
42 |
||
43 |
other:displaceDir(self, |
|
44 |
util.dirToXY(self.direction), |
|
45 |
- util.dirToPosNeg(self.direction)) |
|
46 |
end |
|
47 |
end |
|
2
by Josh C
basic delayed movement |
48 |
} |