-
-
Save gamedevsam/8360381 to your computer and use it in GitHub Desktop.
Fixing up some weirdness - need testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | |
-- store global values up top for easy reminder | |
star = nil | |
cursor = nil | |
function love.load() | |
cursor = love.mouse.newCursor( "cursor_new.png",0,0) | |
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") | |
end | |
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.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 | |
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