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 »

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
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 »

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
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 »

setting linearDampening slows the rock down!
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 »

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.
User avatar
Yell0w
Prole
Posts: 28
Joined: Wed Nov 21, 2012 7:40 am
Location: Norway
Contact:

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

Post by Yell0w »

It is possible (and preffered) if you upload the .love to the forum directly as i dont trust sources off domain :)
You can learn anything, but you cannot learn everything!
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

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

Post by Nixola »

Don't you trust Google?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin »

Nixola wrote:Don't you trust Google?
Is that a trick question?
Help us help you: attach a .love.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

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

Post by Nixola »

Robin wrote:
Nixola wrote:Don't you trust Google?
Is that a trick question?
May it be?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post 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?
Help us help you: attach a .love.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

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

Post 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?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests