★ wanayoo — archive 1999 http://www.webtechniques.com/sourcecode/1999/11/java/1.lstNouvelle recherche | Portail wanayoo

 
| home | current issue | archives | source code | events | demo express | search | editorial calendar | advertising | customer service | author guidelines | jobs | about

S O U R C E   C O D E / 1999 / 11 / java / 1.lst

// A simple class to hold the ball definition

public class Ball
{
public int dir = 1;  // direction of travel
public double x=0;   // current X
public double y=0;   // current y
public int maxheight=100;  // Y limit
public int maxwidth=100;   // X limit
public double speed=.1;    // step size for X
public java.awt.Color color;  // color

public void step()
  {
  x+=dir * speed;   // move X to next spot
  if (x>maxwidth)   // bounce off left/right wall
    {
    x-=speed;
    dir=-dir;
    }
  else if (x<0)
    {
    x+=speed;
    dir=-dir;
    }
 // describe bouncing with a sine wave
  y=Math.abs(Math.sin(x)*maxheight);
  }
}


| home | current issue | archives | source code | demo express | events | search | editorial calendar | advertising | customer service | author guidelines | jobs | about




Entire contents copyright 1996-2000 CMP Media Inc.
Read our privacy policy.