Code: Select all
function love.load()
--initial graphics and physics setup
love.graphics.setMode(1280, 720, false, true, 8) --sets the window dimensions to 720p
love.physics.setMeter(64)
world = love.physics.newWorld(0, 0, 1280, 720, 500, 500, true )
objects = {}
objects.ice = {}
objects.ice.body = love.physics.newBody(world, 0, 0, "dynamic")
objects.ice.shape = love.physics.newRectangleShape(1280, 720)
--objects.ice.fixture = love.physics.newFixture(objects.ice.body, objects.ice.shape)
objects.rock = {}
objects.rock.body = love.physics.newBody(world, 64, 310, "dynamic")
objects.rock.shape = love.physics.newCircleShape(32)
objects.rock.fixture = love.physics.newFixture(objects.rock.body, objects.rock.shape, 1)
objects.rock.fixture:setRestitution(0)
objects.rock.body:setMassData(0, 0, 2, 250)
rock = love.graphics.newImage("rock.png")
ice = love.graphics.newImage("ice.png")
mouse = love.mouse
stonepower = 0
love.graphics.setCaption ("Love Curl Tech Demo")
curl = 0 --going to make this a sine or cosine (depending on in or out turn) function
joint = love.physics.newFrictionJoint( objects.ice.body, objects.rock.body, 0, 0, 1280, 720, true )
force = joint:setMaxForce(1)
end
function love.update(dt)
world:update(dt) --updates every frame (important)
if drag then
objects.rock.body:setPosition(love.mouse.getX()-32,love.mouse.getY()-64)
end
if love.mouse.isDown("l") then
stonepower = stonepower + (dt*1000) -- increases the variable by 100 for every second the button is held down
end
end
function love.mousepressed(x,y,button)
if button == "l" then
if drag == false then
MousePositionSaved = { x= love.mouse.getX(), y=love.mouse.getY() }
end
drag = true
-- if objects.rock.shape:testPoint(mouse.getPosition()) then
-- objects.rock.body:setMass(0,0,0,0)
-- end
end
end
function love.mousereleased()
if drag then
drag = false
-- ojects.rock.body:setLinearVelocity(0,0)
-- objects.rock.body:setMassFromShapes()
objects.rock.body:setLinearVelocity(0, 0)
objects.rock.body:setAngularVelocity(0)
objects.rock.body:applyForce((stonepower*10), 0 )
stonepower = 0
end
velocity = objects.rock.body:getLinearVelocity(x)
while velocity > 0 do
objects.rock.body:applyForce(-(stonepower*10), 0 )
end
end
function love.draw()
love.graphics.draw(ice, 0, 0, 0)
love.graphics.draw(rock, objects.rock.body:getX(), objects.rock.body:getY(), objects.rock.shape:getRadius()) --eventually I want to set a shader to change the colour warmness of the rock based on stonepower
end