/ld26

To get this branch, use:
bzr branch http://9ix.org/bzr/ld26
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
Inventory = Class:extend {
   items = {},
   had = {},
   visible = true,
   nitems = 0,
   add = function(self, item)
            self.items[item.name] = item
            the.app.view:flash({0,255,0})

            item.invTile.y = 10
            item.invTile.x = 50 * self.nitems

            self.nitems = self.nitems + 1
         end,
   remove = function(self, name)
               self.had[name] = self.items[name]
               self.items[name] = nil
               self.nitems = self.nitems - 1

               local newindex = 0
               for _, item in pairs(self.items) do
                  item.invTile.x = 50 * newindex
                  newindex = newindex + 1
               end
            end,
   draw = function(self)
             for _, item in pairs(self.items) do
                item.invTile:draw()
             end
          end
}

the.inventory = Inventory:new()