/ld28

To get this branch, use:
bzr branch http://9ix.org/bzr/ld28

« back to all changes in this revision

Viewing changes to sprite.lua

  • Committer: Josh C
  • Date: 2013-12-14 05:13:09 UTC
  • Revision ID: josh@9ix.org-20131214051309-4gos06aw3r5amsyi
build system

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
function Sprite:displaceDir(other, dir, hint)
3
 
   if not self.solid or self == other or not other.solid then return end
4
 
   if STRICT then assert(other:instanceOf(Sprite), 'asked to displace a non-sprite') end
5
 
 
6
 
   if other.sprites then
7
 
      -- handle groups
8
 
 
9
 
      for _, spr in pairs(other.sprites) do
10
 
         self:displace(spr, dir)
11
 
      end
12
 
   else
13
 
      -- handle sprites
14
 
      local dim = util.dim(dir)
15
 
 
16
 
      local negMove = (other[dir] - self[dir]) + other[dim]
17
 
      local posMove = (self[dir] + self[dim]) - other[dir]
18
 
 
19
 
      if hint then
20
 
         if hint < 0 then
21
 
            chg = - negMove
22
 
         elseif hint > 0 then
23
 
            chg = posMove
24
 
         else
25
 
            error('hint should be 1, -1, or nil')
26
 
         end
27
 
      else
28
 
         if negMove < posMove then
29
 
            chg = - negMove
30
 
         else
31
 
            chg = posMove
32
 
         end
33
 
      end
34
 
   end
35
 
 
36
 
   other[dir] = other[dir] + chg
37
 
end