Gravity Balls!

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Gravity Balls!

Post by Tjakka5 »

User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: Gravity Balls!

Post by Doctory »

its quite something ;)
why wont you share the code >:C
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: Gravity Balls!

Post by Tjakka5 »

I might later, if I get some more things done like, cleaner code, camera module, and a stable orbit :p

Example of "bad" code:

Code: Select all

function planet.update(dt)
	for i, v in ipairs(planetMap) do
		local dist = math.sqrt((v.xPos - player.xPos)^2 + (v.yPos - player.yPos)^2)
		if dist <= v.inf + 4 then
			v.isColliding = true
			local angle = math.atan2((v.yPos - player.yPos), (v.xPos - player.xPos))
			player.addVel((v.gravity*(v.inf*0.01)*math.cos(angle)), (v.gravity*(v.inf*0.01))*math.sin(angle), dt)
		else
			v.isColliding = false
		end

		for i, f in ipairs(planetMap) do
			if v ~= f then
				local dist = math.sqrt((v.xPos - f.xPos)^2 + (v.yPos - f.yPos)^2)
				if dist <= v.inf + f.inf then
					local angle = math.atan2((v.yPos - f.yPos), (v.xPos - f.xPos))
					planet.addVel(f, (v.gravity*(v.inf*0.01)*math.cos(angle)), (v.gravity*(v.inf*0.01))*math.sin(angle), dt)
				end
			end
		end
		planet.move(v, dt)
	end
end
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: Gravity Balls!

Post by veethree »

I made something similar a while back. The gravity calculation is a dirty implementation of Newton's law of universal gravitation. Collision is handled by love.physics.

You can spawn objects with the mouse, Right click for static, left click for dynamic.
With dynamic objects you can also click and drag to spawn them with some velocity.

Code could be cleaner. There's probably mad bugs. Look at the source at your own risk.
Attachments
Planet Physix.love
(81.2 KiB) Downloaded 122 times
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: Gravity Balls!

Post by HugoBDesigner »

Nice little concept! I also made something similar a while ago (you can still find it HERE), but yours seems a lot more "professional" than mine (mine was just a random doodle, but still).
Am I the ONLY one who thought it was a pun about Gravity Falls?
@HugoBDesigner - Twitter
HugoBDesigner - Blog
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: Gravity Balls!

Post by Tjakka5 »

HugoBDesigner wrote:Nice little concept! I also made something similar a while ago (you can still find it HERE), but yours seems a lot more "professional" than mine (mine was just a random doodle, but still).
Am I the ONLY one who thought it was a pun about Gravity Falls?
Actually, that is correct! xD
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Gravity Balls!

Post by Robin »

HugoBDesigner wrote:Am I the ONLY one who thought it was a pun about Gravity Falls?
Didn't think it was a pun, but I was confused for a bit.
Help us help you: attach a .love.
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: Gravity Balls!

Post by Tjakka5 »

I recoded some stuff, made things neater, removed the player completely (Because it was basically a "ball" with no gravity) and added 3 cool things.

1. Ooooh snap, collision detection and resolving... somewhat.
It's very basic, and not good, and it even has a bug which is now a feature, and that is...
2. ...MERGING PLANETS!
Oooooooh snap.
Planets can now merge together because of their gravity and create a planet with triple or quadruple of infinitly its gravity. Dayum
3. Oh, and some lines between planets which are in their spheres of influences. meh.

Also, binary orbits! Whoo
https://www.youtube.com/watch?v=LGnyJyt ... e=youtu.be
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest