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.rrock = {}
objects.rrock.body = love.physics.newBody(world, 64, 310, "dynamic")
objects.rrock.shape = love.physics.newCircleShape(32)
objects.rrock.fixture = love.physics.newFixture(objects.rrock.body, objects.rrock.shape, 1)
objects.rrock.fixture:setRestitution(0)
objects.rrock.body:setMassData(0, 0, 0, 0)
objects.rrock.body:setLinearDamping(0.5)
objects.brock = {}
objects.brock.body = love.physics.newBody(world, 64, 310, "dynamic")
objects.brock.shape = love.physics.newCircleShape(32)
objects.brock.fixture = love.physics.newFixture(objects.brock.body, objects.brock.shape, 1)
objects.brock.fixture:setRestitution(0)
objects.brock.body:setMassData(0, 0, 0, 0)
objects.brock.body:setLinearDamping(0.5)
rrock = love.graphics.newImage("rrock.png")
brock = love.graphics.newImage("brock.png")
ice = love.graphics.newImage("ice.png")
power = love.graphics.newImage("power.png")
mouse = love.mouse
stonepower = 0
love.graphics.setCaption ("Get Your Rocks Off | Version 0.1")
curl = 0 --going to make this a sine or cosine (depending on in or out turn) function
jointr = love.physics.newFrictionJoint( objects.ice.body, objects.rrock.body, 0, 0, 1280, 720, true )
jointb = love.physics.newFrictionJoint( objects.ice.body, objects.brock.body, 0, 0, 1280, 720, true )
forcer = jointr:setMaxForce(1)
forceb = jointb:setMaxForce(1)
shot = objects.rrock.body
x = 0
y = 0
end
function love.update(dt)
world:update(dt) --updates every frame (important)
if drag then
objects.rrock.body:setPosition(64, 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
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
end
end
if love.mousereleased() == true then
x,y = objects.rrock.body:getLinearVelocity() -- define the velocity change for the x and y axis.
end
if x>1 then
objects.rrock = shot
elseif love.mousereleased() == true and objects.brock.body:getLinearVelocity() > 1 then
objects.brock = shot
end
end
function love.mousereleased()
if drag then
drag = false
shot:setLinearVelocity(0, 0)
shot:setAngularVelocity(0)
shot:applyForce((stonepower*30), 0 )
stonepower = 0
end
end
function love.draw()
love.graphics.draw(ice, 0, 0, 0)
love.graphics.draw(brock, objects.brock.body:getX(), objects.brock.body:getY(), objects.brock.shape:getRadius())
love.graphics.draw(rrock, objects.rrock.body:getX(), objects.rrock.body:getY(), objects.rrock.shape:getRadius())
love.graphics.draw(power, 640, 360, stonepower/200, stonepower/2000)
end