Your browser does not support the HTML canvas tag.



Home

//******************************************************************************
// ballbounce.for.java:	Applet
//
//******************************************************************************
// |] 4 |\| |\| 
import java.applet.*;
import java.awt.*;

public class ballbounce extends Applet
{
	   int iMaxX,
           iMaxY,
		   iX, iY,
		   iIteration,
		   iSpeed,
		   iBorder,
		   iXDir, iYDir,
		   iBallX, iBallY,
		   iRed, iGreen, iBlue;

	   Color  clrBackGround,
		  clrBall;
	   
	   private AudioClip sndStart,
			     sndStop,
		             sndBump;
	   	   
public ballbounce()
{
// TODO: Add constructor code here
}

public String getAppletInfo()
{
	return "Name: ballbounce\r\n" +
	       "Author: \r\n" +
	       "Created with Microsoft Visual J++ Version 6.0";
}

public void init()
{
	iMaxX = 255;
	iMaxY = 255;
	
	iX = 50;   //Starting pos for ball
	iY = 100;   //  "   "   "   "   "
	
	iIteration = 1500;
	iSpeed     =  100;
	iBorder    =   25;

	iXDir = +1;
	iYDir = +1;
	
	iBallX = Integer.parseInt(getParameter("BallX") );
	iBallY = Integer.parseInt(getParameter("BallY") );
	
	iRed    = Integer.parseInt(getParameter("Red") );
	iGreen  = Integer.parseInt(getParameter("Green") );
	iBlue   = Integer.parseInt(getParameter("Blue") );
	
	resize( iMaxX, iMaxY );
	
	clrBackGround  = new Color (   0,   0,   0 );
	//clrBall        = new Color ( iRed, iGreen, iBlue );
	
	sndStart = getAudioClip (getDocumentBase(), "start.au" );
	sndStop  = getAudioClip (getDocumentBase(), "stop.au" );
	sndBump  = getAudioClip (getDocumentBase(), "bump.au" );
		

// TODO: Place additional initialization code here
}

public void paint(Graphics g)
{
		g.setColor ( clrBackGround );
		g.fillRect ( 0, 0, iMaxX, iMaxY );
		
		//Border
		for ( int i = 0 ; i < iBorder+1 ; i++ )
		{
		  	g.setColor ( new Color ( 10*i, 0, 0 ));
			g.drawRect ( i, i, iMaxX-i-i-1, iMaxY-i-i-1);
		}
        
		sndStart.play();
		
		for ( int i = 0 ; i < iIteration ; i++ )
		{
			iRed = iRed-3;
			iGreen = iGreen+1;
			iBlue  = iBlue+2;
			g.setColor ( new Color ( iRed, iGreen, iBlue ) );
			g.fillOval ( iX, iY, iBallX, iBallY );
			
			try   { Thread.sleep ( iSpeed ); }
			catch ( InterruptedException ex )
		      { stop(); }
			
			if ( i < iIteration-1 ) 
			{
			g.setColor ( clrBackGround );
			g.fillOval ( iX, iY, iBallX, iBallY );
			}
			
			if ( iX < iBorder+3 )
			{ iXDir = +1;
			  iSpeed = 2*iSpeed/3;
			  sndBump.play();
			}
			if ( iY < iBorder+3 )
			{ iYDir = +1;
			  iSpeed = 2*iSpeed/3;
			  sndBump.play();
			}
			
			if ( iX > iMaxX-iBallX-iBorder-3 )
			{ iXDir = -1;
			  iSpeed = 2*iSpeed/3;
			  sndBump.play();
			}
			if ( iY > iMaxY-iBallY-iBorder-3)
			{ iYDir = -1;
			  iSpeed = 2*iSpeed/3;
			  sndBump.play();
			}
			
			iX += iXDir;
			iY += 2*iYDir;
			
		}
		
		sndStop.play(); 
}

public void start() { }

public void stop()  
{ 
	sndStart.stop(); 
	sndStop.stop();  
	sndBump.stop();  
}


}