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