bzr branch
http://9ix.org/bzr/ld28
11
by Josh C
... add the map. and the extra code to work w/ it. |
1 |
-- monkey patches for zoetrope Sprite |
2 |
||
3 |
-- displace on a specific axis |
|
4 |
function Sprite:displaceDir(other, dir, hint) |
|
5 |
if not self.solid or self == other or not other.solid then return end |
|
6 |
if STRICT then assert(other:instanceOf(Sprite), 'asked to displace a non-sprite') end |
|
7 |
||
8 |
if other.sprites then |
|
9 |
-- handle groups |
|
10 |
||
11 |
for _, spr in pairs(other.sprites) do |
|
12 |
self:displace(spr, dir) |
|
13 |
end |
|
14 |
else |
|
15 |
-- handle sprites |
|
16 |
local dim = util.dim(dir) |
|
17 |
||
18 |
local negMove = (other[dir] - self[dir]) + other[dim] |
|
19 |
local posMove = (self[dir] + self[dim]) - other[dir] |
|
20 |
||
21 |
if hint then |
|
22 |
if hint < 0 then |
|
23 |
chg = - negMove |
|
24 |
elseif hint > 0 then |
|
25 |
chg = posMove |
|
26 |
else |
|
27 |
error('hint should be 1, -1, or nil') |
|
28 |
end |
|
29 |
else |
|
30 |
if negMove < posMove then |
|
31 |
chg = - negMove |
|
32 |
else |
|
33 |
chg = posMove |
|
34 |
end |
|
35 |
end |
|
36 |
end |
|
37 |
||
38 |
other[dir] = other[dir] + chg |
|
39 |
end |