Última atividade 7 hours ago

Some kind of typing game in LÖVE

capitalex's Avatar capitalex revisou este gist 7 hours ago. Ir para a revisão

1 file changed, 40 insertions

main.lua(arquivo criado)

@@ -0,0 +1,40 @@
1 + score = 0
2 + timer = 30
3 + letter = string.char(math.random(97, 122))
4 + font = love.graphics.newFont(48)
5 + gameover = false
6 + love.graphics.setFont(font)
7 +
8 + function love.update(dt)
9 + timer = timer - dt
10 + if timer <= 0 then
11 + gameover = true
12 + end
13 + end
14 +
15 + function 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)
29 + end
30 +
31 + function 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
40 + end
Próximo Anterior