/* * Ball.java * * Created on July 9, 2004, 11:38 AM */ /** * * @author levenick */ import java.awt.*; public class Ball extends FilledCircle { public static int GRAVITY=1; private int vx, vy; //private int nuX=100, nuY=100; /** Creates a new instance of Ball */ public Ball() { } public Ball(int x, int y, int r, Color c) { super(x,y,r,c); } public Ball(int x, int y, int r, Color c, int vx, int vy) { this(x,y,r,c); this.vx = vx; this.vy = vy; } public void badstep() { x += vx; y += vy; vy += GRAVITY; if (y+radius > BallFrame.HT) { // if it hit the wall vy = -vy; // reverse direction System.out.println("vy=" + vy + " y=" + y); } } public void betterstep() { x += vx; y += vy; if (y+radius > BallFrame.HT) { // if it hit the wall vy = -vy*9/10; // reverse direction System.out.println("vy=" + vy + " y=" + y); } else vy += GRAVITY; } public void step() { x += vx; int bottomY = BallFrame.HT-(radius+y); if (vy >= bottomY) { //System.out.println("vy=" + vy + " y=" + y); int bounceHt = vy - bottomY; // how high it bounces this step y = BallFrame.HT - (radius + bounceHt); // the y-coord after this step vy = -(vy-1)*9/10; } else { y += vy; vy += GRAVITY; } } /*public void unpaint(Graphics g) { Color oldColor = getColor(); setColor(Color.WHITE); paint(g); setColor(oldColor); }*/ /*public void update() { x = nuX; y = nuY; }*/ /*public void step() { nuX += vx; nuY += vy; vy += GRAVITY; if (nuY>300-radius) { vy = -vy; nuY = 300-radius; } if (nuY-radius <0) { vy = -vy; nuY = radius; } }*/ }