practice-beefki/love/mike/levels/gamestates.lua

47 lines
1.5 KiB
Lua
Raw Normal View History

Gamestates = {}
-- Title screen
function Gamestates.title_draw()
love.graphics.setColor(255,0,0)
love.graphics.print(string.format("Press space to start!\n Or 'q' to exit."), screen.width/2, screen.height/2)
end
function Gamestates.title_update()
2017-08-11 10:57:28 -07:00
if love.keyboard.isDown("space") then
gamestate.draw = Gamestates.main_draw
gamestate.update = Gamestates.main_update
end
if love.keyboard.isDown(QUIT_KEY) then
love.event.quit()
end
end
-- Main game loop
function Gamestates.main_draw()
-- Draw paddle
love.graphics.setColor(255,255,255)
love.graphics.rectangle("line", actors.player.x, actors.player.y,
actors.player.width, actors.player.height)
-- Draw ball
love.graphics.setColor(255,0,0)
love.graphics.circle("line", actors.ball.x, actors.ball.y,
actors.ball.width, actors.ball.height)
-- FPS counter
love.graphics.setColor(128,72,25)
love.graphics.print("FPS: "..tostring(love.timer.getFPS( )), 10, 10)
-- Ball Score
love.graphics.setColor(255,0,0)
love.graphics.print("Score: "..actors.ball.score, screen.width -80, 10)
-- Timer
love.graphics.setColor(125,42,19)
love.graphics.print(string.format("Time M: %.2f", actors.end_timer/60), screen.width -85, 50)
love.graphics.print(string.format("Time S: %.2f", actors.end_timer), screen.width -85, 30)
end
function Gamestates.main_update(dt)
actors.player = check_keys(actors.player, screen, dt)
actors.ball = ball_bounce(actors.player, actors.ball, dt)
actors.end_timer = love.timer.getTime() - actors.start
end