Gravitonik

Show off your games, demos and other (playable) creations.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Gravitonik

Post by nevon »

What I like most about this game is the fact that you can run around a planet so fast that you'll just fly off into infinity.

Seriously though, great work! It's one of the best looking games I've seen made with Löve. The menu screen is especially well made.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Gravitonik

Post by TechnoCat »

nevon wrote:What I like most about this game is the fact that you can run around a planet so fast that you'll just fly off into infinity.
Hahahaha, I just tried that, it was awesome. :megagrin:
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Gravitonik

Post by nevon »

I've been looking through your code, trying to find the part that deals with the planets' gravity and how it affects the players direction and velocity, but I haven't been able to find it (the code is quite sparsely commented). If you would be so kind as to explain it to me, or at least tell me which part that is relevant, that would be great!

I'm asking because I'm trying to implement something with physics similar to that of a pool game, but with certain static bodies that attract the balls if they are close enough - very much like your planets.
User avatar
middlerun
Citizen
Posts: 64
Joined: Tue Nov 25, 2008 4:31 am
Location: Sydney, Australia
Contact:

Re: Gravitonik

Post by middlerun »

No problem. The gravity is just a straightforward implementation of Newton's Law of Universal Gravitation. Here's the relevant bits, I trimmed out some other stuff:

Code: Select all

force_x = 0 -- Start with zero force
force_y = 0
for i = 1, numplanets, 1 do -- Iterate through each planet and calculate the force with which it attracts the spaceman
  dist = math.sqrt((p_pos_x[i] - sm_pos_x)^2 + (p_pos_y[i] - sm_pos_y)^2) -- This line calculates the distance between the spaceman and the planet (Pythagoras' theorem)

...Some other stuff...

  if dist ~= 0 then -- This is to avoid potential divide by zero errors, because at one point the code was buggy and it was possible to fall under the planet's surface so the distance could be zero
    force = (G * p_mass[i] * sm_mass) / dist^2 -- Calculate gravitational force using Newton's Law. G is just a constant I tweaked until it seemed good
    dir_x = (p_pos_x[i] - sm_pos_x) / dist -- Calculate the direction the force is pulling
    dir_y = (p_pos_y[i] - sm_pos_y) / dist
    force_x = force_x + force * dir_x - 0.0002 * sm_v_x -- Calculate the gravitational force due to this planet as separate x and y components and add it to the running total
    force_y = force_y + force * dir_y - 0.0002 * sm_v_y
  end
end

...Some other stuff...

sm_acc_x = sm_mass * force_x -- Newton's 2nd law, though I just realised I wrote it wrong. It should be sm_acc_x = force_x / sm_mass, not that it matters that much since the spaceman's mass doesn't change and the units of mass and force are arbitrary
sm_acc_y = sm_mass * force_y
sm_v_x = sm_v_x + sm_acc_x -- Update velocity
sm_v_y = sm_v_y + sm_acc_y
sm_pos_x = sm_pos_x + sm_v_x * dt -- Update position
sm_pos_y = sm_pos_y + sm_v_y * dt
The variables beginning with p_ are for planets, and the ones beginning with sm_ are for the spaceman.

As you can see the x and y components for pretty much everything are calculated separately. I'm not 100% sure but I think I could even run the Law of Gravitation separately for x and y [EDIT: Actually I'm pretty sure that wouldn't work]. I guess I should add all these comments to the code, I'm terrible about comments.

In other news, the game is coming along gradually but nicely. I've got about 11 levels done now, plus new planet styles, and lots of bugfixes and small cosmetic changes. Though it will still be at least a week to the final release, making levels takes longer than I expected.
Last edited by middlerun on Fri Jan 29, 2010 1:35 pm, edited 1 time in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Gravitonik

Post by bartbes »

About your guessed G, in real life it's 6.6726*10^-11 Nm²/kg². Just wanted to tell you.
And the formula was as I expected: F = G * M * m / R^2 (M being the mass of the large object, m of the small, although it doesn't really matter which is which.)
User avatar
middlerun
Citizen
Posts: 64
Joined: Tue Nov 25, 2008 4:31 am
Location: Sydney, Australia
Contact:

Re: Gravitonik

Post by middlerun »

Yeah, I know. But if I'd used that I would have had to use ridiculously large values for the planet masses or the spaceman's mass. So I lie. :megagrin:
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Gravitonik

Post by Robin »

bartbes wrote:About your guessed G, in real life it's 6.6726*10^-11 Nm²/kg². Just wanted to tell you.
And the formula was as I expected: F = G * M * m / R^2 (M being the mass of the large object, m of the small, although it doesn't really matter which is which.)
You know, funny you bring this up.

We were explained exactly this formula on school today. Of course, I knew it already. ;)
Help us help you: attach a .love.
User avatar
Fourex
Citizen
Posts: 53
Joined: Tue Nov 10, 2009 2:33 am
Location: Earth

Re: Gravitonik

Post by Fourex »

Great game! It's the only game I've seen in Löve that's close to being finished. You've got a great concept going! There's just one thing; the controls for rotating the space man feel very sensitive. Maybe put a little rotational friction on him? Right now it's hard to point him in the right direction quickly, without over-rotating. Oh, and it was very easy to figure out the goal, and the controls.
User avatar
middlerun
Citizen
Posts: 64
Joined: Tue Nov 25, 2008 4:31 am
Location: Sydney, Australia
Contact:

Re: Gravitonik

Post by middlerun »

Hi everyone, I just thought I should let everyone know what's going on with Gravitonik, since I kind of disappeared after stating the game would be finished in a matter of weeks. Unfortunately life has interfered as it so often does, I got a job and now I'm back at uni and don't have a lot of time to spend working on levels, which is a shame because I'm only a few levels away from finishing the game. I plan on finishing it eventually, but in the meantime here's what I've got so far:

Gravitonik v0.1.7

The levels without names are just placeholders, so is the "random level generator". And the last level is nowhere near finished. Apart from that most of it is done.
Last edited by middlerun on Wed Nov 10, 2010 11:49 am, edited 2 times in total.
User avatar
steventrouble
Prole
Posts: 5
Joined: Tue Dec 01, 2009 3:00 am

Re: Gravitonik

Post by steventrouble »

Rofl, the artwork and performance is amazing, but there's no limit to how fast I can run on a planet... I kept running around until my sprite became a single sprite again, and I jumped about 18 minutes ago, and I'm still flying outward. :rofl:
Post Reply

Who is online

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