/ld27

To get this branch, use:
bzr branch http://9ix.org/bzr/ld27
42 by Josh C
control by touch ("mouse")
1
STRICT = false
36 by Josh C
changes for love 0.9
2
DEBUG = false
39 by Josh C
propagate scaling / translate properly
3
4
if SDL then
5
  print = SDL.log
6
end
3 by Josh C
map loading, super basic movement
7
42 by Josh C
control by touch ("mouse")
8
--lovebird = require 'lovebird'
3 by Josh C
map loading, super basic movement
9
require 'zoetrope'
17 by Josh C
profiler stubs
10
--require 'pepperprof'
25 by Josh C
overhaul collision and physics to fix an annoying collision resolution
11
--inspect = require 'inspect'
12
13
require 'sprite'
14
require 'util'
3 by Josh C
map loading, super basic movement
15
16
require 'version'
17
require 'player'
8 by Josh C
goal... thing
18
require 'goal'
20 by Josh C
pause/quit screen
19
require 'pause_view'
22 by Josh C
win screen (no trigger)
20
require 'win_view'
3 by Josh C
map loading, super basic movement
21
22
GameView = View:extend {
23
   gameStart = 0,
29 by Josh C
play silly sound on level switch
24
   switchSounds = {},
3 by Josh C
map loading, super basic movement
25
   onNew = function (self)
26
              self:loadLayers('data/map.lua')
27
              self.focus = the.player
4 by Josh C
switch mazes
28
              self:clampTo(self.bg)
29
39 by Josh C
propagate scaling / translate properly
30
              the.app:setScaling(self)
38 by Josh C
scaling
31
9 by Josh C
3rd maze... reverse
32
              self.mazes = {self.maze1, self.maze2, self.maze3}
33
              self.bgs = {self.bg, self.bg, self.bg2}
34
              for _, maze in ipairs(self.mazes) do maze:die() end
35
              for _, bg in ipairs(self.bgs) do bg.visible = false end
36
37
              self.maze1.moveMod = 1
11 by Josh C
more map
38
              self.maze2.moveMod = 0.55
9 by Josh C
3rd maze... reverse
39
              self.maze3.moveMod = -1
10 by Josh C
slow level + tiny player
40
              self.maze1.playerScale = 1
41
              self.maze2.playerScale = 0.5
42
              self.maze3.playerScale = 1
3 by Josh C
map loading, super basic movement
43
32 by Josh C
actually handle multiple goals in one maze
44
              self.goals = {{},{},{}}
23 by Josh C
win screen activate!
45
              the.goalsAchieved = 0
14 by Josh C
1 goal in each maze
46
              for _, obj in ipairs(self.objects.sprites) do
47
                 if obj:instanceOf(Goal) then
48
                    obj.visible = false
32 by Josh C
actually handle multiple goals in one maze
49
                    table.insert(self.goals[tonumber(obj.map)], obj)
14 by Josh C
1 goal in each maze
50
                 end
51
              end
52
29 by Josh C
play silly sound on level switch
53
              local sndFiles = {'data/Explosion2.wav', 'data/Explosion3.wav', 'data/Hit_Hurt3.wav'}
54
55
              for _, sndFile in ipairs(sndFiles) do
56
                 local snd = love.audio.newSource(sndFile, 'static')
57
                 table.insert(self.switchSounds, snd)
58
              end
59
3 by Josh C
map loading, super basic movement
60
              --the.interface = Group:new()
61
62
              --self:add(the.interface)
63
5 by Josh C
fade in to let you know change is coming
64
              self:switchMaze()
65
17 by Josh C
profiler stubs
66
              -- profiling...
67
              --the.profiler = newProfiler()
68
              --the.profiler:start()
69
36 by Josh C
changes for love 0.9
70
              self.gameStart = love.timer.getTime()
71
              self.lastChange = love.timer.getTime()
3 by Josh C
map loading, super basic movement
72
           end,
73
   onUpdate = function(self, dt)
36 by Josh C
changes for love 0.9
74
                 if the.player.active and love.timer.getTime() > self.lastChange + 10 then
3 by Josh C
map loading, super basic movement
75
                    -- switch maze
5 by Josh C
fade in to let you know change is coming
76
                    self:switchMaze()
3 by Josh C
map loading, super basic movement
77
                 end
78
12 by Josh C
... more maze (and darker fade, and no collision during debug)
79
                 if not (DEBUG and the.console.visible) then
32 by Josh C
actually handle multiple goals in one maze
80
                    for _, goal in ipairs(the.activeGoals) do
81
                       the.player.collider:collide(goal)
82
                    end
12 by Josh C
... more maze (and darker fade, and no collision during debug)
83
                 end
4 by Josh C
switch mazes
84
20 by Josh C
pause/quit screen
85
                 if the.keys:justPressed('escape', 'q') then
86
                    PauseView:new():activate()
22 by Josh C
win screen (no trigger)
87
                 --elseif the.keys:justPressed('w') then
88
                 --   WinView:new():activate()
20 by Josh C
pause/quit screen
89
                 end
3 by Josh C
map loading, super basic movement
90
              end,
5 by Josh C
fade in to let you know change is coming
91
   switchMaze = function(self)
9 by Josh C
3rd maze... reverse
92
                   if the.activeMaze then
93
                      repeat
94
                         newMaze = math.random(3)
95
                      until self.mazes[newMaze] ~= the.activeMaze
96
97
                      the.activeMaze:die()
98
                      the.activeMaze = self.mazes[newMaze]
99
100
                      the.activeBg.visible = false
101
                      the.activeBg = self.bgs[newMaze]
14 by Josh C
1 goal in each maze
102
32 by Josh C
actually handle multiple goals in one maze
103
                      for _, goal in ipairs(the.activeGoals) do
104
                         goal.visible = false
15 by Josh C
pick up goals
105
                      end
32 by Josh C
actually handle multiple goals in one maze
106
                      the.activeGoals = self.goals[newMaze]
29 by Josh C
play silly sound on level switch
107
108
                      love.audio.play(self.switchSounds[math.random(#self.switchSounds)])
9 by Josh C
3rd maze... reverse
109
                   else
5 by Josh C
fade in to let you know change is coming
110
                      the.activeMaze = self.maze2
9 by Josh C
3rd maze... reverse
111
                      the.activeBg = self.bg
32 by Josh C
actually handle multiple goals in one maze
112
                      the.activeGoals = self.goals[2]
5 by Josh C
fade in to let you know change is coming
113
                   end
9 by Josh C
3rd maze... reverse
114
5 by Josh C
fade in to let you know change is coming
115
                   the.activeMaze:revive()
9 by Josh C
3rd maze... reverse
116
                   the.activeBg.visible = true
32 by Josh C
actually handle multiple goals in one maze
117
                   for _, goal in ipairs(the.activeGoals) do
118
                      goal.visible = true
15 by Josh C
pick up goals
119
                   end
10 by Josh C
slow level + tiny player
120
                   the.player.scale = the.activeMaze.playerScale
19 by Josh C
separate collision box for player so it can scale
121
                   the.player.collider.width = the.player.width * the.activeMaze.playerScale
122
                   the.player.collider.height = the.player.height * the.activeMaze.playerScale
5 by Josh C
fade in to let you know change is coming
123
6 by Josh C
how about fade to black instead?
124
                   self._fx = {0,0,0,0}
12 by Josh C
... more maze (and darker fade, and no collision during debug)
125
                   self.tween:start(self._fx, 4, 175, 10, 'quadIn')
5 by Josh C
fade in to let you know change is coming
126
36 by Josh C
changes for love 0.9
127
                   self.lastChange = love.timer.getTime()
5 by Josh C
fade in to let you know change is coming
128
                end,
3 by Josh C
map loading, super basic movement
129
   onEndFrame = function(self)
130
                   --the.interface.translate.x = the.player.x - the.app.width / 2 + the.player.width / 2
131
                   --the.interface.translate.y = the.player.y - the.app.height / 2 + the.player.height / 2
132
                end
133
}
134
135
MenuScreen = View:extend {
27 by Josh C
title screen
136
   bg = Tile:new{image = 'data/intro.png', x = 0, y = 0},
3 by Josh C
map loading, super basic movement
137
   onNew = function(self)
39 by Josh C
propagate scaling / translate properly
138
              the.app:setScaling(self)
38 by Josh C
scaling
139
27 by Josh C
title screen
140
              self:add(self.bg)
141
              --self.title:centerAround(400, 200)
142
143
              local nr = 'data/NewRocker-Regular.otf'
144
              self:add(Text:new{
33 by Josh C
name the game
145
                          text = 'Treasures of the Decimaze',
27 by Josh C
title screen
146
                          --x = 0,
147
                          y = 100,
148
                          width = self.bg.width,
149
                          font = {nr, 48},
150
                          align = 'center',
151
                          tint = {0,0,0}
152
                       })
153
154
              self:add(Text:new{
31 by Josh C
moved the shinies. added one more.
155
                          text = 'Find the 4 lost shinies!',
27 by Josh C
title screen
156
                          y = 170,
157
                          width = self.bg.width,
158
                          font = {nr, 28},
159
                          align = 'center',
160
                          tint = {0,0,0}
161
                       })
162
163
              self:add(Text:new{
164
                          text = 'Use the arrow keys to move',
165
                          y = 375,
166
                          width = self.bg.width,
167
                          font = {nr, 24},
168
                          align = 'center',
169
                          tint = {0,0,0}
170
                       })
171
172
              self:add(Text:new{
173
                          text = 'Press a key to start',
174
                          y = 425,
175
                          width = self.bg.width,
176
                          font = {nr, 24},
177
                          align = 'center',
178
                          tint = {0,0,0}
179
                       })
180
181
3 by Josh C
map loading, super basic movement
182
           end,
183
   onUpdate = function(self, elapsed)
42 by Josh C
control by touch ("mouse")
184
     if the.keys:allJustPressed() or the.mouse:pressed() then
185
       the.app.view = GameView:new()
186
     end
187
   end
3 by Josh C
map loading, super basic movement
188
}
189
190
the.app = App:new {
38 by Josh C
scaling
191
   width = 800,
192
   height = 600,
33 by Josh C
name the game
193
   name = "Treasures of the Decimaze",
3 by Josh C
map loading, super basic movement
194
   onRun = function (self)
195
              print('Version: ' .. VERSION)
196
27 by Josh C
title screen
197
              self.view = MenuScreen:new()
38 by Josh C
scaling
198
              self:setScaling()
3 by Josh C
map loading, super basic movement
199
200
              if DEBUG then
201
                 self.console:watch('VERSION', 'VERSION')
25 by Josh C
overhaul collision and physics to fix an annoying collision resolution
202
                 self.console:watch('player.x', 'the.player.x')
203
                 self.console:watch('player.y', 'the.player.y')
3 by Josh C
map loading, super basic movement
204
205
                 -- back off that dark overlay a bit
206
                 self.console.fill.fill[4] = 75
207
              end
208
           end,
209
   onUpdate = function (self, dt)
34 by Josh C
leftover screenshot functionality I never checked in
210
                 if the.keys:justPressed('f1') then
211
                    local ss = love.graphics.newScreenshot()
212
                    ss:encode('screenshot-' ..love.timer.getTime()..'.png')
213
                 end
38 by Josh C
scaling
214
              end,
39 by Josh C
propagate scaling / translate properly
215
   update = function(self, dt)
42 by Josh C
control by touch ("mouse")
216
     if lovebird then
217
       fps = love.timer.getFPS()
218
       lovebird.update()
39 by Josh C
propagate scaling / translate properly
219
     end
220
     App.update(self, dt)
221
   end,
222
   setScaling = function(self, view)
223
     local view = view or the.app.view
224
38 by Josh C
scaling
225
     local winw, winh = love.window.getMode()
226
     --if love.window.getFullscreen() then
227
     if winw == self.width and winh == self.height then
228
       self.scale = 1
39 by Josh C
propagate scaling / translate properly
229
       view.realTranslate = { x=0, y=0 }
38 by Josh C
scaling
230
       love.graphics.setScissor()
231
     else
232
       --self.scale = math.min(
233
       --  math.floor(winw / the.app.viewWidth),
234
       --  math.floor(winh / the.app.viewHeight)
235
       --)
236
       if winh >= 1050 then
237
         self.scale = 1.5
238
       elseif winh < the.app.height then
239
         self.scale = winh / the.app.height
240
       end
39 by Josh C
propagate scaling / translate properly
241
       view.realTranslate.x = math.floor((winw - self.width * self.scale) / 2)
242
       view.realTranslate.y = math.floor((winh - self.height * self.scale) / 2)
243
       --print('translate: ' .. view.realTranslate.x .. ', ' .. view.realTranslate.y)
38 by Josh C
scaling
244
245
       love.graphics.setColor(0,0,0)
246
       love.graphics.rectangle('fill', 0, 0, winw, winh)
39 by Josh C
propagate scaling / translate properly
247
       love.graphics.setScissor( view.realTranslate.x,
248
                                 view.realTranslate.y,
38 by Josh C
scaling
249
                                 self.width * self.scale,
250
                                 self.height * self.scale)
251
     end
252
39 by Josh C
propagate scaling / translate properly
253
     view.scale = self.scale
38 by Josh C
scaling
254
   end
3 by Josh C
map loading, super basic movement
255
}
38 by Josh C
scaling
256
257
function love.resize(w, h)
258
  print('love.resize')
259
  the.app:setScaling()
260
end