/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-27 18:35:29 UTC
  • Revision ID: josh@9ix.org-20130427183529-0lqp56qq6m0yocn1
levels hash, scale player

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
STRICT = true
 
2
DEBUG = true
 
3
 
 
4
require 'zoetrope'
 
5
 
 
6
--require 'sprite'
 
7
require 'version'
 
8
 
 
9
require 'player'
 
10
 
 
11
levels = {
 
12
   forest1 = {
 
13
      objects = function() return {
 
14
                      Tile:new{image = 'data/forest1-bg.png'},
 
15
                      Player:new{x = 200, y = 370, image = 'data/forest1-player.png'},
 
16
                      Tile:new{image = 'data/forest1-fg.png'}
 
17
                   } end,
 
18
   },
 
19
   shore = {
 
20
      objects = function() return {
 
21
                      Tile:new{image = 'data/shore-bg.png'},
 
22
                      Player:new{x = 145, y = 133, image = 'data/shore-player.png'},
 
23
                      Tile:new{image = 'data/shore-fg.png'}
 
24
                   } end
 
25
   }
 
26
}
 
27
 
 
28
GameView = View:extend {
 
29
   onNew = function (self)
 
30
              self:newLevel('forest1')
 
31
 
 
32
              --self:loadLayers('data/map.lua')
 
33
              --self.focus = the.player
 
34
              --self:clampTo(self.map)
 
35
           end,
 
36
   draw = function (self, x, y)
 
37
             View.draw(self, x, y)
 
38
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
 
39
             love.graphics.print('version:' .. VERSION, 20, 570)
 
40
          end,
 
41
   onUpdate = function (self, dt)
 
42
                 if the.keys:justPressed('a') then
 
43
                    self:newLevel('forest1')
 
44
                 elseif the.keys:justPressed('b') then
 
45
                    self:newLevel('shore')
 
46
                 end
 
47
              end,
 
48
   newLevel = function (self, level)
 
49
                 self.sprites = levels[level].objects()
 
50
              end
 
51
}
 
52
 
 
53
the.app = App:new {
 
54
   onRun = function (self)
 
55
              self.view = GameView:new()
 
56
              if DEBUG then
 
57
                 self.console:watch('VERSION', 'VERSION')
 
58
                 self.console:watch('updateTook', 'the.updateTook')
 
59
                 --self.console:watch('drawTook', 'the.drawTook')
 
60
              end
 
61
           end,
 
62
   onUpdate = function (self, dt)
 
63
                 if the.keys:justPressed('escape') then
 
64
                    self.quit()
 
65
                 end
 
66
              end,
 
67
   update = function (self, dt)
 
68
               the.updateStart = love.timer.getMicroTime()
 
69
               App.update(self, dt)
 
70
               if the.updateStart then
 
71
                  the.updateTook = love.timer.getMicroTime() - the.updateStart
 
72
               end
 
73
            end
 
74
}