/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: 2013-08-25 02:38:46 UTC
  • Revision ID: josh@9ix.org-20130825023846-wgea9oh4n0o16gct
separate collision box for player so it can scale

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
STRICT = true
 
2
DEBUG = true
 
3
 
 
4
require 'zoetrope'
 
5
--require 'pepperprof'
 
6
 
 
7
--require 'group'
 
8
 
 
9
require 'version'
 
10
--require 'wrap_tile'
 
11
require 'player'
 
12
require 'goal'
 
13
 
 
14
GameView = View:extend {
 
15
   gameStart = 0,
 
16
   onNew = function (self)
 
17
              self:loadLayers('data/map.lua')
 
18
              self.focus = the.player
 
19
              self:clampTo(self.bg)
 
20
 
 
21
              self.mazes = {self.maze1, self.maze2, self.maze3}
 
22
              self.bgs = {self.bg, self.bg, self.bg2}
 
23
              for _, maze in ipairs(self.mazes) do maze:die() end
 
24
              for _, bg in ipairs(self.bgs) do bg.visible = false end
 
25
 
 
26
              self.maze1.moveMod = 1
 
27
              self.maze2.moveMod = 0.55
 
28
              self.maze3.moveMod = -1
 
29
              self.maze1.playerScale = 1
 
30
              self.maze2.playerScale = 0.5
 
31
              self.maze3.playerScale = 1
 
32
 
 
33
              self.goals = {}
 
34
              for _, obj in ipairs(self.objects.sprites) do
 
35
                 if obj:instanceOf(Goal) then
 
36
                    obj.visible = false
 
37
                    self.goals[tonumber(obj.map)] = obj
 
38
                 end
 
39
              end
 
40
 
 
41
              --the.interface = Group:new()
 
42
 
 
43
              --self:add(the.interface)
 
44
 
 
45
              self:switchMaze()
 
46
 
 
47
              -- profiling...
 
48
              --the.profiler = newProfiler()
 
49
              --the.profiler:start()
 
50
 
 
51
              self.gameStart = love.timer.getMicroTime()
 
52
              self.lastChange = love.timer.getMicroTime()
 
53
           end,
 
54
   onUpdate = function(self, dt)
 
55
                 if the.player.active and love.timer.getMicroTime() > self.lastChange + 10 then
 
56
                    -- switch maze
 
57
                    self:switchMaze()
 
58
                 end
 
59
 
 
60
                 if not (DEBUG and the.console.visible) then
 
61
                    the.activeMaze:collide(the.player.collider)
 
62
                    the.player.collider:collide(the.activeGoal)
 
63
                 end
 
64
 
 
65
                 -- for _, mirror in ipairs(the.mirrors.sprites) do
 
66
                 --    if not mirror.of then
 
67
                 --       print('mirror:' .. inspect(mirror))
 
68
                 --       error('mirror OF NOTHING')
 
69
                 --    end
 
70
                 -- end
 
71
              end,
 
72
   switchMaze = function(self)
 
73
                   if the.activeMaze then
 
74
                      repeat
 
75
                         newMaze = math.random(3)
 
76
                      until self.mazes[newMaze] ~= the.activeMaze
 
77
 
 
78
                      the.activeMaze:die()
 
79
                      the.activeMaze = self.mazes[newMaze]
 
80
 
 
81
                      the.activeBg.visible = false
 
82
                      the.activeBg = self.bgs[newMaze]
 
83
 
 
84
                      if the.activeGoal then
 
85
                         the.activeGoal.visible = false
 
86
                      end
 
87
                      the.activeGoal = self.goals[newMaze]
 
88
                   else
 
89
                      the.activeMaze = self.maze2
 
90
                      the.activeBg = self.bg
 
91
                      the.activeGoal = self.goals[2]
 
92
                   end
 
93
 
 
94
                   the.activeMaze:revive()
 
95
                   the.activeBg.visible = true
 
96
                   if the.activeGoal then
 
97
                      the.activeGoal.visible = true
 
98
                   end
 
99
                   the.player.scale = the.activeMaze.playerScale
 
100
                   the.player.collider.width = the.player.width * the.activeMaze.playerScale
 
101
                   the.player.collider.height = the.player.height * the.activeMaze.playerScale
 
102
 
 
103
                   self._fx = {0,0,0,0}
 
104
                   self.tween:start(self._fx, 4, 175, 10, 'quadIn')
 
105
 
 
106
                   self.lastChange = love.timer.getMicroTime()
 
107
                end,
 
108
   onEndFrame = function(self)
 
109
                   --the.interface.translate.x = the.player.x - the.app.width / 2 + the.player.width / 2
 
110
                   --the.interface.translate.y = the.player.y - the.app.height / 2 + the.player.height / 2
 
111
                end
 
112
}
 
113
 
 
114
MenuScreen = View:extend {
 
115
   title = Text:new{text = "Press a key to start", font = 48, wordWrap = false},
 
116
   --title = Tile:new{image = 'data/title.png', x = 0, y = 0},
 
117
   onNew = function(self)
 
118
              self:add(self.title)
 
119
              self.title:centerAround(400, 200)
 
120
           end,
 
121
   onUpdate = function(self, elapsed)
 
122
                 if the.keys:allJustPressed() then
 
123
                    the.app.view = GameView:new()
 
124
                 end
 
125
              end
 
126
}
 
127
 
 
128
the.app = App:new {
 
129
   onRun = function (self)
 
130
              print('Version: ' .. VERSION)
 
131
 
 
132
              self.view = GameView:new()
 
133
 
 
134
              if DEBUG then
 
135
                 self.console:watch('VERSION', 'VERSION')
 
136
 
 
137
                 -- back off that dark overlay a bit
 
138
                 self.console.fill.fill[4] = 75
 
139
              end
 
140
           end,
 
141
   onUpdate = function (self, dt)
 
142
                 if the.keys:justPressed('escape') then
 
143
                    if the.profiler then
 
144
                       the.profiler:stop()
 
145
                       local outfile = io.open( "profile.txt", "w+" )
 
146
                       the.profiler:report( outfile )
 
147
                       outfile:close()
 
148
                    end
 
149
 
 
150
                    self.quit()
 
151
                 end
 
152
              end
 
153
}