/ld27

To get this branch, use:
bzr branch http://9ix.org/bzr/ld27

« back to all changes in this revision

Viewing changes to main.lua

  • Committer: Josh C
  • Date: 2014-07-03 15:28:23 UTC
  • Revision ID: josh@9ix.org-20140703152823-4241je58pflhx7ec
scaling

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
STRICT = false
 
1
STRICT = true
2
2
DEBUG = false
3
3
 
4
 
if SDL then
5
 
  print = SDL.log
6
 
end
7
 
 
8
 
--lovebird = require 'lovebird'
9
4
require 'zoetrope'
10
5
--require 'pepperprof'
11
6
--inspect = require 'inspect'
27
22
              self.focus = the.player
28
23
              self:clampTo(self.bg)
29
24
 
30
 
              the.app:setScaling(self)
 
25
              self.scale = the.app.scale
31
26
 
32
27
              self.mazes = {self.maze1, self.maze2, self.maze3}
33
28
              self.bgs = {self.bg, self.bg, self.bg2}
135
130
MenuScreen = View:extend {
136
131
   bg = Tile:new{image = 'data/intro.png', x = 0, y = 0},
137
132
   onNew = function(self)
138
 
              the.app:setScaling(self)
 
133
              self.scale = the.app.scale
139
134
 
140
135
              self:add(self.bg)
141
136
              --self.title:centerAround(400, 200)
181
176
 
182
177
           end,
183
178
   onUpdate = function(self, elapsed)
184
 
     if the.keys:allJustPressed() or the.mouse:pressed() then
185
 
       the.app.view = GameView:new()
186
 
     end
187
 
   end
 
179
                 if the.keys:allJustPressed() then
 
180
                    the.app.view = GameView:new()
 
181
                 end
 
182
              end
188
183
}
189
184
 
190
185
the.app = App:new {
212
207
                    ss:encode('screenshot-' ..love.timer.getTime()..'.png')
213
208
                 end
214
209
              end,
215
 
   update = function(self, dt)
216
 
     if lovebird then
217
 
       fps = love.timer.getFPS()
218
 
       lovebird.update()
219
 
     end
220
 
     App.update(self, dt)
221
 
   end,
222
 
   setScaling = function(self, view)
223
 
     local view = view or the.app.view
224
 
 
 
210
   setScaling = function(self)
225
211
     local winw, winh = love.window.getMode()
226
212
     --if love.window.getFullscreen() then
227
213
     if winw == self.width and winh == self.height then
228
214
       self.scale = 1
229
 
       view.realTranslate = { x=0, y=0 }
 
215
       self.view.realTranslate = { x=0, y=0 }
230
216
       love.graphics.setScissor()
231
217
     else
232
218
       --self.scale = math.min(
238
224
       elseif winh < the.app.height then
239
225
         self.scale = winh / the.app.height
240
226
       end
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)
 
227
       self.view.realTranslate.x = math.floor((winw - self.width * self.scale) / 2)
 
228
       self.view.realTranslate.y = math.floor((winh - self.height * self.scale) / 2)
 
229
       --print('translate: ' .. self.view.realTranslate.x .. ', ' .. self.view.realTranslate.y)
244
230
 
245
231
       love.graphics.setColor(0,0,0)
246
232
       love.graphics.rectangle('fill', 0, 0, winw, winh)
247
 
       love.graphics.setScissor( view.realTranslate.x,
248
 
                                 view.realTranslate.y,
 
233
       love.graphics.setScissor( self.view.realTranslate.x,
 
234
                                 self.view.realTranslate.y,
249
235
                                 self.width * self.scale,
250
236
                                 self.height * self.scale)
251
237
     end
252
238
 
253
 
     view.scale = self.scale
 
239
     self.view.scale = self.scale
254
240
   end
255
241
}
256
242