This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

Busch2207
Busch2207 presents ...

2011/11/23

Gravity Engine

Move your mouse over the screen.
Press x or y to create balls, where the mouse is!
Press c to clear all balls.
I added a maximum of 100 balls, so don't be surprised if the balls suddenly remove, by creating new one! ;)

The blue balls and red balls are affected by the gravitation.
The blue balls swim on the water, the red ones not.
The yellow balls fly upwards!
The green balls are not affected by any gravitation, but they are getting slower, cause of the air resistance.

(P.s.: If you want, you are of course allowed to copy this scenario and use it for your own projects.)

9706 views / 1327 in the last 7 days

18 votes | 0 in the last 7 days

Tags: with-source

open in greenfoot
Your browser does not support the canvas tag.
tylerstylers

2012/5/12

the balls get stuck on the walls
How have you made it that the balls bounce off? This means how can they know how the earth looks like where they are at the moment?
Busch2207Busch2207

2012/9/23

The method 'getMaterialAt(int x, int y)' returns the Material at the given Location. I initialized some points around the middle of the balls, that have to be checked for Material (In the constructor of tje class Points are the points setted with the method 'setOffset(int [] x,int [] y)'). And when a ball wants to move at a location where solid material is, I calculate the degrees it has to bounce of it.
Ok that sounds a little difficult but I'll try to use this. Thank you.
Gevater_Tod4711Gevater_Tod4711

2012/10/15

I need your help again: I think see where the balls bounce off (in the souce) but what I don't understand is how the balls bouce off with an angle different to the angle they had before. So, how can the balls know how is the angle of the earth?
A new version of this scenario was uploaded on Mon Oct 15 16:58:07 UTC 2012
Busch2207Busch2207

2012/10/15

First I work out the angle of the ground (from line 284-307). I go from the angle of incidence 180 degrees in both directions (+1 degree each check) and check if the object is in solid material at the given location or not. (line 287-294). If it's not in solid Material, I remember the Point and store him. (195-304) And then I calculate the new angle, with angle of incidence is equal to angle of reflection. (308-315)
Gevater_Tod4711Gevater_Tod4711

2012/10/17

Thank you. Now I understood. It was realy hard to integrate it into my scenario but now I've got it.
ROCKY_BALBOAROCKY_BALBOA

2013/6/7

can any on help me with the programing side of gravity
softwhizjxsoftwhizjx

2014/8/7

Thank you! Just what I needed!

See all comments

Want to leave a comment? You must first log in.

Who likes this?

Entity1037 softwhizjx Kartoffelbrot JetLennit MatheMagician Game/maniac SPower camiloab01 tylers spaceblue programmer22 Scaldren tellhowto Advenging K_O_P AwesomeNameGuy darkmist255 bourne