diff --git a/love/mike/levels/gamestates.lua b/love/mike/levels/gamestates.lua new file mode 100644 index 0000000..5b1e383 --- /dev/null +++ b/love/mike/levels/gamestates.lua @@ -0,0 +1,42 @@ +Gamestates = {} + +-- Title screen +function Gamestates.title_draw() + love.graphics.setColor(255,0,0) + love.graphics.print(string.format("Press space to start!"), screen.width/2, screen.height/2) +end + +function Gamestates.title_update() + if love.keyboard.isDown(" ") then + gamestate.draw = Gamestates.main_draw + gamestate.update = Gamestates.main_update + 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 diff --git a/love/mike/main.lua b/love/mike/main.lua index 39f73a4..1be6b29 100644 --- a/love/mike/main.lua +++ b/love/mike/main.lua @@ -1,5 +1,6 @@ require "lib/keys" require "lib/functions" +require "levels/gamestates" function love.load() -- Create a table and grab the screen width/height @@ -21,31 +22,17 @@ function love.load() -- Timer vars (see keys.lua for loaded timer vars) actors.start = love.timer.getTime() actors.end_timer = 0 + + -- Set the starting screen + gamestate = {} + gamestate.draw = Gamestates.title_draw + gamestate.update = Gamestates.title_update end function love.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 + gamestate.update(dt) end function love.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) + gamestate.draw() end