Page 2 of 4

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

Posted: Thu Jan 17, 2013 7:47 pm
by Sp1k3
I still don't understand why uncommenting the ice fixture causes such a weird bug, if I could get that working then friction should just work.

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

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

Posted: Sat Jan 19, 2013 9:48 pm
by Sp1k3
okay I tried only getting the x value of the linear velocity and it still doesn't work :(

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, 0, 0)
  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 


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 )
velx,vely = objects.rock.body:getLinearVelocity()
while velx > 0 do
  objects.rock.body:applyForce(-(stonepower*10), 0 )
end
      stonepower = 0
   end
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

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

Posted: Sat Jan 19, 2013 10:02 pm
by Sp1k3
setting linearDampening slows the rock down!

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

Posted: Sun Jan 20, 2013 3:26 am
by Sp1k3
http://code.google.com/p/get-your-rocks ... p&can=2&q=

Now I'm starting an entity system but the working demo with just one rock is also included in the above zip file.

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

Posted: Mon Jan 21, 2013 10:59 am
by Yell0w
It is possible (and preffered) if you upload the .love to the forum directly as i dont trust sources off domain :)

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

Posted: Mon Jan 21, 2013 11:14 am
by Nixola
Don't you trust Google?

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

Posted: Mon Jan 21, 2013 6:39 pm
by Robin
Nixola wrote:Don't you trust Google?
Is that a trick question?

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

Posted: Mon Jan 21, 2013 6:46 pm
by Nixola
Robin wrote:
Nixola wrote:Don't you trust Google?
Is that a trick question?
May it be?

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

Posted: Mon Jan 21, 2013 7:00 pm
by Robin
Nixola wrote:
Robin wrote:
Nixola wrote:Don't you trust Google?
Is that a trick question?
May it be?
Have we derailed this thread yet?

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

Posted: Mon Jan 21, 2013 7:09 pm
by Nixola
Robin wrote:
Nixola wrote:
Robin wrote:May it be?
Have we derailed this thread yet?
Do you think someone's gonna recover it?