001    // Shrinker.java
002    // Created: Thursday, September 23, 1999 10:24:26 PM
003    
004    package ballworld;
005    
006    import cs101.lang.Animate;
007    
008    /**
009     * A ball that falls and shrinks at the same time.
010     *
011     * @author (original author unknown)
012     * @author Patrick G. Heck, gus.heck@olin.edu
013     * @version $Id: Shrinker.java,v 1.2 2003/09/11 21:35:37 gus Exp $
014     */
015    public class Shrinker implements Animate, Ball
016    {
017            double x;
018            double y;
019            double dx;
020            double dy;
021            double radius= 5;
022            World world;
023    
024            /**
025             * Create a shrinker at a given point and give it random velocities
026             * @param x The x coordinate to start at.
027             * @param y The y coordinte to start at
028             */        
029            public Shrinker(double x, double y) {
030                    dx= Math.random()-0.5;
031                    dy= Math.random()-0.5;
032                    this.x= x;
033                    this.y= y;
034            }
035            
036            /**
037             * Create a default shrinker. This version starts at 0,0 and has no initial
038             * velocity.
039             */        
040            public Shrinker() {
041            }
042            
043            public double getX() {return x;}
044            public double getY() {return y;}
045            public double getRadius() {return radius;}
046            
047            public void setWorld(World theWorld) {
048                    this.world= theWorld;
049            }
050            
051            public void userClicked(double x, double y) {}
052            public void userTyped(char key) {}
053            
054            public void act() {
055                    radius-=0.03;
056                    x+= dx;
057                    y+= dy;
058                    dy-= 0.01;
059                    if (radius<0.01) {
060                            world.removeBall(this);
061                    }
062            }
063                    
064    }