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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
STRICT = true
DEBUG = true
require 'zoetrope'
--require 'pepperprof'
--inspect = require 'inspect'
require 'sprite'
require 'util'
require 'version'
require 'player'
require 'goal'
require 'pause_view'
require 'win_view'
GameView = View:extend {
gameStart = 0,
switchSounds = {},
onNew = function (self)
self:loadLayers('data/map.lua')
self.focus = the.player
self:clampTo(self.bg)
self.mazes = {self.maze1, self.maze2, self.maze3}
self.bgs = {self.bg, self.bg, self.bg2}
for _, maze in ipairs(self.mazes) do maze:die() end
for _, bg in ipairs(self.bgs) do bg.visible = false end
self.maze1.moveMod = 1
self.maze2.moveMod = 0.55
self.maze3.moveMod = -1
self.maze1.playerScale = 1
self.maze2.playerScale = 0.5
self.maze3.playerScale = 1
self.goals = {}
the.goalsAchieved = 0
for _, obj in ipairs(self.objects.sprites) do
if obj:instanceOf(Goal) then
obj.visible = false
self.goals[tonumber(obj.map)] = obj
end
end
local sndFiles = {'data/Explosion2.wav', 'data/Explosion3.wav', 'data/Hit_Hurt3.wav'}
for _, sndFile in ipairs(sndFiles) do
local snd = love.audio.newSource(sndFile, 'static')
table.insert(self.switchSounds, snd)
end
--the.interface = Group:new()
--self:add(the.interface)
self:switchMaze()
-- profiling...
--the.profiler = newProfiler()
--the.profiler:start()
self.gameStart = love.timer.getMicroTime()
self.lastChange = love.timer.getMicroTime()
end,
onUpdate = function(self, dt)
if the.player.active and love.timer.getMicroTime() > self.lastChange + 10 then
-- switch maze
self:switchMaze()
end
if not (DEBUG and the.console.visible) then
--the.player.collider:collide(the.activeMaze)
the.player.collider:collide(the.activeGoal)
end
if the.keys:justPressed('escape', 'q') then
PauseView:new():activate()
--elseif the.keys:justPressed('w') then
-- WinView:new():activate()
end
end,
switchMaze = function(self)
if the.activeMaze then
repeat
newMaze = math.random(3)
until self.mazes[newMaze] ~= the.activeMaze
the.activeMaze:die()
the.activeMaze = self.mazes[newMaze]
the.activeBg.visible = false
the.activeBg = self.bgs[newMaze]
if the.activeGoal then
the.activeGoal.visible = false
end
the.activeGoal = self.goals[newMaze]
love.audio.play(self.switchSounds[math.random(#self.switchSounds)])
else
the.activeMaze = self.maze2
the.activeBg = self.bg
the.activeGoal = self.goals[2]
end
the.activeMaze:revive()
the.activeBg.visible = true
if the.activeGoal then
the.activeGoal.visible = true
end
the.player.scale = the.activeMaze.playerScale
the.player.collider.width = the.player.width * the.activeMaze.playerScale
the.player.collider.height = the.player.height * the.activeMaze.playerScale
self._fx = {0,0,0,0}
self.tween:start(self._fx, 4, 175, 10, 'quadIn')
self.lastChange = love.timer.getMicroTime()
end,
onEndFrame = function(self)
--the.interface.translate.x = the.player.x - the.app.width / 2 + the.player.width / 2
--the.interface.translate.y = the.player.y - the.app.height / 2 + the.player.height / 2
end
}
MenuScreen = View:extend {
bg = Tile:new{image = 'data/intro.png', x = 0, y = 0},
onNew = function(self)
self:add(self.bg)
--self.title:centerAround(400, 200)
local nr = 'data/NewRocker-Regular.otf'
self:add(Text:new{
text = 'Name Of Game',
--x = 0,
y = 100,
width = self.bg.width,
font = {nr, 48},
align = 'center',
tint = {0,0,0}
})
self:add(Text:new{
text = 'Find the 3 lost shinies!',
y = 170,
width = self.bg.width,
font = {nr, 28},
align = 'center',
tint = {0,0,0}
})
self:add(Text:new{
text = 'Use the arrow keys to move',
y = 375,
width = self.bg.width,
font = {nr, 24},
align = 'center',
tint = {0,0,0}
})
self:add(Text:new{
text = 'Press a key to start',
y = 425,
width = self.bg.width,
font = {nr, 24},
align = 'center',
tint = {0,0,0}
})
end,
onUpdate = function(self, elapsed)
if the.keys:allJustPressed() then
the.app.view = GameView:new()
end
end
}
the.app = App:new {
onRun = function (self)
print('Version: ' .. VERSION)
self.view = MenuScreen:new()
if DEBUG then
self.console:watch('VERSION', 'VERSION')
self.console:watch('player.x', 'the.player.x')
self.console:watch('player.y', 'the.player.y')
-- back off that dark overlay a bit
self.console.fill.fill[4] = 75
end
end,
onUpdate = function (self, dt)
end
}
|