Skip to content

Instantly share code, notes, and snippets.

Created January 10, 2014 18:11
Show Gist options
  • Save anonymous/8359473 to your computer and use it in GitHub Desktop.
Save anonymous/8359473 to your computer and use it in GitHub Desktop.
mycolor = {0, 0, 0}
CAM_STIFFNESS = 1000.0
CAM_DAMPING = 100.0
CAM_MASS = 5.0
position = {0,0}
speed = {0,0}
target ={0,0}
function updatestar(dt)
stretchx = position[1] - target[1]
stretchy = position[2] - target[2]
forcex = (stretchx * -CAM_STIFFNESS) - (speed[1] * CAM_DAMPING)
forcey = (stretchy * -CAM_STIFFNESS) - (speed[2] * CAM_DAMPING)
accelx = forcex / CAM_MASS
accely = forcey / CAM_MASS
speed[1] = speed[1] + (accelx * dt)
speed[2] = speed[2] + (accely * dt)
position[1] = position[1] + (speed[1] *dt)
position[2] = position[2] + (speed[2] *dt)
end
function love.load()
star = love.graphics.newImage("hand.png")
world = love.physics.newWorld(0, 200, true) --Gravity is being set to 0 in the x direction and 200 in the y direction.
love.graphics.setNewFont(12)
background = love.graphics.newImage("background.jpg")
love.mouse.setVisible(true)
Marble_blue = love.graphics.newImage("Marble_blue.png")
cursor = love.mouse.newCursor( "cursor_new.png",0,0)
end
function love.update(dt)
target[1] = love.mouse.getX()
target[2] = love.mouse.getY()
updatestar(dt)
world:update(dt)
end
function love.draw()
love.graphics.draw (background,0,0)
love.graphics.draw (star, position[1], position[2])
love.graphics.draw (Marble_blue)
love.graphics.draw (cursor)
end
if text then
love.graphics.setColor(0,0,0)
love.graphics.print (text, position[1], position[2])
end
function love.mousepressed(x, y, button)
if button == 'l' then
position[1] = x
position[2] = y
firstclick = 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment