/ld26

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

« back to all changes in this revision

Viewing changes to main.lua

  • Committer: Josh C
  • Date: 2013-04-28 22:23:30 UTC
  • Revision ID: josh@9ix.org-20130428222330-ng2gzvphijabfjfm
flag

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
require 'player'
10
10
require 'transition'
11
11
require 'displacer'
 
12
require 'inventory'
 
13
require 'levels'
 
14
require 'items'
 
15
require 'troll'
 
16
 
12
17
require 'svg_levels'
13
18
 
14
 
levels = {
15
 
   forest1 = {
16
 
      objects = function() return {
17
 
                      Tile:new{image = 'data/forest1-bg.png'},
18
 
                      Player:new{x = 200, y = 380,
19
 
                                 minY = 330, maxY = 500,
20
 
                                 image = 'data/forest1-player.png'},
21
 
                      Tile:new{image = 'data/forest1-fg.png'}
22
 
                   } end,
23
 
   },
24
 
   shore = {
25
 
      objects = function() return {
26
 
                      Tile:new{image = 'data/shore-bg.png'},
27
 
                      Player:new{x = 145, y = 133,
28
 
                                 minY = 133, maxY = 133,
29
 
                                 image = 'data/shore-player.png'},
30
 
                      Tile:new{image = 'data/shore-fg.png'},
31
 
                      Transition:new{x = 10, y = 133, target = 'forest1',
32
 
                                     targetX = 735, targetY = 370}
33
 
                   } end
34
 
   }
35
 
}
36
 
 
37
19
GameView = View:extend {
38
 
   level = 'forest1', --default level
39
20
   onNew = function (self)
40
21
              --print('loading level: '..self.level)
 
22
              if not levels[self.level] then
 
23
                 error('no such level: '..self.level)
 
24
              end
41
25
              for _, obj in ipairs(levels[self.level].objects()) do
42
26
                 self:add(obj)
43
27
              end
44
28
              for _, obj in ipairs(svg_objects[self.level]) do
45
 
                 self:add(obj)
 
29
                 if not the.inventory.items[obj.name] then
 
30
                    self:add(obj)
 
31
                 end
46
32
              end
47
33
 
 
34
              self:add(the.inventory)
 
35
 
48
36
              self:flash({0,0,0})
49
37
 
50
38
              --self.focus = the.player
52
40
           end,
53
41
   draw = function (self, x, y)
54
42
             View.draw(self, x, y)
55
 
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
56
 
             love.graphics.print('version:' .. VERSION, 20, 570)
 
43
             --love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
 
44
             --love.graphics.print('version:' .. VERSION, 20, 570)
57
45
          end,
58
46
   onUpdate = function (self, dt)
59
 
                 if the.keys:justPressed('a') then
60
 
                    the.app.view = GameView:new{level = 'forest1'}
61
 
                 elseif the.keys:justPressed('b') then
62
 
                    the.app.view = GameView:new{level = 'shore'}
63
 
                 end
64
47
              end
65
48
}
66
49
 
67
50
the.app = App:new {
 
51
   level = 'shore', --default level
68
52
   onRun = function (self)
69
 
              self.view = GameView:new()
 
53
              print('Version: ' .. VERSION)
 
54
              self.view = GameView:new{level = self.level}
70
55
              if DEBUG then
71
56
                 self.console:watch('VERSION', 'VERSION')
72
57
                 self.console:watch('updateTook', 'the.updateTook')
77
62
                 -- back off that dark overlay a bit
78
63
                 self.console.fill.fill[4] = 75
79
64
              end
 
65
 
 
66
              the.inventory:add(Flower:new())
80
67
           end,
81
68
   onUpdate = function (self, dt)
82
69
                 if the.keys:justPressed('escape') then
91
78
               end
92
79
            end
93
80
}
 
81
 
 
82
-- for accessing from debug console
 
83
function l(level)
 
84
   the.app.view = GameView:new{level = level}
 
85
end
 
86
 
 
87
function love.load(arg)
 
88
   if arg[2] then
 
89
      the.app.level = arg[2]
 
90
   end
 
91
 
 
92
   the.app:run()
 
93
end
 
 
b'\\ No newline at end of file'