1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
STRICT = true
DEBUG = true
require 'zoetrope'
__ = require 'underscore'
--inspect = require 'inspect'
require 'pepperprof'
require 'getopt_alt'
require 'sprite'
require 'animation'
require 'player'
require 'balloon'
util = {
dim = function(dir)
if dir == 'x' then
return 'width'
elseif dir == 'y' then
return 'height'
else
if STRICT then error('dir '..dir) end
end
end
}
GameView = View:extend {
onNew = function (self)
self:loadLayers('data/map.lua')
self.focus = the.player
self:clampTo(self.map)
the.recorder = Recorder:new{mousePosInterval = 9999}
the.app.meta:add(the.recorder)
if the.app.record then
the.recorder:startRecording()
elseif the.app.playback then
local storage = Storage:new{filename = 'record.lua'}
storage:load()
--print(inspect(storage.data))
the.recorder.record = storage.data
the.recorder:startPlaying()
end
end,
onUpdate = function (self)
--print('drawTook: ', the.drawTook)
--print('tick')
--the.player:collide(self.map)
--self.map:collide(the.player)
end,
-- draw = function (self, x, y)
-- View.draw(self, x, y)
-- love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
-- end
}
MenuScreen = View:extend {
--title = Text:new{text = "Test Platform Game", font = 48, wordWrap = false},
title = Tile:new{image = 'data/title.png', x = 0, y = 0},
onNew = function(self)
self:add(self.title)
--self.title:centerAround(400, 200)
end,
onUpdate = function(self, elapsed)
if the.keys:allJustPressed() then
the.app.view = GameView:new()
end
end
}
the.app = App:new {
record = true,
onRun = function (self)
self.view = MenuScreen:new()
if DEBUG then
self.console:watch('onGround', 'the.player.onGround')
self.console:watch('onWall', 'the.player.onWall')
self.console:watch('updateTook', 'the.updateTook')
self.console:watch('drawTook', 'the.drawTook')
self.console:watch('recorder state', 'the.recorder.state')
end
--the.profiler = newProfiler('time', 2000)
--the.profiler = newProfiler()
--the.profiler:start()
end,
onUpdate = function (self, dt)
if the.keys:justPressed('escape') then
if the.profiler then
the.profiler:stop()
local outfile = io.open( "profile.txt", "w+" )
the.profiler:report( outfile )
outfile:close()
end
if self.record and the.recorder then
if not love.filesystem.remove('record.lua') then
print('could not remove record.lua')
end
local storage = Storage:new{
data = the.recorder.record,
filename = 'record.lua'
}
storage:save(false)
--print(inspect(the.recorder.record))
end
self.quit()
end
end,
update = function (self, dt)
the.updateStart = love.timer.getMicroTime()
App.update(self, dt)
if the.updateStart then
the.updateTook = love.timer.getMicroTime() - the.updateStart
end
end
}
function love.load (arg)
opts = getopt(arg, '')
if opts['p'] then
the.app.playback = true
the.app.record = false
elseif opts['r'] then
the.app.record = true
end
the.app:run()
end
|