main.lua
· 1.4 KiB · Lua
Sin formato
Playground
score = 0
timer = 30
letter = string.char(math.random(97, 122))
font = love.graphics.newFont(48)
gameover = false
love.graphics.setFont(font)
function love.update(dt)
timer = timer - dt
if timer <= 0 then
gameover = true
end
end
function love.draw()
if not gameover then
love.graphics.setColor(50/256, 127/256, 75/256)
love.graphics.rectangle('fill', 0, love.graphics.getHeight()/2 - 50, love.graphics.getWidth() * (timer / 30), 100)
love.graphics.setColor(1, 1, 1)
love.graphics.print(letter, love.graphics.getWidth() / 2 - font:getWidth(letter)/2, love.graphics.getHeight()/2 - font:getHeight()/2)
else
love.graphics.setColor(200/256, 50/256, 50/256)
love.graphics.print("GAME OVER", love.graphics.getWidth() / 2 - font:getWidth("GAME OVER")/2, love.graphics.getHeight()/2 - font:getHeight()/2)
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)
end
love.graphics.setColor(1, 1, 1)
love.graphics.print(score, love.graphics.getWidth() / 2 - font:getWidth(tostring(score)) / 2, 0)
end
function love.keypressed(key, scancode)
if key == letter and not gameover then
score = score + 1
letter = string.char(math.random(97, 122))
elseif gameover and scancode == 'r' then
score = 0
gameover = false
timer = 30
end
end
| 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 |