I'd also like to note that the innacuracy is proportional to the gravity. (world.lua line 8)
I'm attaching the .love file but please note that it's for v0.10.2. Sorry for all the bad code, any feedback is appreciated.
Here's the code that sets the player flying. (player.lua line 60)
Code: Select all
function player.mousereleased(x, y, mb, istouch)
obj.player.body:setLinearVelocity((player.onScreenX-x)*ui.pullStrength, (obj.player.body:getY()-y)*ui.pullStrength)
end
Code: Select all
function ui.drawBackground()
love.graphics.setColor(230, 100, 60)
love.graphics.setLineWidth(H*0.006)
love.graphics.setPointSize(H*0.006)
if love.mouse.isDown(1) then
love.graphics.line(player.onScreenX, obj.player.body:getY(), love.mouse.getX(), love.mouse.getY())
-- Per second approach
for n = .01, .8, .02 do
love.graphics.setColor(230, 100, 60, 255-255*n/.8)
love.graphics.line(player.onScreenX+(player.onScreenX-love.mouse.getX())*ui.pullStrength*n,
obj.player.body:getY()+(obj.player.body:getY()-love.mouse.getY())*ui.pullStrength*n+(world.g*world.meter*n^2)/2,
player.onScreenX+(player.onScreenX-love.mouse.getX())*ui.pullStrength*(n+.01),
obj.player.body:getY()+(obj.player.body:getY()-love.mouse.getY())*ui.pullStrength*(n+.01)+(world.g*world.meter*(n+.01)^2)/2)
end
-- Per timestep approach
love.graphics.setColor(51, 244, 88)
for n = 1, 60, 1 do
love.graphics.points(player.onScreenX + (player.onScreenX-love.mouse.getX())*ui.pullStrength*n/60,
obj.player.body:getY() + (obj.player.body:getY()-love.mouse.getY())*ui.pullStrength*n/60 + (n*n+n)*(world.g*world.meter)/(60*60)/2)
end
end
end