Loveballs, A love2d Softbody lib

Showcase your libraries, tools and other projects that help your fellow love users.
Connorses
Prole
Posts: 49
Joined: Fri Sep 06, 2013 7:02 am

Re: Loveballs, A love2d Softbody lib

Post by Connorses » Wed Feb 11, 2015 10:11 pm

Thanks for all the help, by the way, I'm just busy lately with college, but I fully intend to re-write my code from scratch to incorporate everything I need when I've got some spare time. I'm confident I'll now have all the tools I need if I decide to continue with the softbody game.

IndieRetro
Citizen
Posts: 51
Joined: Mon Apr 15, 2013 8:21 pm
Contact:

Re: Loveballs, A love2d Softbody lib

Post by IndieRetro » Thu Feb 12, 2015 4:26 am

Connorses wrote:Thanks for all the help, by the way, I'm just busy lately with college, but I fully intend to re-write my code from scratch to incorporate everything I need when I've got some spare time. I'm confident I'll now have all the tools I need if I decide to continue with the softbody game.
Awesome! If you make anything using it let me know, I'd love to see it ^^
irc.freenode.org ##oodnet
http://exez.in/

User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Loveballs, A love2d Softbody lib

Post by Ranguna259 » Sun Feb 22, 2015 6:25 pm

Love you lib, now we can do games like microtrip :P
But I'd like to ask some changes if you don't mind.

1. Instead of having the global "Softbody" maybe you could local that variable in init.lua and in the then return it, like this:
init.lua

Code: Select all

--Softbody lib by Shorefire/Steven
--tesselate function by Amadiro/Jonathan Ringstad
local path = ...;
require(path.."/class");
local Softbody = newclass("Softbody");

...

