最后活跃于 6 hours ago

Some kind of typing game in LÖVE

main.lua 原始文件 Playground
1score = 0
2timer = 30
3letter = string.char(math.random(97, 122))
4font = love.graphics.newFont(48)
5gameover = false
6love.graphics.setFont(font)
7
8function love.update(dt)
9 timer = timer - dt
10 if timer <= 0 then
11 gameover = true
12 end
13end
14
15function love.draw()
16 if not gameover then
17 love.graphics.setColor(50/256, 127/256, 75/256)
18 love.graphics.rectangle('fill', 0, love.graphics.getHeight()/2 - 50, love.graphics.getWidth() * (timer / 30), 100)
19 love.graphics.setColor(1, 1, 1)
20 love.graphics.print(letter, love.graphics.getWidth() / 2 - font:getWidth(letter)/2, love.graphics.getHeight()/2 - font:getHeight()/2)
21 else
22 love.graphics.setColor(200/256, 50/256, 50/256)
23 love.graphics.print("GAME OVER", love.graphics.getWidth() / 2 - font:getWidth("GAME OVER")/2, love.graphics.getHeight()/2 - font:getHeight()/2)
24 love.graphics.print("Press R to Restart", love.graphics.getWidth() / 2 - font:getWidth("Press R to Restart")/2, love.graphics.getHeight()/2 + font:getHeight() * 3/2)
25 end
26
27 love.graphics.setColor(1, 1, 1)
28 love.graphics.print(score, love.graphics.getWidth() / 2 - font:getWidth(tostring(score)) / 2, 0)
29end
30
31function love.keypressed(key, scancode)
32 if key == letter and not gameover then
33 score = score + 1
34 letter = string.char(math.random(97, 122))
35 elseif gameover and scancode == 'r' then
36 score = 0
37 gameover = false
38 timer = 30
39 end
40end