-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.lua
More file actions
88 lines (74 loc) · 2.07 KB
/
Copy pathinterface.lua
File metadata and controls
88 lines (74 loc) · 2.07 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
require "field"
Interface = {}
local numOfMenuFields = 3
function Interface:load(arg1, arg2, arg3, arg4, arg5)
x1 = arg1
y1 = arg2
dt = { x = arg3, y = arg4 }
defaultColor = arg5
menuField = {
{name = "Start", lighted = false, x = x1, y = y1},
{name = "Exit", lighted = false, x = x1, y = y1+dt.y*3},
{name = "Clear", lighted = false, x = x1, y = y1+dt.y}
}
--Flags
command = nil
gameStarted = nil
end
function Interface:draw(x,y)
local i
for i = 1, numOfMenuFields, 1 do
if menuField[i].lighted then
love.graphics.setColor(60,130,230)
love.graphics.print(menuField[i].name, menuField[i].x, menuField[i].y)
love.graphics.setColor(defaultColor.r,defaultColor.g, defaultColor.b)
else
love.graphics.print(menuField[i].name,menuField[i].x, menuField[i].y)
end
end
end
function Interface:update(mouseClicked)
local i, x, y
x, y = love.mouse.getPosition()
for i = 1, numOfMenuFields, 1 do
Interface:processMouseSignal(i, x, y, mouseClicked)
end
gameStarted = Interface:processSignal()
command = nil
return gameStarted
end
function Interface:processSignal()
if command ~= nil then
print(command)
end
if command == "Start" then
if gameStarted then
return 0
else
return 1
end
else
if command == "Clear" then
return love.load(defaultColor)
else
if command == "Exit" then
love.event.push('quit')
end
end
end
if gameStarted then
return 1
end
end
function Interface:processMouseSignal(i, x, y, mouseClicked)
if menuField[i].x < x and x < menuField[i].x + dt.x and menuField[i].y < y and y < menuField[i].y + dt.y then
if menuField[i].lighted == false then
menuField[i].lighted = true
end
if mouseClicked then
command = menuField[i].name
end
else
menuField[i].lighted = false
end
end