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