Only been using Love for a couple of hours and playing around with a simple penalty shootout game idea.
I have managed to work out to detect when the mouse clicks the ball (thanks to help) and I am also able to launch the ball when the mouse is released. I have set the speed of my ball to 1 pixel in the horizontal direction but notice is is flying across the screen.
I would therefore like advice on how best to control the speed of the ball. Do I need to set up some sort of timer, or can I change the FPS or do I just need to change the speed to a smaller value (i.e a decimal less than one).
Thanks
Paul
Here is my entire code so far
Code: Select all
function love.load()
ball = love.graphics.newImage("ball.png")
ballx = 100
bally = 400
ballHorizontalVelocity = 0
ballVerticalVelocity = 0
arrow = love.graphics.newImage("arrow.png")
arrowx = 150
arrowy = 150
end
function love.draw()
love.graphics.draw(ball, ballx, bally)
love.graphics.draw(arrow, arrowx, arrowy)
end
function love.update(dt)
ballx = ballx + ballHorizontalVelocity
end
function love.mousepressed(x, y, button)
-- Calculate if mouse over ball
-- i.e distance squared less than radius squared
local ballRadiusSquared = 900 -- 30 x 30
if button == 'l' then
local distanceSquared = distanceSquaredFrom(x,y,ballx + 30,bally + 30)
if distanceSquared <= ballRadiusSquared then
arrowx = ballx + 30 -- move arrow to center of ball clicked
arrowy = bally + 30 - 7
end
end
end
function love.mousereleased(x, y, button)
if button == 'l' then
kickBall(x,y)
end
end
function kickBall(x,y)
ballHorizontalVelocity = 1
end
function distanceSquaredFrom(x1,y1,x2,y2)
return (x2 - x1) ^ 2 + (y2 - y1) ^ 2
end