practice/love/mike/main.lua

54 lines
1.7 KiB
Lua

require "lib/keys"
require "lib/functions"
function love.load()
saveFile = "test.lua"
-- Create a table and grab the screen width/height
screen = {}
screen.width = love.graphics.getWidth()
screen.height = love.graphics.getHeight()
-- Create a table to hold all actors
actors = {}
-- Create a table to hold all the player data
actors.player = create_object(screen.width /2, screen.height - 50, 30, 5, 500)
-- Create a table to hold ball data
actors.ball = create_object(screen.width /2, screen.height /2, 5, 5, 600)
actors.ball.x_speed = (-actors.ball.speed /2)
actors.ball.y_speed = (-actors.ball.speed /2)
actors.ball.score = 0
actors.start = love.timer.getTime()
actors.end_timer = 0
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
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)
end