function tessellate(vertices, new_vertices)

  ...

  for i = 1,#new_vertices,4 do
    if i == 1 then
      -- x coordinate
      new_vertices[1] = MIX_FACTOR*(new_vertices[#new_vertices - 1] + new_vertices[3])/2 + (1 - MIX_FACTOR)*new_vertices[1]
      -- y coordinate
      new_vertices[2] = MIX_FACTOR*(new_vertices[#new_vertices - 0] + new_vertices[4])/2 + (1 - MIX_FACTOR)*new_vertices[2]
    else
      -- x coordinate
      new_vertices[i] = MIX_FACTOR*(new_vertices[i - 2] + new_vertices[i + 2])/2 + (1 - MIX_FACTOR)*new_vertices[i]
      -- y coordinate
      new_vertices[i + 1] = MIX_FACTOR*(new_vertices[i - 1] + new_vertices[i + 3])/2 + (1 - MIX_FACTOR)*new_vertices[i + 1]
    end
  end
end

return Softbody
main.lua

Code: Select all

softbody = require('loveballs')
or

Code: Select all

randomvariablename = require('loveballs')
2. We have to update every softbody we create individually, it'd be great if we could create a softbody world which then we would use to create bodies and then we'd just need to update the world instead of every body:
main.lua

Code: Select all

softbody = require('loveballs')
function love.load()
  physWorld = love.physics.newWorld(0,9.81,true)
  softWorld = softbody:newWorld(physWorld)
  soft1 = softWorld:newBody(world, 400, -200, 100, 2, 4)
  soft2 = softWorld:newBody(world, 400, 0, 35, 2, 4)
end

function love.update()
  softWorld:update()
end

function love.draw()
  soft1:draw()
  soft2:draw("line")
end
What do you think ?
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.

User avatar
ArchAngel075
Party member
Posts: 317
Joined: Mon Jun 24, 2013 5:16 am

Re: Loveballs, A love2d Softbody lib

Post by ArchAngel075 » Sun Feb 22, 2015 7:18 pm

Ranguna259 wrote: -snip-

Microtrip looks incredibly cute and fun :awesome: , too bad im not too big a fan of mobile games :nyu:

If you want to have the changes made then perhaps pull request the project on github - I would do so myself seeing as i might want the softbody world aswell for future ideas (ive never need for it yet as my on hold project only had one softbody to deal with at a time)

IndieRetro
Citizen
Posts: 51
Joined: Mon Apr 15, 2013 8:21 pm
Contact:

Re: Loveballs, A love2d Softbody lib

Post by IndieRetro » Tue Feb 24, 2015 1:04 am

Ranguna259 wrote:Love you lib, now we can do games like microtrip :P
But I'd like to ask some changes if you don't mind.

1. Instead of having the global "Softbody" maybe you could local that variable in init.lua and in the then return it, like this:
init.lua

Code: Select all

--Softbody lib by Shorefire/Steven
--tesselate function by Amadiro/Jonathan Ringstad
local path = ...;
require(path.."/class");
local Softbody = newclass("Softbody");

...

function tessellate(vertices, new_vertices)

  ...

  for i = 1,#new_vertices,4 do
    if i == 1 then
      -- x coordinate
      new_vertices[1] = MIX_FACTOR*(new_vertices[#new_vertices - 1] + new_vertices[3])/2 + (1 - MIX_FACTOR)*new_vertices[1]
      -- y coordinate
      new_vertices[2] = MIX_FACTOR*(new_vertices[#new_vertices - 0] + new_vertices[4])/2 + (1 - MIX_FACTOR)*new_vertices[2]
    else
      -- x coordinate
      new_vertices[i] = MIX_FACTOR*(new_vertices[i - 2] + new_vertices[i + 2])/2 + (1 - MIX_FACTOR)*new_vertices[i]
      -- y coordinate
      new_vertices[i + 1] = MIX_FACTOR*(new_vertices[i - 1] + new_vertices[i + 3])/2 + (1 - MIX_FACTOR)*new_vertices[i + 1]
    end
  end
end

return Softbody
main.lua

Code: Select all

softbody = require('loveballs')
or

Code: Select all

randomvariablename = require('loveballs')
2. We have to update every softbody we create individually, it'd be great if we could create a softbody world which then we would use to create bodies and then we'd just need to update the world instead of every body:
main.lua

Code: Select all

softbody = require('loveballs')
function love.load()
  physWorld = love.physics.newWorld(0,9.81,true)
  softWorld = softbody:newWorld(physWorld)
  soft1 = softWorld:newBody(world, 400, -200, 100, 2, 4)
  soft2 = softWorld:newBody(world, 400, 0, 35, 2, 4)
end

function love.update()
  softWorld:update()
end

function love.draw()
  soft1:draw()
  soft2:draw("line")
end
What do you think ?
As for the first point, I'll probably do that at somepoint when I get a chance.

But the second point, personally I dislike this as I find it better to keep each softbody individual, as each one is its own object you may want to update them at different times, or store them in your own tables and iterate over those tables to draw/update them as you please. It's just generally better coding imo.

Besides, the updating isnt to actually update the physics object, thats all handled in Box2D's world update, the softbody update is for updaing the tesselation for drawing, which realistically you should only ever call when drawing it, so its good to keep these things seperate and let the programmer call them when they need them :p

But I'll 100% implement that first idea at some point, when I get the chance. I really need to go over all the code at somepoint and clean it all up, add a few useful functions and make it more modular.
irc.freenode.org ##oodnet
http://exez.in/

IndieRetro
Citizen
Posts: 51
Joined: Mon Apr 15, 2013 8:21 pm
Contact:

Re: Loveballs, A love2d Softbody lib

Post by IndieRetro » Tue Feb 24, 2015 2:24 pm

Small update released, fixed a few bugs and things.

See first post for changes.
irc.freenode.org ##oodnet
http://exez.in/

IndieRetro
Citizen
Posts: 51
Joined: Mon Apr 15, 2013 8:21 pm
Contact:

Re: Loveballs, A love2d Softbody lib

Post by IndieRetro » Fri Feb 27, 2015 7:13 pm

Update released, see first post for details.
irc.freenode.org ##oodnet
http://exez.in/

User avatar
Ulydev
Party member
Posts: 440
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

Re: Loveballs, A love2d Softbody lib

Post by Ulydev » Mon Jul 27, 2015 5:14 am

Where has this gone ? :cry:

IndieRetro
Citizen
Posts: 51
Joined: Mon Apr 15, 2013 8:21 pm
Contact:

Re: Loveballs, A love2d Softbody lib

Post by IndieRetro » Mon Jul 27, 2015 2:08 pm

Ulydev wrote:Where has this gone ? :cry:
It's back up now.
irc.freenode.org ##oodnet
http://exez.in/

User avatar
Ulydev
Party member
Posts: 440
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

Re: Loveballs, A love2d Softbody lib

Post by Ulydev » Mon Jul 27, 2015 6:04 pm

Neat ! Thank you :awesome:

That'd be very much appreciated if you put the source for the example shown here, with dragging features : https://www.youtube.com/watch?t=13&v=LFBQypY7E3E

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests