Report as inappropriate.
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.
Want to leave a comment? You must first log in.
2008/7/12
2008/7/12
2012/4/27