/ld28

To get this branch, use:
bzr branch /bzr/ld28
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
-- monkey patches for zoetrope Sprite

-- displace on a specific axis
function Sprite:displaceDir(other, dir, hint)
   if not self.solid or self == other or not other.solid then return end
   if STRICT then assert(other:instanceOf(Sprite), 'asked to displace a non-sprite') end

   if other.sprites then
      -- handle groups

      for _, spr in pairs(other.sprites) do
         self:displace(spr, dir)
      end
   else
      -- handle sprites
      local dim = util.dim(dir)

      local negMove = (other[dir] - self[dir]) + other[dim]
      local posMove = (self[dir] + self[dim]) - other[dir]

      if hint then
         if hint < 0 then
            chg = - negMove
         elseif hint > 0 then
            chg = posMove
         else
            error('hint should be 1, -1, or nil')
         end
      else
         if negMove < posMove then
            chg = - negMove
         else
            chg = posMove
         end
      end
   end

   other[dir] = other[dir] + chg
end