-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathword.lua
More file actions
81 lines (63 loc) · 1.44 KB
/
word.lua
File metadata and controls
81 lines (63 loc) · 1.44 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
Class = require "lib/hump.class"
Letter = Class {
init = function(self, x, y, str)
self.x = x
self.y = y
self.str = str
self.strlength = string.len(str)
self.status = 0
end;
__tostring = function(self)
return self.str
end;
}
function Letter:update(dt)
end
function Letter:draw()
if self.status == 1 then
love.graphics.setColor(0, 1, 0, 1)
elseif self.status == -1 then
love.graphics.setColor(1, 0, 0, 1)
end
love.graphics.print(self.str, self.x, self.y)
love.graphics.setColor(1, 1, 1, 1)
end
Word = Class {
init = function(self, str)
self.str = str
self.letters = {}
self.status = 0
self.current = 1
self.x = 280
self.y = 674
for i = 1, string.len(str) do
table.insert(self.letters, Letter(self.x + ((i-1)*32), self.y, string.sub(str, i, i)))
end
end;
__tostring = function(self)
return self.str
end;
}
function Word:update(dt)
end
function Word:draw()
for _,v in pairs(self.letters) do
v:draw()
end
end
function Word:akey(key)
if self.status == 0 then
if key == self.letters[self.current].str then
self.letters[self.current].status = 1
if self.letters[self.current + 1] == nil then
self.status = 1
end
else
self.status = -1
for _,v in pairs(self.letters) do
v.status = -1
end
end
end
self.current = self.current + 1
end