/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
39 by Josh C
title screen
58
MenuScreen = View:extend {
59
   --title = Text:new{text = "Test Platform Game", font = 48, wordWrap = false},
60
   title = Tile:new{image = 'data/title.png', x = 0, y = 0},
61
   onNew = function(self)
62
              self:add(self.title)
63
              --self.title:centerAround(400, 200)
64
           end,
65
   onUpdate = function(self, elapsed)
66
                 if the.keys:allJustPressed() then
67
                    the.app.view = GameView:new()
68
                 end
69
              end
70
}
71
2 by Josh C
basic tiles, map, player, movement
72
the.app = App:new {
31 by Josh C
command line option for playback/record
73
   record = true,
2 by Josh C
basic tiles, map, player, movement
74
   onRun = function (self)
39 by Josh C
title screen
75
              self.view = MenuScreen:new()
35 by Josh C
actually make separate player/sprite work. clean up some code that
76
              if DEBUG then
77
                 self.console:watch('onGround', 'the.player.onGround')
78
                 self.console:watch('onWall', 'the.player.onWall')
79
                 self.console:watch('updateTook', 'the.updateTook')
80
                 self.console:watch('drawTook', 'the.drawTook')
81
                 self.console:watch('recorder state', 'the.recorder.state')
82
              end
24 by Josh C
profiling and analysis
83
84
              --the.profiler = newProfiler('time', 2000)
85
              --the.profiler = newProfiler()
86
              --the.profiler:start()
2 by Josh C
basic tiles, map, player, movement
87
           end,
88
   onUpdate = function (self, dt)
24 by Josh C
profiling and analysis
89
                 if the.keys:justPressed('escape') then
90
                    if the.profiler then
91
                       the.profiler:stop()
92
                       local outfile = io.open( "profile.txt", "w+" )
93
                       the.profiler:report( outfile )
94
                       outfile:close()
95
                    end
96
39 by Josh C
title screen
97
                    if self.record and the.recorder then
29 by Josh C
record/playback system (doesn't really work)
98
                       if not love.filesystem.remove('record.lua') then
31 by Josh C
command line option for playback/record
99
                          print('could not remove record.lua')
29 by Josh C
record/playback system (doesn't really work)
100
                       end
101
                       local storage = Storage:new{
102
                          data = the.recorder.record,
103
                          filename = 'record.lua'
104
                       }
105
                       storage:save(false)
106
                       --print(inspect(the.recorder.record))
107
                    end
108
17 by Josh C
reorganize code - separate X and Y physics so we can collide in each
109
                    self.quit()
12 by Josh C
only jump when you're on the ground
110
                 end
24 by Josh C
profiling and analysis
111
              end,
112
   update = function (self, dt)
113
               the.updateStart = love.timer.getMicroTime()
114
               App.update(self, dt)
115
               if the.updateStart then
116
                  the.updateTook = love.timer.getMicroTime() - the.updateStart
117
               end
118
            end
119
}
31 by Josh C
command line option for playback/record
120
121
function love.load (arg)
122
   opts = getopt(arg, '')
123
   if opts['p'] then
124
      the.app.playback = true
125
      the.app.record = false
126
   elseif opts['r'] then
127
      the.app.record = true
128
   end
129
130
   the.app:run()
131
end