This repository has been archived by the owner on Jan 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayLevel.lua
113 lines (78 loc) · 1.91 KB
/
playLevel.lua
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
require "elementEditor"
require "audio"
musicIndex = 1
local function enter()
states.elementEditor.enter()
local unclassed = require("Levels/" .. levelToLoad)
copy = {}
for k,v in pairs(unclassed) do
copy[k] = v
end
applyClassesAndSet( copy )
-- reset boids
states.boids.enter()
-- choose some music!
sounds.music.level1:stop()
sounds.music.level2:stop()
sounds.music.level3:stop()
sounds.music["level" .. musicIndex]:play()
musicIndex = musicIndex + 1
if (musicIndex > 3) then musicIndex = 1 end
end
local function weWon()
-- see how many goal elements are happy
for k, element in pairs(activeElements)do
if (not element:AllowWin()) then
return false
end
end
return true
end
local function draw()
-- draw the placed elements
for k, template in pairs(activeElements) do
template:draw()
end
boids.draw()
local y = love.graphics.getHeight() - 100;
love.graphics.print("R to restart ESC to exit puzzle", 10, y )
local win_sound = sounds.sfx["win"];
if (weWon()) then
love.graphics.print("YOU WIN!", 600, y)
if not win_sound:isPlaying() then
win_sound:play()
end
else
if win_sound:isPlaying() then
win_sound:stop()
end
end
end
local function update(dt)
boids.update(dt)
updateDrag()
end
local function keypressed(key)
if key == "r" then
setMainState(states.playLevel);
end
if key == "escape" then
setMainState(states.levelList);
end
end
local function mousereleased(x,y)
updateDrag()
draggedGuy = nil;
end
local function mousepressed(x,y)
local placed = getHitElement(x,y,activeElements);
if (placed and not placed.playerCantDrag) then
startDrag(x,y,placed)
end
end
return { enter = enter,
draw = draw,
update=update,
keypressed=keypressed,
mousereleased=mousereleased,
mousepressed=mousepressed};