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

Report as inappropriate.

Skintkingle
Skintkingle presents ...

2008/7/11

GravityClass

I quickly knocked up a couple of Gravity methods in a class, along with some bouncing effects just
to test how some stuff works... feel free to comment, and/or use it if you like.
everything par the hippo is set to move randomly left or right, at the start.
Hippo's at weight 10.
Steel ball's at weight 4.
Bouncy balls are at weight 1.
weight works on a scale of 1-10, 10 being the heaviest.
Call:
void actGravity(int weight); // brings gravity into effect.
void bounce(int weight); // bounces if the object reaches the bottom of the world.
void moveHorizontal(int speed); // bounces off the sides of the world.
int getNewSpeed(int speed); // returns a new speed if you have collided with any side (primitive friction).
Edit: BugFix with friction.
Edit: Added 2 new functions:
void wrapHorizontal(); // wraps the object when it meets the sides.
void wrapVertical(); // wraps the object when it meets the top or bottom
the little balls now wrap horizontally,
the metal balls wrap horizontally and vertically.
(note: wrapping must be put in before a bounce)
(another) Edit:
added something just for convenience in the code:
boolean detectCollision(Class item, int xcord, int ycord) // call this, first parameter asks for an object
of a class, second 2 parameters ask for the direction away from you to check.
this will return a bool true, if there is an object there.
and false if not.

5703 views / 28 in the last 7 days

1 vote | 0 in the last 7 days

Tags: simulation physics demo

open in greenfoot
Your browser does not support the canvas tag.
A new version of this scenario was uploaded on Fri Jul 11 23:03:26 UTC 2008
A new version of this scenario was uploaded on Sat Jul 12 02:22:10 UTC 2008
A new version of this scenario was uploaded on Sat Jul 12 14:36:36 UTC 2008
delmardelmar

2008/7/12

Since the last update, the metal ball behaves strangely... (It doesn't bounce, but just falls through the floor and into the ceiling again.)
SkintkingleSkintkingle

2008/7/12

because the metal ball has horizontal wrapping AND vertical wrapping, it falls through the bottom to the top, and from the top to the bottom (if it ever happened)... and from left to right/right to left.. the small balls only have horizontal wrapping.
A new version of this scenario was uploaded on Sat Jul 12 20:18:10 UTC 2008
JMollerJMoller

2012/4/27

excuse me Skintkingle, would it be alright if i used some of your code for a simulation project im working on? Cheers Jason

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

Who likes this?

LusT