-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.lua
More file actions
169 lines (150 loc) · 4.71 KB
/
menu.lua
File metadata and controls
169 lines (150 loc) · 4.71 KB
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
----------------------------
-- Author: M. Utku Altinkaya
-- utkualtinkaya@gmail.com
----------------------------
require "gui"
--Scene for intro and menu
MenuScene = Class(UIScene)
function MenuScene:init()
UIScene.init(self)
self.ui = self:startUI()
local images = {}
self.emitters = {}
for i, name in ipairs({"blue", "lime", "lightBlue", "orange", "green", "purple", "red"}) do
table.insert(images, love.graphics.newImage("assets/"..name..".png"))
end
self.backTop = love.graphics.newImage("assets/back_top.png")
self.backBottom = love.graphics.newImage("assets/back_bottom.png")
self.title = love.graphics.newImage("assets/title.png")
--Particle system for falling blocks
for n=3,1,-1 do -- 3 different layers to create depth illusion
for _, piece in ipairs(images) do
local p = love.graphics.newParticleSystem(piece, 30)
p:setEmissionRate(1)
p:setSpeed(100/n, 200/n)
p:setSizes(1/n,1/n,1/n)
p:setColors(255, 255, 255, 255/n, 255, 255, 255, 255/n)
p:setLifetime(-1)
p:setParticleLife(20)
p:setDirection(math.pi/2)
p:setSpread(0)
p:setSpin( math.pi*0.1, math.pi*0.2, math.pi*0.05)
table.insert(self.emitters, p)
end
end
love.audio.play(music["default"], 0)
--Particle sytem for fire wall
local p = love.graphics.newParticleSystem(love.graphics.newImage("assets/part1.png"), 300)
p:setEmissionRate(200)
p:setSpeed(250, 350)
p:setSizes(1, 2)
p:setColors(220, 105, 20, 255, 194, 30, 18, 0)
p:setPosition(400, 300)
p:setLifetime(-1)
p:setParticleLife(0.4)
p:setSpread(0)
p:setDirection(-math.pi/2)
p:setTangentialAcceleration(100)
p:setRadialAcceleration(-200)
self.firewall = p
end
--Start ui
function MenuScene:startUI()
local ui = {}
local x, y = windowWidth/2, windowHeight/2 + 100
ui["start"] = Button:create("Start", x, y)
ui["score"] = Button:create("Highscores", x, y+40)
ui["settings"] = Button:create("Difficulty", x, y+75)
ui["about"] = Button:create("About", x, y+215)
return ui
end
--Setting ui
function MenuScene:settingsUI()
local ui = {}
local x, y = windowWidth/2, windowHeight/2 + 100
ui["setEasy"] = Button:create("Easy", x, y)
ui["setNormal"] = Button:create("Normal", x, y+35)
ui["setHard"] = Button:create("Hard", x, y+65)
local names = {"setEasy", "setNormal", "setHard"}
ui[names[settings.difficulty]].normalColor = {255, 0, 0, 255}
return ui
end
--Start ui
function MenuScene:aboutUI()
local x, y = windowWidth/2, windowHeight/2 + 80
local ui = {}
ui["title"] = Label:create("Blocking Bad", x, y)
ui["name"] = Label:create("M. Utku Altinkaya", x, y+40)
ui["desc"] = Label:create("an open source free game", x, y+80)
ui["site"] = Button:create("Site - Source", x, y+120)
ui["menu"] = Button:create("Back", x, y+200)
return ui
end
--Top score list ui
function MenuScene:scoreUI()
local x, y = windowWidth/2, windowHeight/2 + 80
local ui = {}
ui["title"] = Label:create("Hall of fame", x, y)
for i=1,5 do
y = y + 35
ui[i] = Label:create(scoreboard[i].name.." - "..scoreboard[i].score, x, y)
end
ui["menu"] = Button:create("Back", x, y+35)
return ui
end
function MenuScene:update(dt)
UIScene.update(self, dt)
for i, emitter in ipairs(self.emitters) do
emitter:setPosition(math.random()*windowWidth, -100)
emitter:update(dt)
end
self.firewall:update(dt)
self.firewall:setPosition(math.random()*windowWidth, 500)
end
function MenuScene:draw()
love.graphics.draw(self.backTop)
for i, emitter in ipairs(self.emitters) do
love.graphics.draw(emitter)
end
local colorMode = love.graphics.getColorMode()
local blendMode = love.graphics.getBlendMode()
love.graphics.setColorMode("modulate")
love.graphics.setBlendMode("additive")
love.graphics.draw(self.firewall)
love.graphics.setColorMode(colorMode)
love.graphics.setBlendMode(blendMode)
love.graphics.draw(self.backBottom)
love.graphics.draw(self.title)
UIScene.draw(self)
end
--Receive and process button click event
function MenuScene:buttonClick(button)
if button == "start" then
love.audio.stop(music["default"])
game:setState(GameScene:create())
elseif button == "settings" then
self.ui = self:settingsUI()
elseif button == "about" then
self.ui = self:aboutUI()
elseif button == "menu" then
self.ui = self:startUI()
elseif button == "score" then
self.ui = self:scoreUI()
elseif button == "setEasy" then
settings.difficulty = 1
self.ui = self:startUI()
elseif button == "setNormal" then
settings.difficulty = 2
self.ui = self:startUI()
elseif button == "setHard" then
settings.difficulty = 3
self.ui = self:startUI()
elseif button == "site" then
os.execute("start http://mua.github.io")
end
end
ScoreScene = Class(UIScene)
function ScoreScene:init()
self.super.init(self)
table.insert(self.ui, Button:create("Done", 100, 100))
end