forked from gustavostuff/gooi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
executable file
·233 lines (197 loc) · 7.92 KB
/
main.lua
File metadata and controls
executable file
·233 lines (197 loc) · 7.92 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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
require "gooi"
function love.load()
gr = love.graphics
kb = love.keyboard
mo = love.mouse
gr.setBackgroundColor(0, 63, 127)
function width() return gr.getWidth() end
function height() return gr.getHeight() end
imgDir = "/imgs/"
fontDir = "/fonts/"
style = {
font = gr.newFont(fontDir.."ProggySquare.ttf", 16),
fgColor = "#ffffff",
bgColor = "#25AAE1F0",
mode3d = true,
glass = true,
radius = 3,
innerRadius = 3
}
gooi.setStyle(style)
gooi.desktopMode()
gr.setDefaultFilter("nearest", "nearest")
ship = {
img = gr.newImage(imgDir.."ship.png"),
x = 480,
y = 200
}
bullets = {}
imgBullet = gr.newImage(imgDir.."bullet.png")
imgBg = gr.newImage(imgDir.."bg.png")
-----------------------------------------------
-----------------------------------------------
-- Free elements with no layout:
-----------------------------------------------
-----------------------------------------------
lbl1 = gooi.newLabel("Free elements (no layout):", 10, 10)
lbl2 = gooi.newLabel("0", 10, 40, 90, 22):setAlign("center")
btn1 = gooi.newButton("Exit with tooltip", 110, 40, 180, 22):setIcon(imgDir.."coin.png"):bg({255, 0, 0})
:setTooltip("This is a tooltip!")
:onRelease(function()
gooi.confirm("Are you sure?", function()
quit()
end)
end)
sli1 = gooi.newSlider({x = 10, w = 90, h = 22, y = 70, value = 0.2})
spin1 = gooi.newSpinner({min = -10, max = 50, value = 33, x = 110, y = 70, w = 180, h = 22})
chb1 = gooi.newCheck({text = "A Check Box", x = 10, y = 200, w = 180, h = 22}):onRelease(function(c)
if c.checked then
gr.setBackgroundColor(127, 63, 0)
else
gr.setBackgroundColor(0, 63, 127)
end
end)
-- Radio group:
rad1 = gooi.newRadio({y = 100, h = 22, w = 80, text = "one", radioGroup = "g1", selected = true})
rad2 = gooi.newRadio({y = 130, h = 22, w = 80, text = "two", radioGroup = "g1"})
rad3 = gooi.newRadio({y = 160, h = 22, w = 80, text = "three", radioGroup = "g1"})
knob1 = gooi.newKnob({x = 110, y = 100, value = 0.9, size = 82})
-- Anoher radio group:
rad4 = gooi.newRadio({y = 100, x = 200, w = 80, h = 22, text = "Apr", radioGroup = "g2", selected = true})
rad5 = gooi.newRadio({y = 130, x = 200, w = 80, h = 22, text = "May", radioGroup = "g2"})
rad6 = gooi.newRadio({y = 160, x = 200, w = 80, h = 22, text = "Jun", radioGroup = "g2"})
txt1 = gooi.newText({y = 260, w = 180, h = 22, text = "text box"})
bar1 = gooi.newBar({y = 230, w = 180, h = 22, value = 0}):increaseAt(0.1)
joy1 = gooi.newJoy({x = 120, y = 420, size = 150}):
setImage(imgDir.."cat.png"):noSpring():noGlass():bg("#ff880088")
vertSlider = gooi.newSlider({x = 200, y = 200, w = 25, h = 82, value = 0}):vertical()
vertSlider2 = gooi.newSlider({x = 230, y = 200, w = 25, h = 82, value = 0.5}):vertical()
vertSlider3 = gooi.newSlider({x = 260, y = 200, w = 25, h = 82, value = 1}):vertical()
-----------------------------------------------
-----------------------------------------------
-- Game layout:
-----------------------------------------------
-----------------------------------------------
joyShip = gooi.newJoy({size = 60})
btnShot = gooi.newButton("Shot"):onRelease(function()
table.insert(bullets, {
x = ship.x,
y = ship.y
})
end)
pGame = gooi.newPanel(350, 10, 420, 270, "game")
pGame:add(gooi.newButton("Bomb"), "b-r")
pGame:add(btnShot, "b-r")
pGame:add(joyShip, "b-l")
pGame:add(gooi.newLabel("(Game Layout demo)"), "t-l")
pGame:add(gooi.newLabel("Score: 702013"), "t-l")
pGame:add(gooi.newBar({value = 1, w = 100}):decreaseAt(0.1), "t-r"):fg("#FFFFFF")
-----------------------------------------------
-----------------------------------------------
-- Grid layout:
-----------------------------------------------
-----------------------------------------------
pGrid = gooi.newPanel(350, 290, 420, 290, "grid 10x3")
-- Add in the specified cell:
pGrid:add(gooi.newRadio({text = "Radio 1", selected = true}), "7,1")
pGrid:add(gooi.newRadio({text = "Radio 2"}):setRadius(0):bg("#00000000"):fg("#00ff00"), "8,1")
pGrid:add(gooi.newRadio({text = "Radio 3"}):setRadius(0):bg("#00000000"):border(1, "#000000"):fg("#ff7700"), "9,1")
pGrid
:setColspan(1, 1, 3)-- Row, column and span size
:setRowspan(6, 3, 2)
:setColspan(8, 2, 2)
:setRowspan(8, 2, 3)
:add(
gooi.newLabel({text = "(Grid Layout demo)", align = "center"}),
gooi.newLabel({text = "Left label", align = "left"}),
gooi.newLabel({text = "Centered", align = "center"}),
gooi.newLabel({text = "Right", align = "right"}),
gooi.newButton({text = "Left button", align = "left"}):bg("#ff8800"),
gooi.newButton("Centered"):bg("#22aa22"),
gooi.newButton({text = "Right", align = "right"}),
gooi.newLabel({text = "Left label", align = "left", icon = imgDir.."coin.png"}),
gooi.newLabel({text = "Centered", align = "center", icon = imgDir.."coin.png"}),
gooi.newLabel({text = "Right", align = "right", icon = imgDir.."coin.png"}),
gooi.newButton({text = "Left button", align = "left", icon = imgDir.."medal.png"}):bg("#888888"),
gooi.newButton({text = "Alert btn", align = "center", icon = imgDir.."medal.png"})
:bg("#880088"):onRelease(function()
gr.setBackgroundColor(r2(), r2(), r2())
gooi.alert("The background has changed!")
end),
gooi.newButton({text = "Confirm btn", align = "right", icon = imgDir.."medal.png"}):bg("#888800")
:onRelease(function()
gooi.confirm("Change background?", function()
gr.setBackgroundColor(r2(), r2(), r2())
end)
end),
gooi.newSlider({value = 0.75}):bg("#00000000"):border(3, "#00ff00"):fg({255, 0, 0}),
gooi.newCheck("Debug"):setRadius(12, 10):bg({127, 63, 0, 200}):fg("#00ffff"):border(1, "#ffff00")
:onRelease(function(c)
pGrid.layout.debug = not pGrid.layout.debug
end),
gooi.newBar(0):setRadius(0, 10):bg("#77ff00"):fg("#8800ff"):increaseAt(0.05),
gooi.newSpinner(-10, 30, 3):setRadius(0, 0):bg("#ff00ff"),
gooi.newJoy():setRadius(0):border(1, "#000000", "rough"):bg({0, 0, 0, 0}),
gooi.newKnob(1)
)
-- Salute:
lblCoords = gooi.newLabel("", 30, 330, 300, 30):setAlign("left")
gooi.newLabel("This is a demonstration of the different\n"..
"components, styles and layouts supported", 30, 360):setAlign("left")
--gooi.removeComponent(pGrid)
end
function love.update(dt)
gooi.update(dt)
lbl2:setText(sli1:getValue())
-- Move itself:
joy1.x = (joy1.x + joy1:xValue() * dt * 200)
joy1.y = (joy1.y + joy1:yValue() * dt * 200)
ship.x = (ship.x + joyShip:xValue() * dt * 150)
ship.y = (ship.y + joyShip:yValue() * dt * 150)
if ship.x > width() then ship.x = width() end
if ship.x < 0 then ship.x = width() end
-- Move bullets:
for i = #bullets, 1, -1 do
bullets[i].y = bullets[i].y - dt * 800
if bullets[i].y < -100 then
table.remove(bullets, i)
end
end
lblCoords:setText("coords: "..joy1:xValue()..", "..joy1:yValue())
end
function love.draw()
-- Background:
gr.draw(imgBg, 0, 0, 0, width() / imgBg:getWidth(), height() / imgBg:getHeight())
-- Bullets:
for i = 1, #bullets do
local b = bullets[i]
gr.draw(imgBullet, b.x, b.y, 0, 4, 4,
imgBullet:getWidth() / 2,
imgBullet:getHeight() / 2)
end
gr.setColor(0, 0, 0, 127)
gr.rectangle("line", pGame.x, pGame.y, pGame.w, pGame.h)
gr.rectangle("line", pGrid.x, pGrid.y, pGrid.w, pGrid.h)
gr.setColor(255, 255, 255)
gr.draw(ship.img, ship.x, ship.y, 0, 4, 4,
ship.img:getWidth() / 2,
ship.img:getHeight() / 2)
gooi.draw()
gr.print("FPS: "..love.timer.getFPS())
end
function love.mousereleased(x, y, button) gooi.released() end
function love.mousepressed(x, y, button) gooi.pressed() end
function love.textinput(text)
gooi.textinput(text)
end
function love.keypressed(key)
gooi.keypressed(key)
if key == "escape" then
quit()
end
end
function quit()
love.event.quit()
end
function r() return love.math.random(0, 255) end
function r2() return love.math.random(0, 127) end