/*
Copyright F. P. Marin ( April 07 13:12:53 1997 )
E-mail: felix@bloch.ciens.ucv.ve
Permission to use, copy, modify and distribute this software and its
documentation for NON-COMERCIAL purposes and without fee is hereby
granted provided that this copyright notice appears in all copies.
F. P. Marin makes no representations or warranties about the suitability
of the software, either express or implied, including but no limited to
the implied warranties of merchantability, fitness for a particular
purpose, or non-infringement. F. P. Marin shall not be liable for any
damage suffered by license as a result of using, modifying or
distributing this software or its derivatives.
HTML code is
*/
import java.awt.*;
public class PacmanGas extends java.applet.Applet implements Runnable
{
boolean running;
Graphics gr;
Image img;
int delay,nactual,xf,yf;
Pacman pm[];
Thread pacmanthread=null;
public void init()
{
int minradius,maxradius,maxspeed,n;
String s=getParameter("npacmans");
if ( s!=null ) {
n=Integer.parseInt(s);
if ( n<1 ) n=1;
} else n=1;
pm=new Pacman[n];
s=getParameter("maxspeed");
if ( s!=null ) {
n=Integer.parseInt(s);
if ( n<3 ) n=3;
} else n=3;
maxspeed=n;
s=getParameter("minradius");
if ( s!=null ) {
n=Integer.parseInt(s);
if ( n<3 ) n=3;
if ( n>(size().width/10) ) n=size().width/10;
} else n=3;
minradius=n;
s=getParameter("maxradius");
if ( s!=null ) {
n=Integer.parseInt(s);
if ( n<3 ) n=3;
if ( n>(size().width/10) ) n=size().width/10;
} else n=3;
maxradius=n;
if ( minradius>maxradius ) {
n=minradius;
minradius=maxradius;
maxradius=n;
}
s=getParameter("delay");
if ( s!=null ) {
n=Integer.parseInt(s);
if ( n<11 ) n=42;
} else n=42;
delay=n;
nactual=0;
xf=size().width - 1;
yf=size().height - 1;
for ( n=0 ; n0.0 ) {
Dy/=Dx;
Dx*=Math.sqrt(1.0 + Dy*Dy);
}
if ( Dx<=(r + pg.pm[I].r - 1) ) {
angle=(int)(360.0*Math.random());
pg.pm[I].angle=(int)(360.0*Math.random());
return col=pg.pm[I].col=true;
}
}
return false;
}
boolean move()
{
Oldx=x;
Oldy=y;
move((int)(x + vx + 0.5),(int)(y + vy + 0.5));
Inx=( ( r<=x ) && ( x<=xf ) );
Iny=( ( r<=y ) && ( y<=yf ) );
if ( ( Inx ) && ( Iny ) ) {
if ( icrash() ) {
move(Oldx,Oldy);
Dx=vx;
vx=pg.pm[I].vx;
pg.pm[I].vx=Dx;
Dx=vy;
vy=pg.pm[I].vy;
pg.pm[I].vy=Dx;
return false;
}
} else {
move(Oldx,Oldy);
if ( !Inx ) vx=-vx;
if ( !Iny ) vy=-vy;
return false;
}
return true;
}
Color randColor()
{
int r,g,b;
r=(int)(256*Math.random());
g=(int)(256*Math.random());
b=(int)(256*Math.random());
return new Color(r,g,b);
}
}