/zoeplat

To get this branch, use:
bzr branch http://9ix.org/bzr/zoeplat
2 by Josh C
basic tiles, map, player, movement
1
STRICT = true
37 by Josh C
text balloon system
2
DEBUG = true
2 by Josh C
basic tiles, map, player, movement
3
4
require 'zoetrope'
20 by Josh C
fairly major overhaul of collision handling to track whether we're on a
5
__ = require 'underscore'
12 by Josh C
only jump when you're on the ground
6
--inspect = require 'inspect'
24 by Josh C
profiling and analysis
7
require 'pepperprof'
31 by Josh C
command line option for playback/record
8
require 'getopt_alt'
2 by Josh C
basic tiles, map, player, movement
9
35 by Josh C
actually make separate player/sprite work. clean up some code that
10
require 'sprite'
37 by Josh C
text balloon system
11
require 'animation'
35 by Josh C
actually make separate player/sprite work. clean up some code that
12
require 'player'
37 by Josh C
text balloon system
13
require 'balloon'
35 by Josh C
actually make separate player/sprite work. clean up some code that
14
26 by Josh C
don't go off the edge
15
util = {
16
   dim = function(dir)
17
      if dir == 'x' then
18
         return 'width'
19
      elseif dir == 'y' then
20
         return 'height'
21
      else
29 by Josh C
record/playback system (doesn't really work)
22
         if STRICT then error('dir '..dir) end
26 by Josh C
don't go off the edge
23
      end
24
   end
25
}
26
2 by Josh C
basic tiles, map, player, movement
27
GameView = View:extend {
28
   onNew = function (self)
29
              self:loadLayers('data/map.lua')
30
              self.focus = the.player
31
              self:clampTo(self.map)
29 by Josh C
record/playback system (doesn't really work)
32
33
              the.recorder = Recorder:new{mousePosInterval = 9999}
34
              the.app.meta:add(the.recorder)
31 by Josh C
command line option for playback/record
35
              if the.app.record then
29 by Josh C
record/playback system (doesn't really work)
36
                 the.recorder:startRecording()
31 by Josh C
command line option for playback/record
37
              elseif the.app.playback then
29 by Josh C
record/playback system (doesn't really work)
38
                 local storage = Storage:new{filename = 'record.lua'}
39
                 storage:load()
40
                 --print(inspect(storage.data))
41
                 the.recorder.record = storage.data
42
                 the.recorder:startPlaying()
43
              end
8 by Josh C
some basic collision (and workarounds)
44
           end,
45
   onUpdate = function (self)
27 by Josh C
hack to not fall through floor on long first tick, monkey patch to turn
46
                 --print('drawTook: ', the.drawTook)
8 by Josh C
some basic collision (and workarounds)
47
                 --print('tick')
17 by Josh C
reorganize code - separate X and Y physics so we can collide in each
48
                 --the.player:collide(self.map)
8 by Josh C
some basic collision (and workarounds)
49
                 --self.map:collide(the.player)
28 by Josh C
fps indicator, maybe a new tile
50
              end,
29 by Josh C
record/playback system (doesn't really work)
51
   -- draw = function (self, x, y)
52
   --           View.draw(self, x, y)
28 by Josh C
fps indicator, maybe a new tile
53
29 by Josh C
record/playback system (doesn't really work)
54
   --           love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
55
   --        end
2 by Josh C
basic tiles, map, player, movement
56
}
57
58
the.app = App:new {
31 by Josh C
command line option for playback/record
59
   record = true,
2 by Josh C
basic tiles, map, player, movement
60
   onRun = function (self)
61
              self.view = GameView:new()
35 by Josh C
actually make separate player/sprite work. clean up some code that
62
              if DEBUG then
63
                 self.console:watch('onGround', 'the.player.onGround')
64
                 self.console:watch('onWall', 'the.player.onWall')
65
                 self.console:watch('updateTook', 'the.updateTook')
66
                 self.console:watch('drawTook', 'the.drawTook')
67
                 self.console:watch('recorder state', 'the.recorder.state')
68
              end
24 by Josh C
profiling and analysis
69
70
              --the.profiler = newProfiler('time', 2000)
71
              --the.profiler = newProfiler()
72
              --the.profiler:start()
2 by Josh C
basic tiles, map, player, movement
73
           end,
74
   onUpdate = function (self, dt)
24 by Josh C
profiling and analysis
75
                 if the.keys:justPressed('escape') then
76
                    if the.profiler then
77
                       the.profiler:stop()
78
                       local outfile = io.open( "profile.txt", "w+" )
79
                       the.profiler:report( outfile )
80
                       outfile:close()
81
                    end
82
31 by Josh C
command line option for playback/record
83
                    if self.record then
29 by Josh C
record/playback system (doesn't really work)
84
                       if not love.filesystem.remove('record.lua') then
31 by Josh C
command line option for playback/record
85
                          print('could not remove record.lua')
29 by Josh C
record/playback system (doesn't really work)
86
                       end
87
                       local storage = Storage:new{
88
                          data = the.recorder.record,
89
                          filename = 'record.lua'
90
                       }
91
                       storage:save(false)
92
                       --print(inspect(the.recorder.record))
93
                    end
94
17 by Josh C
reorganize code - separate X and Y physics so we can collide in each
95
                    self.quit()
12 by Josh C
only jump when you're on the ground
96
                 end
24 by Josh C
profiling and analysis
97
              end,
98
   update = function (self, dt)
99
               the.updateStart = love.timer.getMicroTime()
100
               App.update(self, dt)
101
               if the.updateStart then
102
                  the.updateTook = love.timer.getMicroTime() - the.updateStart
103
               end
104
            end
105
}
31 by Josh C
command line option for playback/record
106
107
function love.load (arg)
108
   opts = getopt(arg, '')
109
   if opts['p'] then
110
      the.app.playback = true
111
      the.app.record = false
112
   elseif opts['r'] then
113
      the.app.record = true
114
   end
115
116
   the.app:run()
117
end