home *** CD-ROM | disk | FTP | other *** search
- import com.next.gt.Actor;
- import com.next.gt.Gamelication;
- import java.awt.Image;
-
- public class Ball extends Actor {
- int bounceCount;
- Image theImage;
- int MAX_VELOLCITY_X = 200;
- int MAX_VELOLCITY_Y = 1200;
-
- Ball(Gamelication var1) {
- super.owner = var1;
- super.x = Math.random() * (double)super.owner.getSize().width;
- super.y = Math.random() * (double)super.owner.getSize().height;
- super.velocity_x = (double)((int)Gamelication.randBetween((double)0.5F, (double)1.5F) * 2 - 1) * Math.random() * (double)this.MAX_VELOLCITY_X;
- super.velocity_y = Math.random() * (double)this.MAX_VELOLCITY_Y;
- this.bounceCount = 0;
- this.theImage = super.owner.getImage(super.owner.getCodeBase(), "images/pingPong.gif");
- ((Actor)this).setImage(this.theImage, 4, 16);
- super.currentFrame = (int)Gamelication.randBetween((double)0.0F, (double)super.numFrames);
- super.wrapAround = false;
- }
-
- public void calculateNewPosition() {
- super.calculateNewPosition();
- if (super.x > (double)(super.owner.getSize().width - super.width)) {
- super.velocity_x = -super.velocity_x;
- super.x = (double)(super.owner.getSize().width - super.width);
- } else if (super.x < (double)0.0F) {
- super.velocity_x = -super.velocity_x;
- super.x = (double)0.0F;
- }
-
- if (super.y > (double)(super.owner.getSize().height - super.height)) {
- super.velocity_y = -super.velocity_y * (double)0.75F;
- super.y = (double)(super.owner.getSize().height - super.height);
- if (this.bounceCount++ > 8) {
- this.bounceCount = 0;
- super.velocity_y = -Math.random() * (double)this.MAX_VELOLCITY_Y;
- }
- } else if (super.y < (double)0.0F) {
- super.velocity_y = -super.velocity_y * (double)0.75F;
- super.y = (double)0.0F;
- }
-
- super.velocity_y += (double)5.0F;
- }
- }
-