-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.lua
188 lines (166 loc) · 5.01 KB
/
main.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
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
gamestate = require('gamestate')
wordpro = require('wordpro')
sideboard = require('sideboard')
font = 'Cousine-Regular.ttf'
Keyboard = require('keyboard')
Keyboards = {
selected = 'butterstick'
}
function love.load(arg)
success = love.window.setFullscreen(true)
local fontSize = love.graphics.getHeight() / 32
local lsKeyboards = io.popen("ls keyboards")
if lsKeyboards then
local keebs = lsKeyboards:read("*a")
for keeb in keebs:gmatch("[^\r\n]+") do
keeb = keeb:sub(1, #keeb - 4)
if keeb ~= 'keyboard' then
Keyboards[keeb] = require('keyboards/' .. keeb)
Keyboards[keeb]:setup(love.graphics.newFont(font, fontSize))
end
end
else
print("ERROR - failed to read keebs from keyboard-folder")
love.event.quit()
end
gamestate:setMenu()
local fontSize = love.graphics.getHeight() / 24
wordpro:setup('dictionaries/mixed.txt',
love.graphics.newFont(font, fontSize),
love.graphics.getWidth() / 2)
background = {
image = love.graphics.newImage('images/backgroundColorForest.png'),
y = -64,
x = -love.graphics.getWidth(),
speed = .8
}
background.tiles = (love.graphics.getWidth() * 2) / background.image:getWidth()
local fontSize = love.graphics.getHeight() / 24
menu = {
font = love.graphics.newFont(font, fontSize),
y = love.graphics.getHeight() / 2
}
menu.fontHeight = menu.font:getHeight('A')
endScreen = {
font = menu.font,
y = love.graphics.getHeight() / 2
}
local fontSize = love.graphics.getHeight() / 32
sideboard:setup(love.graphics.newFont(font, fontSize))
end
function love.update()
if gamestate:isMenu() then
elseif gamestate:isGame() then
sideboard:update()
if wordpro:isComplete() then
sideboard:newWord(wordpro.current, wordpro.typingCorrectlyWord)
wordpro:newWord()
end
if sideboard:timesUp() then
gamestate:setScore()
end
Keyboards:update(wordpro.nextLetter)
elseif gamestate:isScore() then
end
end
function love.draw()
love.graphics.setColor(1, 1, 1)
background.x = background.x + background.speed
if background.x > 0 then
background.x = -love.graphics.getWidth()
end
for x=0,background.tiles do
x = x * background.image:getWidth()
love.graphics.draw(background.image, x + background.x, background.y)
end
sideboard:draw()
Keyboards:draw()
if gamestate:isMenu() then
darkenScreen()
love.graphics.setColor(0, 0, 0)
love.graphics.setFont(menu.font)
local anyKey = Keyboards:getEnterKeyCombo()
local message = 'Press ' .. anyKey .. ' to start'
local x = (love.graphics.getWidth() / 2) - (menu.font:getWidth(message) / 2)
love.graphics.print(message, x, menu.y)
message = '< ' .. Keyboards.selected .. ' >'
x = (love.graphics.getWidth() / 2) - (menu.font:getWidth(message) / 2)
love.graphics.print(message, x, menu.y + menu.fontHeight)
elseif gamestate:isGame() then
wordpro:draw()
elseif gamestate:isScore() then
if not endScreen.x then
endScreen.message = sideboard.score .. ' points, ' .. sideboard.words .. ' words'
endScreen.x = (love.graphics.getWidth() / 2) -
(endScreen.font:getWidth(endScreen.message) / 2)
end
darkenScreen()
love.graphics.setColor(0, 0, 0)
love.graphics.setFont(endScreen.font)
love.graphics.print(endScreen.message, endScreen.x, endScreen.y)
end
end
function love.keypressed(key, scancode, isrepeat)
if gamestate:isMenu() then
if key == 'escape' then
love.event.quit()
end
elseif gamestate:isGame() then
if key == 'escape' then
gamestate:setMenu()
end
elseif gamestate:isScore() then
if key == 'escape' or
key == 'space'
then
endScreen.x = nil
gamestate:setMenu()
end
end
end
function love.keyreleased(key)
if gamestate:isMenu() then
if key == 'left' or key == 'right' then
toggleKeyboard()
elseif Keyboards.selected == 'butterstick' and key == 'a' then
newGame()
elseif Keyboards.selected == 'asetniop' and key == 'return' then
newGame()
end
elseif gamestate:isGame() then
wordpro:typing(key)
sideboard:typing(wordpro.typingCorrectlyLetter)
elseif gamestate:isScore() then
end
end
function darkenScreen()
love.graphics.setColor(0, 0, 0, 0.3)
love.graphics.rectangle('fill', 0, 0,
love.graphics.getWidth(),
love.graphics.getHeight())
end
function newGame()
gamestate:setGame()
wordpro:newWord()
sideboard:start()
end
function toggleKeyboard()
if Keyboards.selected == 'butterstick' then
Keyboards.selected = 'asetniop'
elseif Keyboards.selected == 'asetniop' then
Keyboards.selected = 'butterstick'
end
end
function Keyboards:draw()
self[self.selected]:draw()
end
function Keyboards:update(nextLetter)
self[self.selected]:update(nextLetter)
end
function Keyboards:getEnterKeyCombo()
if self.selected == 'asetniop' then
return 'n i o p'
elseif self.selected == 'butterstick' then
return 'q z'
end
end