trying to make a click and drag curling rock demo

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Sp1k3
Prole
Posts: 20
Joined: Mon Jan 14, 2013 7:32 am

Re: trying to make a click and drag curling rock demo

Post by Sp1k3 »

The below code doesn't work but I think I get the gist of it, the debugger doesn't give me much help on why it doesn't work though.

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
Sp1k3
Prole
Posts: 20
Joined: Mon Jan 14, 2013 7:32 am

Re: trying to make a click and drag curling rock demo

Post by Sp1k3 »

Alright so I got some more help with the code, if anybody is interested they can download the zip attached to this message.
Attachments
GYROv0.314159265359.zip
(1.44 MiB) Downloaded 130 times
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot] and 9 guests