PacWars


//****ALL CODE COPYRIGHT © DAVID KAPLAN 1999****\\
//davkapl@aol.com
//http://members.aol.com/davkapl
//will work for low wages!
import java.awt.*;
import java.applet.Applet;
import java.util.Vector;
import java.applet.AudioClip;
import java.net.URL;

public class Pacman extends Applet	{
	final static int appletWidth=425, appletHeight=440;
	static Pacmen p=null, p2=null;
	Wall w=null;
	Food f=null;
	static int level, score, lives;
	int size;
	boolean started=false;
	static Vector level1, level2, level3, levelCustom, food1, food2, food3, foodCustom;
	static Vector sleepThreadVector;
	static Graphics gfx;
	static boolean[][] customArray;
	static boolean mapEditorOn;
	Choice mapChoice, instructions, colorChoice, editorInstructions, playerNumberChoice, bulletChoice;
	setPanel choicePanel;
	ColorThread ct;
	static Vector[] foodArray;
	static char[][] foodCustomArray;
	static Vector bulletVector, mineVector;
	static Font normalFont, endFont;
	static AudioClip wc=null;
	static AudioClip gc=null;
	static AudioClip ac=null;
	static AudioClip ec=null;
	static URL baseURL;
	static boolean ended;
	static char editorSet;
	static boolean soundsLoaded=false;
	public void init()	{
		Pacmen.g=getGraphics();
		level1=new Vector();
		level2=new Vector();
		level3=new Vector();
		levelCustom=new Vector();
		sleepThreadVector=new Vector();
		gfx=getGraphics();
		initLevel1();
		level=0;
		choicePanel=new setPanel(425,82);
		setLayout(new BorderLayout(4,4));
		add("South",choicePanel);
		mapChoice=new Choice();
		mapChoice.addItem("Map 1: The Fork");
		mapChoice.addItem("Map 2: Garden Maze");
		mapChoice.addItem("Map 3: Ode to Tetris");
		mapChoice.addItem("Map 4: Custom");
		mapChoice.addItem("Level Editor");
		choicePanel.add(mapChoice);
		instructions=new Choice();
		instructions.addItem("INSTRUCTIONS (pull down)");
		instructions.addItem("The object of the game is to");
		instructions.addItem("kill the other Pac-person.");
		instructions.addItem("Player one moves with W, A, S, D");
		instructions.addItem("shoots with space, and lays mines with B.");
		instructions.addItem("Player two moves with the arrow");
		instructions.addItem("keys, shoots with return, and");
		instructions.addItem("lays mines with the apostrophe key.");
		instructions.addItem("Copyright © 1999 David Kaplan");
		instructions.addItem("davkapl@aol.com");
		instructions.addItem("http://members.aol.com/davkapl");
//		instructions.addItem("Send shareware fee to David Kaplan");
//		instructions.addItem("75 Fleur Place");
//		instructions.addItem("Atherton, CA, 94027 (USA)");
		choicePanel.add(instructions);
		colorChoice=new Choice();
		editorInstructions=new Choice();
		colorChoice.addItem("Color List (for editor)");
		colorChoice.addItem("Random");
		colorChoice.addItem("Red");
		colorChoice.addItem("Green");
		colorChoice.addItem("Blue");
		colorChoice.addItem("Magenta");
		colorChoice.addItem("Yellow");
		colorChoice.addItem("Orange");
		colorChoice.addItem("White");
		choicePanel.add(colorChoice);
		editorInstructions.addItem("Level Editor Instructions");
		editorInstructions.addItem("Click once to draw a wall,");
		editorInstructions.addItem("and click again to erase it.");
		editorInstructions.addItem("To place an ammo pack, hold");
		editorInstructions.addItem("down the 'a' key and click.");
		editorInstructions.addItem("To place mine ammo, hold down");
		editorInstructions.addItem("the 'm' key and click.  To erase");
		editorInstructions.addItem("an ammo pack, hold down 'a' and");
		editorInstructions.addItem("click again; hold down 'm' and");
		editorInstructions.addItem("click to erase mine ammo.");
		editorInstructions.addItem("Select wall color using the");
		editorInstructions.addItem("pull-down.  Then select the");
		editorInstructions.addItem("'Custom' map and enjoy!");
		choicePanel.add(editorInstructions);
		customArray=new boolean[17][16];
		foodCustomArray=new char[17][16];
		ct=new ColorThread();
		playerNumberChoice=new Choice();
		playerNumberChoice.addItem("2 Players");
		playerNumberChoice.addItem("3 Players");
		playerNumberChoice.addItem("4 Players");
		bulletChoice=new Choice();
		bulletChoice.addItem("Bullet Speed");
		bulletChoice.addItem("6x");
		bulletChoice.addItem("4x (default)");
		bulletChoice.addItem("3x");
		bulletChoice.addItem("2x");
		choicePanel.add(bulletChoice);
		food1=new Vector();
		food2=new Vector();
		food3=new Vector();
		foodCustom=new Vector();
		initFood1();
		initFood2();
		initFood3();
		foodArray=new Vector[4];
		foodArray[0]=food1;
		foodArray[1]=food2;
		foodArray[2]=food3;
		foodArray[3]=foodCustom;
		initFoodCustom();
		bulletVector=new Vector();
		mineVector=new Vector();
		normalFont=new Font("Geneva",Font.PLAIN,10);
		endFont=new Font("Geneva",Font.BOLD,30);
		gfx.setFont(normalFont);
		baseURL=getCodeBase();
		ended=false;
		editorSet='w';
			p=new Pacmen(25,25,true);
			p2=new Pacmen(375,350,false);
	}
	public void loadSounds()	{
		try	{
			wc=getAudioClip(new URL("http://members.aol.com/davkapl/PacWars/winner.au"));
		} catch(Exception e)	{}
		try	{
			gc=getAudioClip(new URL("http://www.best.com/~jfn/gunshot.au"));
		} catch(Exception e)	{}
		try	{
			ac=getAudioClip(new URL("http://www.best.com/~jfn/applause.au"));
		} catch(Exception e)	{}
		try	{
			ec=getAudioClip(new URL("http://www.best.com/~jfn/explosion.au"));
		} catch(Exception e)	{}
		try	{
			play(new URL("http://www.best.com/~jfn/letsrock.au"));
		} catch(Exception e)	{}
		soundsLoaded=true;
	}
	public void start()	{
			repaint();
			loadSounds();
			repaint();
			if (started)	{
				p.start();
				p2.start();
			}
	}
	public void stop()	{
		p.stop();
		p2.stop();
	}
	public void paint(Graphics g)	{
		Food f;
		g.setColor(Color.black);
		g.fillRect(0,0,appletWidth,appletHeight);
	if (!ended)	{
		if (level==1)	{
			for (int i=0;i<level1.size();i++)	{
				w=(Wall)level1.elementAt(i);
				w.draw(g);
			}
			for (int i=0;i<foodArray[0].size();i++)	{
				f=(Food)foodArray[0].elementAt(i);
				f.draw(g);
			}
		}
		else if (level==2)	{
			for (int i=0;i<level2.size();i++)	{
				w=(Wall)level2.elementAt(i);
				w.draw(g);
			}
			for (int i=0;i<foodArray[1].size();i++)	{
				f=(Food)foodArray[1].elementAt(i);
				f.draw(g);
			}
		}
		else if (level==3)	{
			for (int i=0;i<level3.size();i++)	{
				w=(Wall)level3.elementAt(i);
				w.draw(g);
			}
			for (int i=0;i<foodArray[2].size();i++)	{
				f=(Food)foodArray[2].elementAt(i);
				f.draw(g);
			}
		}
		else if (level==4)	{
			if (colorChoice.getSelectedIndex()==2)	{
				Wall.wallColor=Color.red;
				Wall.bricks=true;
			}
			else if (colorChoice.getSelectedIndex()==3)	{
				Wall.wallColor=Color.green;
				Wall.bricks=true;
			}
			else if (colorChoice.getSelectedIndex()==4)	{
				Wall.wallColor=Color.blue;
				Wall.bricks=true;
			}
			else if (colorChoice.getSelectedIndex()==5)	{
				Wall.wallColor=Color.magenta;
				Wall.bricks=true;
			}
			else if (colorChoice.getSelectedIndex()==6)	{
				Wall.wallColor=Color.yellow;
				Wall.bricks=true;
			}
			else if (colorChoice.getSelectedIndex()==7)	{
				Wall.wallColor=Color.orange;
				Wall.bricks=true;
			}
			else if (colorChoice.getSelectedIndex()==8)	{
				Wall.wallColor=Color.white;
				Wall.bricks=true;
			}
			for (int i=0;i<levelCustom.size();i++)	{
				if (colorChoice.getSelectedIndex()==1)	{
					int r=(int)(Math.random()*225)+30;
					int green=(int)(Math.random()*195)+60;
					int b=(int)(Math.random()*165)+90;
					Wall.wallColor=new Color(r,green,b);
					Wall.bricks=false;
				}
				w=(Wall)levelCustom.elementAt(i);
				w.draw(g);
			}
			for (int i=0;i<foodArray[3].size();i++)	{
				f=(Food)foodArray[3].elementAt(i);
				f.draw(g);
			}
		}
	}
		else if (level==5)	{
			g.setColor(Color.red);
			for (int i=0;i<17;i++)	{
				for (int j=0;j<16;j++)	{
					if (customArray[i][j])
						g.fillRect(25*i,25*j,25,25);
				}
			}
			g.drawString("P1",25,35);
			g.drawString("P2",375,360);
			g.drawString("start",25,45);
			g.drawString("start",375,370);
			for (int i=0;i<17;i++)	{
				for (int j=0;j<16;j++)	{
					if ((foodCustomArray[i][j]=='a') || (foodCustomArray[i][j]=='m'))
						new Food(25*i,25*j,foodCustomArray[i][j], 4);
				}
			}
		}
		if (!soundsLoaded)	{
			g.setColor(Color.green);
			g.drawString("Please wait for the sounds to load...",200,200);
			g.drawString("This should take ~32 seconds on a 33.6 modem",200,215);
//			g.setColor(Color.red);
//			g.drawString("This game is shareware.  If you play it and enjoy it, send $2 to",30,50);
//			g.drawString("the address below.  If you wish to use the applet on your website,",30,65);
//			g.drawString("please acknowledge the author (David Kaplan) and send $10 to the address below.",30,80);
//			g.drawString("I will e-mail you the source code, too, once I receive the money.  Thank you.",30,95);
//			g.drawString("David Kaplan",30,110);
//			g.drawString("75 Fleur Place",30,125);
//			g.drawString("Atherton, CA (USA), 94027",30,140);
		}
		else if (!started)	{
			g.setColor(Color.green);
			g.drawString("Click to begin",200,200);
//			g.setColor(Color.red);
//			g.drawString("This game is shareware.  If you play it and enjoy it, send $2 to",30,50);
//			g.drawString("the address below.  If you wish to use the applet on your website,",30,65);
//			g.drawString("please acknowledge the author (David Kaplan) and send $10 to the address below.",30,80);
//			g.drawString("I will e-mail you the source code, too, once I receive the money.  Thank you.",30,95);
//			g.drawString("David Kaplan",30,110);
//			g.drawString("75 Fleur Place",30,125);
//			g.drawString("Atherton, CA (USA), 94027",30,140);
		}
		g.setColor(Color.white);
		g.fillRect(0,appletHeight-40,appletWidth,40);
		g.setColor(Color.black);
		if (level>0)
			Pacman.updateStatusBar();
		if ((level>0) && (started))	{
			if ((p.health==0) || (p2.health==0))	{
				boolean w=(p.health==0)?true:false;
				g.setFont(endFont);
				Color c=(!w)?Color.yellow:Color.blue;
				g.setColor(c);
				String s=(!w)?"Player One is the WINNER!":"Player Two is the WINNER!";
				g.drawString(s,10,200);
				g.setFont(normalFont);
			}
		}
	}
	public boolean keyDown(Event e,int key)	{
		if (key==1004)	{
			if (p2.checkUp())
				p2.dir='u';
			else
				p2.waitingUp=true;
		}
		if (key==1005)	{
			if (p2.checkDown())
				p2.dir='d';
			else
				p2.waitingDown=true;
		}
		if (key==1006)	{
			if (p2.checkLeft())
				p2.dir='l';
			else
				p2.waitingLeft=true;
		}
		if (key==1007)	{
			if (p2.checkRight())
				p2.dir='r';
			else
				p2.waitingRight=true;
		}
		if (key==119)	{
			if (p.checkUp())
				p.dir='u';
			else
				p.waitingUp=true;
		}
		if (key==115)	{
			if (p.checkDown())
				p.dir='d';
			else
				p.waitingDown=true;
		}
		if (key==97)	{
			editorSet='a';
			if (p.checkLeft())
				p.dir='l';
			else
				p.waitingLeft=true;
		}
		if (key==100)	{
			if (p.checkRight())
				p.dir='r';
			else
				p.waitingRight=true;
		}
		if (key==109)	{
			editorSet='m';
		}
	if (!ended)	{
		if (key==10)	{
			if (p2.ammo>0)	{
				p2.shoot();
			}
		}
		if (key==39)	{
			if (p2.mines>0)	{
				p2.mine();
			}
		}
		if (key==32)	{
			if (p.ammo>0)	{
				p.shoot();
			}
		}
		if (key==98)	{
			if (p.mines>0)	{
				p.mine();
			}
		}
	}
		Pacman.updateStatusBar();
		return super.keyDown(e,key);
	}
	public boolean keyUp(Event e, int key)	{
		if (key==1004)	{
			p2.waitingUp=false;
		}
		if (key==1005)	{
			p2.waitingDown=false;
		}
		if (key==1006)	{
			p2.waitingLeft=false;
		}
		if (key==1007)	{
			p2.waitingRight=false;
		}
		if (key==119)	{
			p.waitingUp=false;
		}
		if (key==115)	{
			p.waitingDown=false;
		}
		if (key==97)	{
			if (!(editorSet=='m'))
				editorSet='w';
			p.waitingLeft=false;
		}
		if (key==100)	{
			p.waitingRight=false;
		}
		if (key==109)	{
			if (!(editorSet=='a'))
				editorSet='w';
		}
		return super.keyDown(e, key);
	}
	public boolean mouseDown(Event e, int x, int y)	{
		if (!started)	{
			started=true;
			repaint();
			p.start();
			p2.start();
			ct.start();
			level=1;
		}
		if (mapEditorOn)	{
			if (editorSet=='w')	{
				int a1=x/25;
				int a2=y/25;
				if (!(((a1==1) && (a2==1)) || ((a1==15) && (a2==14))))	{
					customArray[a1][a2]=!customArray[a1][a2];
					repaint();
				}
			}
			else {
				int a1=x/25;
				int a2=y/25;
				if (!(((a1==1) && (a2==1)) || ((a1==15) && (a2==14))))	{
					if (foodCustomArray[a1][a2]!=editorSet)	{
						foodCustomArray[a1][a2]=editorSet;
					}
					else	{
						foodCustomArray[a1][a2]=' ';
					}
					repaint();
				}
			}
		}
		return super.mouseDown(e, x, y);
	}
	static public void updateStatusBar()	{
		gfx.setColor(Color.white);
		gfx.fillRect(0,appletHeight-40,425,40);
		gfx.setColor(Color.black);
		gfx.drawString("P1: ammo=" + p.ammo + " mines=" + p.mines + " health=" + p.health,0,appletHeight-30);
		gfx.drawString("P2: ammo=" + p2.ammo + " mines=" + p2.mines + " health=" + p2.health,225,appletHeight-30);
		gfx.setColor(Color.red);
		gfx.drawLine(10,appletHeight-28,70,appletHeight-28);
		gfx.drawLine(10,appletHeight-21,70,appletHeight-21);
		gfx.drawLine(355,appletHeight-28,415,appletHeight-28);
		gfx.drawLine(355,appletHeight-21,415,appletHeight-21);
		gfx.drawLine(70,appletHeight-28,70,appletHeight-21);
		gfx.drawLine(415,appletHeight-28,415,appletHeight-21);
		gfx.fillRect(10,appletHeight-28,p.health*2,7);
		gfx.fillRect(355,appletHeight-28,p2.health*2,7);
	}
	public void initLevel1()	{
		w=new Wall(0,0,425,false);
		level1.addElement(w);
		w=new Wall(0,375,425,false);
		level1.addElement(w);
		w=new Wall(0,25,150,true);
		level1.addElement(w);
		w=new Wall(0,200,175,true);
		level1.addElement(w);
		w=new Wall(400,25,150,true);
		level1.addElement(w);
		w=new Wall(400,200,175,true);
		level1.addElement(w);
		w=new Wall(100,275,50,false);
		level1.addElement(w);
		w=new Wall(175,275,75,false);
		level1.addElement(w);
		w=new Wall(275,275,50,false);
		level1.addElement(w);
		w=new Wall(50,325,50,false);
		level1.addElement(w);
		w=new Wall(325,325,50,false);
		level1.addElement(w);
		w=new Wall(125,300,50,true);
		level1.addElement(w);
		w=new Wall(275,300,50,true);
		level1.addElement(w);
		w=new Wall(150,325,25,false);
		level1.addElement(w);
		w=new Wall(250,325,25,false);
		level1.addElement(w);
		w=new Wall(200,325,50,true);
		level1.addElement(w);
		w=new Wall(50,200,50,true);
		level1.addElement(w);
		w=new Wall(25,275,50,false);
		level1.addElement(w);
		w=new Wall(350,200,50,true);
		level1.addElement(w);
		w=new Wall(350,275,50,false);
		level1.addElement(w);
		w=new Wall(50,100,75,true);
		level1.addElement(w);
		w=new Wall(50,50,50,false);
		level1.addElement(w);
		w=new Wall(350,100,75,true);
		level1.addElement(w);
		w=new Wall(325,50,50,false);
		level1.addElement(w);
		w=new Wall(100,225,225,false);
		level1.addElement(w);
		w=new Wall(100,100,100,false);
		level1.addElement(w);
		w=new Wall(225,100,100,false);
		level1.addElement(w);
		w=new Wall(100,150,75,true);
		level1.addElement(w);
		w=new Wall(125,50,50,true);
		level1.addElement(w);
		w=new Wall(150,125,75,true);
		level1.addElement(w);
		w=new Wall(200,150,125,true);
		level1.addElement(w);
		w=new Wall(250,125,75,true);
		level1.addElement(w);
		w=new Wall(275,50,50,true);
		level1.addElement(w);
		w=new Wall(300,150,75,true);
		level1.addElement(w);
		w=new Wall(175,50,75,false);
		level1.addElement(w);
		w=new Wall(200,25,25,true);
		level1.addElement(w);
	}
	public void initLevel2()	{
		w=new Wall(0,0,175,false);
		level2.addElement(w);
		w=new Wall(250,0,175,false);
		level2.addElement(w);
		w=new Wall(0,0,175,true);
		level2.addElement(w);
		w=new Wall(0,225,175,true);
		level2.addElement(w);
		w=new Wall(0,375,175,false);
		level2.addElement(w);
		w=new Wall(250,375,175,false);
		level2.addElement(w);
		w=new Wall(400,0,175,true);
		level2.addElement(w);
		w=new Wall(400,225,175,true);
		level2.addElement(w);
		w=new Wall(50,50,325,false);
		level2.addElement(w);
		w=new Wall(50,325,325,false);
		level2.addElement(w);
		w=new Wall(75,75,100,true);
		level2.addElement(w);
		w=new Wall(75,225,100,true);
		level2.addElement(w);
		w=new Wall(325,75,100,true);
		level2.addElement(w);
		w=new Wall(325,225,100,true);
		level2.addElement(w);
		w=new Wall(325,225,75,true);
		level2.addElement(w);
		w=new Wall(150,125,150,true);
		level2.addElement(w);
		w=new Wall(175,125,25,true);
		level2.addElement(w);
		w=new Wall(175,250,25,true);
		level2.addElement(w);
		w=new Wall(225,125,25,true);
		level2.addElement(w);
		w=new Wall(225,250,25,true);
		level2.addElement(w);
		w=new Wall(25,100,25,true);
		level2.addElement(w);
		w=new Wall(25,275,25,true);
		level2.addElement(w);
		w=new Wall(375,100,25,true);
		level2.addElement(w);
		w=new Wall(375,275,25,true);
		level2.addElement(w);
		w=new Wall(250,125,150,true);
		level2.addElement(w);
	}
	public void initLevel3()	{
		w=new Wall(0,0,100,false);
		level3.addElement(w);
		w=new Wall(325,375,100,false);
		level3.addElement(w);
		w=new Wall(50,50,50,false);
		level3.addElement(w);
		w=new Wall(50,75,50,false);
		level3.addElement(w);
		w=new Wall(325,300,50,false);
		level3.addElement(w);
		w=new Wall(325,325,50,false);
		level3.addElement(w);
		w=new Wall(150,25,50,false);
		level3.addElement(w);
		w=new Wall(150,50,50,false);
		level3.addElement(w);
		w=new Wall(225,325,50,false);
		level3.addElement(w);
		w=new Wall(225,350,50,false);
		level3.addElement(w);
		w=new Wall(0,150,100,true);
		level3.addElement(w);
		w=new Wall(0,325,75,true);
		level3.addElement(w);
		w=new Wall(25,175,25,true);
		level3.addElement(w);
		w=new Wall(25,350,25,true);
		level3.addElement(w);
		w=new Wall(25,275,25,true);
		level3.addElement(w);
		w=new Wall(50,125,75,true);
		level3.addElement(w);
		w=new Wall(50,250,75,true);
		level3.addElement(w);
		w=new Wall(100,125,50,false);
		level3.addElement(w);
		w=new Wall(100,175,100,true);
		level3.addElement(w);
		w=new Wall(100,325,75,false);
		level3.addElement(w);
		w=new Wall(125,275,75,false);
		level3.addElement(w);
		w=new Wall(125,100,50,false);
		level3.addElement(w);
		w=new Wall(150,175,50,true);
		level3.addElement(w);
		w=new Wall(150,350,25,true);
		level3.addElement(w);
		w=new Wall(175,150,50,true);
		level3.addElement(w);
		w=new Wall(175,250,50,true);
		level3.addElement(w);
		w=new Wall(225,100,75,false);
		level3.addElement(w);
		w=new Wall(225,125,25,true);
		level3.addElement(w);
		w=new Wall(225,200,50,true);
		level3.addElement(w);
		w=new Wall(250,25,25,true);
		level3.addElement(w);
		w=new Wall(250,50,75,false);
		level3.addElement(w);
		w=new Wall(250,175,50,true);
		level3.addElement(w);
		w=new Wall(250,275,50,false);
		level3.addElement(w);
		w=new Wall(275,250,50,false);
		level3.addElement(w);
		w=new Wall(300,125,100,true);
		level3.addElement(w);
		w=new Wall(350,75,75,true);
		level3.addElement(w);
		w=new Wall(350,200,75,true);
		level3.addElement(w);
		w=new Wall(375,100,25,false);
		level3.addElement(w);
		w=new Wall(375,25,25,true);
		level3.addElement(w);
		w=new Wall(375,200,25,false);
		level3.addElement(w);
		w=new Wall(400,0,75,true);
		level3.addElement(w);
		w=new Wall(400,150,100,true);
		level3.addElement(w);
	}
	public void initLevelCustom()	{
		levelCustom=new Vector();
		for (int i=0;i<17;i++)	{
			for (int j=0;j<16;j++)	{
				if (customArray[i][j])
					levelCustom.addElement(new Wall(i*25,j*25,25,true));
			}
		}
	}
	public void initFood1()	{
		f=new Food(25,400, 'a', 1);
		food1.addElement(f);
		f=new Food(425,25, 'a', 1);
		food1.addElement(f);
		f=new Food(0,175, 'a', 1);
		food1.addElement(f);
		f=new Food(400,175, 'a', 1);
		food1.addElement(f);
		f=new Food(200,300, 'm', 1);
		food1.addElement(f);
		f=new Food(200,125, 'm', 1);
		food1.addElement(f);
	}
	public void initFood2()	{
		f=new Food(200,125, 'a', 2);
		food2.addElement(f);
		f=new Food(200,250, 'a', 2);
		food2.addElement(f);
		f=new Food(100,75, 'a', 2);
		food2.addElement(f);
		f=new Food(300,75, 'm', 2);
		food2.addElement(f);
		f=new Food(100,300, 'm', 2);
		food2.addElement(f);
		f=new Food(300,300, 'a', 2);
		food2.addElement(f);
	}
	public void initFood3()	{
		f=new Food(200,175, 'm', 3);
		food3.addElement(f);
		f=new Food(25,325, 'a', 3);
		food3.addElement(f);
		f=new Food(375,50, 'a', 3);
		food3.addElement(f);
		f=new Food(25,150, 'm', 3);
		food3.addElement(f);
		f=new Food(375,225, 'm', 3);
		food3.addElement(f);
	}
	public void initFoodCustom()	{
		foodArray[3]=new Vector();
		for (int i=0;i<17;i++)	{
			for (int j=0;j<16;j++)	{
				if ((foodCustomArray[i][j]=='a') || (foodCustomArray[i][j]=='m'))
					foodArray[3].addElement(new Food(i*25,j*25,foodCustomArray[i][j], 4));
				else
					foodCustomArray[i][j]=' ';
			}
		}
	}
	public boolean action(Event e, Object arg)	{
		if (e.target==mapChoice)	{
			for (int k=0;k<mineVector.size();k++)	{
				mine m=(mine)mineVector.elementAt(k);
				m.alive=false;
			}
			for (int d=0;d<sleepThreadVector.size();d++)	{
				SleepThread st=(SleepThread)sleepThreadVector.elementAt(d);
				st.stop();
			}
			mineVector=new Vector();
			int i=mapChoice.getSelectedIndex();
			Pacman.level=i+1;
			if (i==0)	{
				initLevel1();
				mapEditorOn=false;
				level=1;
				Wall.wallColor=Color.red;
				Wall.bricks=true;
			}
			else if (i==1)	{
				initLevel2();
				mapEditorOn=false;
				level=2;
				Wall.wallColor=Color.green;
				Wall.bricks=true;
			}
			else if (i==2)	{
				initLevel3();
				mapEditorOn=false;
				level=3;
				Wall.wallColor=Color.blue;
				Wall.bricks=false;
			}
			else if (i==3)	{
				initLevelCustom();
				initFoodCustom();
				mapEditorOn=false;
				level=4;
				Wall.wallColor=Color.magenta;
				Wall.bricks=false;
			}
			else if (i==4)	{
				initLevelCustom();
				mapEditorOn=true;
				level=5;
				p.stop();
				p2.stop();
				gfx.setColor(Color.black);
				gfx.fillRect(0,0,425,400);
				gfx.setColor(Color.red);
				gfx.drawString("P1",25,35);
				gfx.drawString("P2",375,360);
				gfx.drawString("start",25,45);
				gfx.drawString("start",375,370);
				p.health=30;
				p2.health=30;
				repaint();
			}
			if (i<4)
				newGame();
			else
				ended=true;
		}
		if (e.target==instructions)	{
			if (instructions.getSelectedIndex()==10)
				try	{
					getAppletContext().showDocument(new URL("http://members.aol.com/davkapl"));
				} catch(Exception malformedurl) {}
		}
		if (e.target==bulletChoice)	{
			if (bulletChoice.getSelectedIndex()==1)
				bullet.delay=2;
			else if (bulletChoice.getSelectedIndex()==2)
				bullet.delay=3;
			else if (bulletChoice.getSelectedIndex()==3)
				bullet.delay=4;
			else if (bulletChoice.getSelectedIndex()==4)
				bullet.delay=6;
		}
		return super.action(e, arg);
	}
	public void newGame()	{
		Pacman.ended=false;
		p.stop();
		p2.stop();
		p=new Pacmen(25,25,true);
		p2=new Pacmen(375,350,false);
		p.start();
		p2.start();
		for (int i=0;i<Pacman.bulletVector.size();i++)	{
			bullet t=(bullet)Pacman.bulletVector.elementAt(i);
			t.stop();
		}
		Pacman.bulletVector=new Vector();
		for (int i=0;i<Pacman.foodArray[Pacman.level-1].size();i++)	{
			f=(Food)Pacman.foodArray[Pacman.level-1].elementAt(i);
			f.eaten=false;
		}
		repaint();
		updateStatusBar();
	}
	public void destroy()	{
		if (p!=null)
			p.stop();
		if (p2!=null)
			p2.stop();
		for (int i=0;i<bulletVector.size();i++)	{
			bullet b=(bullet)bulletVector.elementAt(i);
			b.stop();
		}
		for (int i=0;i<mineVector.size();i++)	{
			mine m=(mine)mineVector.elementAt(i);
		}
	}
	public static void endGame(boolean p)	{
		Pacman.ended=true;
		for (int i=0;i<bulletVector.size();i++)	{
			bullet b=(bullet)bulletVector.elementAt(i);
			b.stop();
		}
		gfx.setColor(Color.black);
		gfx.fillRect(0,0,425,400);
		gfx.setFont(endFont);
		Color c=(!p)?Color.yellow:Color.blue;
		gfx.setColor(c);
		String s=(!p)?"Player One is the WINNER!":"Player Two is the WINNER!";
		gfx.drawString(s,10,200);
		gfx.setFont(normalFont);
		playSound('w');
		Pacman.p.stop();
		Pacman.p2.stop();
	}
	public void playGunShot()	{
		gc.play();
	}
	public static void playSound(char t)	{
		if (t=='g')
			new Pacman().playGunShot();
		else if (t=='w')
			new Pacman().playWinnerClip();
		else
			new Pacman().playExplosion();
	}
	public void playWinnerClip()	{
		wc.play();
		try	{
			Thread.sleep(1600);
		} catch (Exception e)	{}
		ac.play();
	}
	public void playExplosion()	{
		ec.play();
	}
}
class ColorThread extends Thread	{
	int R=255;
	int G=255;
	int B=0;
	int R2=0,G2=255,B2=255;
	public void run()	{
		while (Pacman.p.alive)	{
			Pacmen.itColor=new Color(R,G,B);
			Pacmen.itColor2=new Color(B,G,R);
			try	{
				sleep(5);
			} catch (Exception e)	{}
			if (Pacmen.toYellow)	{
				if (G>0)
					G--;
				else	{
					G++;
					Pacmen.toYellow=false;
				}
			}
			else 	{
				if (G<255)
					G++;
				else {
					G--;
					Pacmen.toYellow=true;
				}
			}
		}
	}
}

class Pacmen extends Thread	{
	static Color itColor=new Color(255,255,0), itColor2=new Color(0,0,255);
	static Graphics g;
	char dir='r';
	boolean p;
	Food f;
	int x, y;
	int stage=44;
	boolean closing=true;
	static boolean toYellow=true, toGreen=false;
	final static short delay=6;
	static boolean alive=true;
	static Font itFont=new Font("Geneva",Font.PLAIN,10);
	boolean waitingUp=false, waitingDown=false, waitingRight=false, waitingLeft=false;
	int ammo=25, mines=5, health=30;
	final static int ammoDamage=1, mineDamage=5;
	final static int pacWidth=25, pacHeight=25;
	Pacmen(int x, int y, boolean p)	{
		this.x=x;
		this.y=y;
		this.p=p;
	}
	public void run()	{
		while ((alive) && (!Pacman.ended))	{
			if (closing)	{
				if (stage>0)
					stage-=2;
				else	{
					stage+=2;
					closing=false;
				}
			}
			else	{
				if (stage<44)
					stage+=2;
				else	{
					stage-=2;
					closing=true;
				}
			}
			for (int i=0;i<Pacman.foodArray[Pacman.level-1].size();i++)	{
				f=(Food)Pacman.foodArray[Pacman.level-1].elementAt(i);
				if ((this.x+25>f.x) && (this.y<f.y+Food.radius) && (this.y+25>f.y) && (this.x<f.x+Food.radius) && (!f.eaten))	{
					f.eat(this.p);
					f.eaten=true;
					Pacman.updateStatusBar();
				}
			}
			if (this.dir=='r')	{
				for (int i=0;i<2;i++)	{
					g.setColor(Color.black);
					g.fillRect(this.x,this.y,pacHeight,pacHeight);
					this.draw();
					if (i<1)	{
						try	{
							sleep((int)this.delay);
						} catch (Exception e)	{}
					}
				}
					try	{
						sleep((int)this.delay);
					} catch (Exception e)	{}
					g.setColor(Color.black);
					g.fillRect(this.x,this.y,pacHeight,pacHeight);
					if (checkRight())	{
						this.x+=1;
						this.checkMineProxy();
						this.checkMineHit();
						if (this.x>=Pacman.appletWidth)	{
							this.x=0;
						}
						if (this.waitingDown)	{
							if (checkDown())
								this.dir='d';
						}
						if (this.waitingLeft)	{
							if (checkLeft())
								this.dir='l';
						}
						if (this.waitingUp)	{
							if (checkUp())
								this.dir='u';
						}
					}
			}
			if (this.dir=='u')	{
				for (int i=0;i<2;i++)	{
					g.setColor(Color.black);
					g.fillRect(this.x,this.y,pacHeight,pacHeight);
					this.draw();
					if (i<1)	{
						try	{
							sleep((int)this.delay);
						} catch (Exception e)	{}
					}
				}
					try	{
						sleep((int)this.delay);
					} catch (Exception e)	{}
					g.setColor(Color.black);
					g.fillRect(this.x,this.y,pacHeight,pacHeight);
					if (checkUp())	{
						this.y-=1;
						this.checkMineProxy();
						this.checkMineHit();
						if (this.y<=-pacHeight)
							this.y=Pacman.appletHeight-40-25;
						if (this.waitingRight)	{
							if (checkRight())
								this.dir='r';
						}
						if (this.waitingLeft)	{
							if (checkLeft())
								this.dir='l';
						}
						if (this.waitingDown)	{
							if (checkDown())
								this.dir='d';
						}
					}
			}
			if (this.dir=='l')	{
				for (int i=0;i<2;i++)	{
					g.setColor(Color.black);
					g.fillRect(this.x,this.y,pacHeight,pacHeight);
					this.draw();
					if (i<1)	{
						try	{
							sleep((int)this.delay);
						} catch (Exception e)	{}
					}
				}
					try	{
						sleep((int)this.delay);
					} catch (Exception e)	{}
					g.setColor(Color.black);
					g.fillRect(this.x,this.y,pacHeight,pacHeight);
					if (checkLeft())	{
						this.x-=1;
						this.checkMineProxy();
						this.checkMineHit();
						if (this.x<=-pacWidth)
							this.x=Pacman.appletWidth-pacWidth;
						if (this.waitingRight)	{
							if (checkRight())
								this.dir='r';
						}
						if (this.waitingDown)	{
							if (checkDown())
								this.dir='d';
						}
						if (this.waitingUp)	{
							if (checkUp())
								this.dir='u';
						}
					}
			}
			if (this.dir=='d')	{
				for (int i=0;i<2;i++)	{
					g.setColor(Color.black);
					g.fillRect(this.x,this.y,pacHeight,pacHeight);
					this.draw();
					if (i<1)	{
						try	{
							sleep((int)this.delay);
						} catch (Exception e)	{}
					}
				}
					try	{
						sleep((int)this.delay);
					} catch (Exception e)	{}
					g.setColor(Color.black);
					g.fillRect(this.x,this.y,pacHeight,pacHeight);
					if (checkDown())	{
						if (this.y>=Pacman.appletHeight-40-25)	{
							g.setColor(Color.black);
							g.fillRect(this.x,375,25,25);
							this.y=-25;
						}
						this.y+=1;
						this.checkMineProxy();
						this.checkMineHit();
						if (this.waitingRight)	{
							if (checkRight())
								this.dir='r';
						}
						if (this.waitingLeft)	{
							if (checkLeft())
								this.dir='l';
						}
						if (this.waitingUp)	{
							if (checkUp())
								this.dir='u';
						}
					}
			}
		}
	}
	public boolean checkRight()	{
		boolean OK=true;
		Wall w;
		if (Pacman.level==1)	{
			for (int i=0;i<Pacman.level1.size();i++)	{
				w=(Wall)Pacman.level1.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x+25<w.x1)) && (this.y+25>w.y1) && (this.y<w.y1+w.length)) && !(this.x+25>w.x1))
						OK=false;
				} else	{
					if (((!(this.x+25<w.x1)) && (this.y+25>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x+25>w.x1))
					OK=false;
				}
			}
		}
		else if (Pacman.level==2)	{
			for (int i=0;i<Pacman.level2.size();i++)	{
				w=(Wall)Pacman.level2.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x+25<w.x1)) && (this.y+25>w.y1) && (this.y<w.y1+w.length)) && !(this.x+25>w.x1))
						OK=false;
				} else	{
					if (((!(this.x+25<w.x1)) && (this.y+25>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x+25>w.x1))
					OK=false;
				}
			}
		}
		else if (Pacman.level==3)	{
			for (int i=0;i<Pacman.level3.size();i++)	{
				w=(Wall)Pacman.level3.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x+25<w.x1)) && (this.y+25>w.y1) && (this.y<w.y1+w.length)) && !(this.x+25>w.x1))
						OK=false;
				} else	{
					if (((!(this.x+25<w.x1)) && (this.y+25>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x+25>w.x1))
					OK=false;
				}
			}
			if (this.x>=400)	{
				for (int i=0;i<Pacman.level3.size();i++)	{
					w=(Wall)Pacman.level3.elementAt(i);
					if (w.x1==0)	{
						if (w.vertical)	{
							if ((w.y1<this.y+25) && (w.y1+w.length>this.y))
								OK=false;
						}
						else	{
							if ((w.y1<this.y+25) && (w.y1+Wall.width>this.y))
								OK=false;
						}
					}
				}
			}
		}
		else if (Pacman.level==4)	{
			for (int i=0;i<Pacman.levelCustom.size();i++)	{
				w=(Wall)Pacman.levelCustom.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x+25<w.x1)) && (this.y+25>w.y1) && (this.y<w.y1+w.length)) && !(this.x+25>w.x1))
						OK=false;
				} else	{
					if (((!(this.x+25<w.x1)) && (this.y+25>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x+25>w.x1))
					OK=false;
				}
			}
			if (this.x>=400)	{
				for (int i=0;i<Pacman.levelCustom.size();i++)	{
					w=(Wall)Pacman.levelCustom.elementAt(i);
					if (w.x1==0)	{
						if (w.vertical)	{
							if ((w.y1<this.y+25) && (w.y1+w.length>this.y))
								OK=false;
						}
						else	{
							if ((w.y1<this.y+25) && (w.y1+Wall.width>this.y))
								OK=false;
						}
					}
				}
			}
		}
		return OK;
	}
	public boolean checkUp()	{
		boolean OK=true;
		Wall w;
		if (Pacman.level==1)	{
			for (int i=0;i<Pacman.level1.size();i++)	{
				w=(Wall)Pacman.level1.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y>w.y1+Wall.width)) && (this.x+25>w.x1) && (this.x<w.x1+w.length)) && !(this.y<w.y1))
						OK=false;
				} else	{
					if (((!(this.y>w.y1+w.length)) && (this.x+25>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y<w.y1))
						OK=false;
				}
			}
		}
		else if (Pacman.level==2)	{
			for (int i=0;i<Pacman.level2.size();i++)	{
				w=(Wall)Pacman.level2.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y>w.y1+Wall.width)) && (this.x+25>w.x1) && (this.x<w.x1+w.length)) && !(this.y<w.y1))
						OK=false;
				} else	{
					if (((!(this.y>w.y1+w.length)) && (this.x+25>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y<w.y1))
						OK=false;
				}
			}
		}
		else if (Pacman.level==3)	{
			for (int i=0;i<Pacman.level3.size();i++)	{
				w=(Wall)Pacman.level3.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y>w.y1+Wall.width)) && (this.x+25>w.x1) && (this.x<w.x1+w.length)) && !(this.y<w.y1))
						OK=false;
				} else	{
					if (((!(this.y>w.y1+w.length)) && (this.x+25>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y<w.y1))
						OK=false;
				}
			}
			if (this.y<=0)	{
				for (int i=0;i<Pacman.level3.size();i++)	{
					w=(Wall)Pacman.level3.elementAt(i);
					if ((w.y1==375) || ((w.y1+w.length==400) && (w.vertical)))	{
						if (w.vertical)	{
							if ((this.x<w.x1+25) && (this.x+25>w.x1))
								OK=false;
						}
						else	{
							if ((this.x<w.x1+w.length) && (this.x+25>w.x1))
								OK=false;
						}
					}
				}
			}
		}
		else if (Pacman.level==4)	{
			for (int i=0;i<Pacman.levelCustom.size();i++)	{
				w=(Wall)Pacman.levelCustom.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y>w.y1+Wall.width)) && (this.x+25>w.x1) && (this.x<w.x1+w.length)) && !(this.y<w.y1))
						OK=false;
				} else	{
					if (((!(this.y>w.y1+w.length)) && (this.x+25>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y<w.y1))
						OK=false;
				}
			}
			if (this.y<=0)	{
				for (int i=0;i<Pacman.levelCustom.size();i++)	{
					w=(Wall)Pacman.levelCustom.elementAt(i);
					if (w.y1==375)	{
						if (w.vertical)	{
							if ((this.x<w.x1+25) && (this.x+25>w.x1))
								OK=false;
						}
						else	{
							if ((this.x<w.x1+w.length) && (this.x+25>w.x1))
								OK=false;
						}
					}
				}
			}
		}
		return OK;
	}
	public boolean checkLeft()	{
		boolean OK=true;
		Wall w;
		if (Pacman.level==1)	{
			for (int i=0;i<Pacman.level1.size();i++)	{
				w=(Wall)Pacman.level1.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x>w.x1+Wall.width)) && (this.y+25>w.y1) && (this.y<w.y1+w.length)) && !(this.x<w.x1))
						OK=false;
				} else	{
					if (((!(this.x>w.x1+w.length)) && (this.y+25>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x<w.x1))
						OK=false;
				}
			}
		}
		else if (Pacman.level==2)	{
			for (int i=0;i<Pacman.level2.size();i++)	{
				w=(Wall)Pacman.level2.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x>w.x1+Wall.width)) && (this.y+25>w.y1) && (this.y<w.y1+w.length)) && !(this.x<w.x1))
						OK=false;
				} else	{
					if (((!(this.x>w.x1+w.length)) && (this.y+25>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x<w.x1))
						OK=false;
				}
			}
		}
		else if (Pacman.level==3)	{
			for (int i=0;i<Pacman.level3.size();i++)	{
				w=(Wall)Pacman.level3.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x>w.x1+Wall.width)) && (this.y+25>w.y1) && (this.y<w.y1+w.length)) && !(this.x<w.x1))
						OK=false;
				} else	{
					if (((!(this.x>w.x1+w.length)) && (this.y+25>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x<w.x1))
						OK=false;
				}
			}
			if (this.x<=0)	{
				for (int i=0;i<Pacman.level3.size();i++)	{
					w=(Wall)Pacman.level3.elementAt(i);
					if ((w.x1==400) || ((w.x1+w.length==425) && (!w.vertical)))	{
						if (w.vertical)	{
							if ((w.y1<this.y+25) && (w.y1+w.length>this.y))
								OK=false;
						}
						else	{
							if ((w.y1<this.y+25) && (w.y1+Wall.width>this.y))
								OK=false;
						}
					}
				}
			}
		}
		else if (Pacman.level==4)	{
			for (int i=0;i<Pacman.levelCustom.size();i++)	{
				w=(Wall)Pacman.levelCustom.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x>w.x1+Wall.width)) && (this.y+25>w.y1) && (this.y<w.y1+w.length)) && !(this.x<w.x1))
						OK=false;
				} else	{
					if (((!(this.x>w.x1+w.length)) && (this.y+25>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x<w.x1))
						OK=false;
				}
			}
			if (this.x<=0)	{
				for (int i=0;i<Pacman.levelCustom.size();i++)	{
					w=(Wall)Pacman.levelCustom.elementAt(i);
					if ((w.x1==400) || (w.x1+w.length==425))	{
						if (w.vertical)	{
							if ((w.y1<this.y+25) && (w.y1+w.length>this.y))
								OK=false;
						}
						else	{
							if ((w.y1<this.y+25) && (w.y1+Wall.width>this.y))
								OK=false;
						}
					}
				}
			}
		}
		return OK;
	}
	public boolean checkDown()	{
		boolean OK=true;
		Wall w;
		if (Pacman.level==1)	{
			for (int i=0;i<Pacman.level1.size();i++)	{
				w=(Wall)Pacman.level1.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y+25<w.y1)) && (this.x+25>w.x1) && (this.x<w.x1+w.length)) && !(this.y>w.y1))
						OK=false;
				} else	{
					if (((!(this.y+25<w.y1)) && (this.x+25>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y>w.y1))
						OK=false;
				}
			}
		}
		else if (Pacman.level==2)	{
			for (int i=0;i<Pacman.level2.size();i++)	{
				w=(Wall)Pacman.level2.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y+25<w.y1)) && (this.x+25>w.x1) && (this.x<w.x1+w.length)) && !(this.y>w.y1))
						OK=false;
				} else	{
					if (((!(this.y+25<w.y1)) && (this.x+25>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y>w.y1))
						OK=false;
				}
			}
		}
		else if (Pacman.level==3)	{
			for (int i=0;i<Pacman.level3.size();i++)	{
				w=(Wall)Pacman.level3.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y+25<w.y1)) && (this.x+25>w.x1) && (this.x<w.x1+w.length)) && !(this.y>w.y1))
						OK=false;
				} else	{
					if (((!(this.y+25<w.y1)) && (this.x+25>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y>w.y1))
						OK=false;
				}
			}
			if (this.y>=375)	{
				for (int i=0;i<Pacman.level3.size();i++)	{
					w=(Wall)Pacman.level3.elementAt(i);
					if (w.y1==0)	{
						if (w.vertical)	{
							if ((this.x<w.x1+25) && (this.x+25>w.x1))
								OK=false;
						}
						else	{
							if ((this.x<w.x1+w.length) && (this.x+25>w.x1))
								OK=false;
						}
					}
				}
			}
		}
		else if (Pacman.level==4)	{
			for (int i=0;i<Pacman.levelCustom.size();i++)	{
				w=(Wall)Pacman.levelCustom.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y+25<w.y1)) && (this.x+25>w.x1) && (this.x<w.x1+w.length)) && !(this.y>w.y1))
						OK=false;
				} else	{
					if (((!(this.y+25<w.y1)) && (this.x+25>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y>w.y1))
						OK=false;
				}
			}
			if (this.y>=375)	{
				for (int i=0;i<Pacman.levelCustom.size();i++)	{
					w=(Wall)Pacman.levelCustom.elementAt(i);
					if (w.y1==0)	{
						if (w.vertical)	{
							if ((this.x<w.x1+25) && (this.x+25>w.x1))
								OK=false;
						}
						else	{
							if ((this.x<w.x1+w.length) && (this.x+25>w.x1))
								OK=false;
						}
					}
				}
			}
		}
		return OK;
	}
	public void checkMineProxy()	{
		for (int i=0;i<Pacman.mineVector.size();i++)	{
			mine m=(mine)Pacman.mineVector.elementAt(i);
			if ((m.x+30>this.x) && (m.x<this.x+30) && (m.y+30>this.y) && (m.y<this.y+30))	{
				m.draw();
			}
		}
	}
	public void checkMineHit()	{
		for (int i=0;i<Pacman.mineVector.size();i++)	{
			mine m=(mine)Pacman.mineVector.elementAt(i);
			if ((m.x+25>this.x) && (m.x<this.x+25) && (m.y+25>this.y) && (m.y<this.y+25))	{
				this.health-=Pacmen.mineDamage;
				m.explode(this.dir,false);
				if (this.dir=='r')	{
					for(int k=0;k<36;k++)	{
						try	{
							Thread.sleep(2);
						}	catch(Exception e)	{System.out.println("HELLLOOOEOEOOEOEOEE");}
						g.setColor(Color.black);
						g.fillRect(this.x,this.y,25,25);
						if (checkLeft())	{
							if (this.x>-25)
								this.x--;
							else
								this.x=424;
						}
						this.draw();
					}
				}
				else if (this.dir=='l')	{
					for(int k=0;k<36;k++)	{
						try	{
							Thread.sleep(2);
						}	catch(Exception e)	{}
						g.setColor(Color.black);
						g.fillRect(this.x,this.y,25,25);
						if (checkRight())	{
							if (this.x<425)
								this.x++;
							else
								this.x=-24;
						}
						this.draw();
					}
				}
				else if (this.dir=='u')	{
					for(int k=0;k<36;k++)	{
						try	{
							Thread.sleep(2);
						}	catch(Exception e)	{System.out.println("HELLLOOOEOEOOEOEOEE");}
						g.setColor(Color.black);
						g.fillRect(this.x,this.y,25,25);
						if (checkDown())	{
							if (this.y<375)
								this.y++;
							else
								this.y=-24;
						}
						this.draw();
					}
				}
				else if (this.dir=='d')	{
					for(int k=0;k<36;k++)	{
						try	{
							Thread.sleep(2);
						}	catch(Exception e)	{}
						g.setColor(Color.black);
						g.fillRect(this.x,this.y,25,25);
						if (checkUp())	{
							if (this.y>-25)
								this.y--;
							else
								this.y=375;
						}
						this.draw();
					}
				}
				if (this.health<=0)
					this.health=0;
				Pacman.updateStatusBar();
				if (this.health==0)
					Pacman.endGame(this.p);
			}
		}
	}
	public synchronized void shoot()	{
		bullet b=new bullet(this.x, this.y, this.p, this.dir);
		if (((b.dir=='r') && (b.checkRight())) || ((b.dir=='l') && (b.checkLeft())) || ((b.dir=='u') && (b.checkUp())) || ((b.dir=='d') && (b.checkDown())))	{
			b.start();
			b.serial=Pacman.bulletVector.size();
			Pacman.bulletVector.addElement(b);
			this.ammo--;
			Pacman.updateStatusBar();
			Pacman.playSound('g');
		}
	}
	public void mine()	{
		if (checkMine())	{
			mine m=new mine(this.x, this.y, this.p, this.dir);
			this.mines--;
			m.serial=Pacman.mineVector.size();
			Pacman.mineVector.addElement(m);
		}
	}
	public boolean checkMine()	{
		boolean OK=true;
		Wall w;
		if (Pacman.level==1)	{
			for (int i=0;i<Pacman.level1.size();i++)	{
				w=(Wall)Pacman.level1.elementAt(i);
				if (this.dir=='d')	{
					if (!w.vertical)	{
						if ((w.y1<this.y) && (this.y<w.y1+50) && (this.x+25>w.x1) && (this.x<w.x1+w.length))
							OK=false;
					} else	{
						if ((w.y1<this.y) && (this.y<w.y1+w.length+25) && (this.x+25>w.x1) && (this.x<w.x1+25))
							OK=false;
					}
				}
				if (this.dir=='u')	{
					if (this.y>350)	{
						OK=false;
					}
					if (!w.vertical)	{
						if ((w.y1-25<this.y) && (this.y+25<w.y1+25) && (this.x+25>w.x1) && (this.x<w.x1+w.length))
							OK=false;
					} else	{
						if ((w.y1-25<this.y+25) && (this.y+25<w.y1+w.length) && (this.x+25>w.x1) && (this.x<w.x1+25))
							OK=false;
					}
				}
				if (this.dir=='l')	{
					if (!w.vertical)	{
						if ((w.x1-25<this.x+25) && (this.x+25<w.x1+w.length) && (this.y+25>w.y1) && (this.y<w.y1+25))
							OK=false;
					} else	{
						if ((w.x1-25<this.x+25) && (this.x+25<w.x1+25) && (this.y+25>w.y1) && (this.y<w.y1+w.length))
							OK=false;
					}
				}
				if (this.dir=='r')	{
					if (!w.vertical)	{
						if ((w.x1<this.x) && (this.x<w.x1+w.length+25) && (this.y+25>w.y1) && (this.y<w.y1+25))
							OK=false;
					} else	{
						if ((w.x1<this.x) && (this.x<w.x1+50) && (this.y+25>w.y1) && (this.y<w.y1+w.length))
							OK=false;
					}
				}
			}
		}
		else if (Pacman.level==2)	{
			for (int i=0;i<Pacman.level2.size();i++)	{
				w=(Wall)Pacman.level2.elementAt(i);
				if (this.dir=='d')	{
					if (!w.vertical)	{
						if ((w.y1<this.y) && (this.y<w.y1+50) && (this.x+25>w.x1) && (this.x<w.x1+w.length))
							OK=false;
					} else	{
						if ((w.y1<this.y) && (this.y<w.y1+w.length+25) && (this.x+25>w.x1) && (this.x<w.x1+25))
							OK=false;
					}
				}
				if (this.dir=='u')	{
					if (this.y>350)	{
						OK=false;
					}
					if (!w.vertical)	{
						if ((w.y1-25<this.y+25) && (this.y+25<w.y1+25) && (this.x+25>w.x1) && (this.x<w.x1+w.length))
							OK=false;
					} else	{
						if ((w.y1-25<this.y+25) && (this.y+25<w.y1+w.length) && (this.x+25>w.x1) && (this.x<w.x1+25))
							OK=false;
					}
				}
				if (this.dir=='l')	{
					if (!w.vertical)	{
						if ((w.x1-25<this.x+25) && (this.x+25<w.x1+w.length) && (this.y+25>w.y1) && (this.y<w.y1+25))
							OK=false;
					} else	{
						if ((w.x1-25<this.x+25) && (this.x+25<w.x1+25) && (this.y+25>w.y1) && (this.y<w.y1+w.length))
							OK=false;
					}
				}
				if (this.dir=='r')	{
					if (!w.vertical)	{
						if ((w.x1<this.x) && (this.x<w.x1+w.length+25) && (this.y+25>w.y1) && (this.y<w.y1+25))
							OK=false;
					} else	{
						if ((w.x1<this.x) && (this.x<w.x1+50) && (this.y+25>w.y1) && (this.y<w.y1+w.length))
							OK=false;
					}
				}
			}
		}
		else if (Pacman.level==3)	{
			for (int i=0;i<Pacman.level3.size();i++)	{
				w=(Wall)Pacman.level3.elementAt(i);
				if (this.dir=='d')	{
					if (!w.vertical)	{
						if ((w.y1<this.y) && (this.y<w.y1+50) && (this.x+25>w.x1) && (this.x<w.x1+w.length))
							OK=false;
					} else	{
						if ((w.y1<this.y) && (this.y<w.y1+w.length+25) && (this.x+25>w.x1) && (this.x<w.x1+25))
							OK=false;
					}
				}
				if (this.dir=='u')	{
					if (this.y>350)	{
						OK=false;
					}
					if (!w.vertical)	{
						if ((w.y1-25<this.y) && (this.y+25<w.y1+25) && (this.x+25>w.x1) && (this.x<w.x1+w.length))
							OK=false;
					} else	{
						if ((w.y1-25<this.y+25) && (this.y+25<w.y1+w.length) && (this.x+25>w.x1) && (this.x<w.x1+25))
							OK=false;
					}
				}
				if (this.dir=='l')	{
					if (!w.vertical)	{
						if ((w.x1-25<this.x+25) && (this.x+25<w.x1+w.length) && (this.y+25>w.y1) && (this.y<w.y1+25))
							OK=false;
					} else	{
						if ((w.x1-25<this.x+25) && (this.x+25<w.x1+25) && (this.y+25>w.y1) && (this.y<w.y1+w.length))
							OK=false;
					}
				}
				if (this.dir=='r')	{
					if (!w.vertical)	{
						if ((w.x1<this.x) && (this.x<w.x1+w.length+25) && (this.y+25>w.y1) && (this.y<w.y1+25))
							OK=false;
					} else	{
						if ((w.x1<this.x) && (this.x<w.x1+50) && (this.y+25>w.y1) && (this.y<w.y1+w.length))
							OK=false;
					}
				}
			}
		}
		else if (Pacman.level==4)	{
			for (int i=0;i<Pacman.levelCustom.size();i++)	{
				w=(Wall)Pacman.levelCustom.elementAt(i);
				if (this.dir=='d')	{
					if (!w.vertical)	{
						if ((w.y1<this.y) && (this.y<w.y1+50) && (this.x+25>w.x1) && (this.x<w.x1+w.length))
							OK=false;
					} else	{
						if ((w.y1<this.y) && (this.y<w.y1+w.length+25) && (this.x+25>w.x1) && (this.x<w.x1+25))
							OK=false;
					}
				}
				if (this.dir=='u')	{
					if (this.y>350)	{
						OK=false;
					}
					if (!w.vertical)	{
						if ((w.y1-25<this.y) && (this.y+25<w.y1+25) && (this.x+25>w.x1) && (this.x<w.x1+w.length))
							OK=false;
					} else	{
						if ((w.y1-25<this.y+25) && (this.y+25<w.y1+w.length) && (this.x+25>w.x1) && (this.x<w.x1+25))
							OK=false;
					}
				}
				if (this.dir=='l')	{
					if (!w.vertical)	{
						if ((w.x1-25<this.x+25) && (this.x+25<w.x1+w.length) && (this.y+25>w.y1) && (this.y<w.y1+25))
							OK=false;
					} else	{
						if ((w.x1-25<this.x+25) && (this.x+25<w.x1+25) && (this.y+25>w.y1) && (this.y<w.y1+w.length))
							OK=false;
					}
				}
				if (this.dir=='r')	{
					if (!w.vertical)	{
						if ((w.x1<this.x) && (this.x<w.x1+w.length+25) && (this.y+25>w.y1) && (this.y<w.y1+25))
							OK=false;
					} else	{
						if ((w.x1<this.x) && (this.x<w.x1+50) && (this.y+25>w.y1) && (this.y<w.y1+w.length))
							OK=false;
					}
				}
			}
		}
		return OK;
	}
	public void draw()	{
		if (this.dir=='d')	{
				if (this.health<5)	{
					if (this.p)
						g.setColor(itColor);
					else
						g.setColor(itColor2);
				}
				else	{
					if (this.p)
						g.setColor(Color.yellow);
					else
						g.setColor(Color.blue);
				}
				g.fillArc(this.x, this.y,25,25,270+this.stage*1,360-this.stage*2*1);
				g.setColor(Color.black);
				g.drawOval(this.x+18,this.y+11,5,5);
				g.fillOval(this.x+19,this.y+14,3,3);
		}
		else if (this.dir=='u')	{
			if (this.health<5)	{
				if (this.p)
					g.setColor(itColor);
				else
					g.setColor(itColor2);
			}
			else	{
				if (this.p)
					g.setColor(Color.yellow);
				else
					g.setColor(Color.blue);
			}
			g.fillArc(this.x, this.y,25,25,90+this.stage*1,360-this.stage*2*1);
			g.setColor(Color.black);
			g.drawOval(this.x+3,this.y+14,5,5);
			g.fillOval(this.x+5,this.y+14,3,3);
		}
		else if (this.dir=='l')	{
			if (this.health<5)	{
				if (this.p)
					g.setColor(itColor);
				else
					g.setColor(itColor2);
			}
			else	{
				if (this.p)
					g.setColor(Color.yellow);
				else
					g.setColor(Color.blue);
			}
			g.fillArc(this.x, this.y,25,25,180+this.stage*1,360-this.stage*2*1);
			g.setColor(Color.black);
			g.drawOval(this.x+12,this.y+3,5,5);
			g.fillOval(this.x+12,this.y+5,3,3);
		}
		else if (this.dir=='r')	{
			if (this.health<5)	{
				if (this.p)
					g.setColor(itColor);
				else
					g.setColor(itColor2);
			}
			else	{
				if (this.p)
					g.setColor(Color.yellow);
				else
					g.setColor(Color.blue);
			}
			g.fillArc(this.x, this.y,25,25,this.stage*1,360-this.stage*2*1);
			g.setColor(Color.black);
			g.drawOval(this.x+7,this.y+3,5,5);
			g.fillOval(this.x+10,this.y+5,3,3);
		}
	}
}
class Wall {
	static Color wallColor=Color.red;
	static boolean bricks=true;
	int x1, y1, length;
	boolean vertical;
	final static int width=25;
	Wall(int x1, int y1, int length, boolean vertical)	{
		this.x1=x1;
		this.y1=y1;
		this.length=length;
		this.vertical=vertical;
	}
	public void draw(Graphics g)	{
		g.setColor(wallColor);
		if (vertical)
			g.fillRect(this.x1, this.y1, width, length);
		else
			g.fillRect(this.x1, this.y1, length, width);
		g.setColor(Color.black);
		if (bricks)	{
	if (vertical)	{
	for (int i=0;i<this.length/25;i++)	{
		g.drawLine(this.x1,this.y1+25*i,this.x1,this.y1+6+25*i);
		g.drawLine(this.x1+12,this.y1+25*i,this.x1+12,this.y1+6+25*i);
		g.drawLine(this.x1+25,this.y1+25*i,this.x1+25,this.y1+6+25*i);
		g.drawLine(this.x1+6,this.y1+6+25*i,this.x1+6,this.y1+12+25*i);
		g.drawLine(this.x1+19,this.y1+6+25*i,this.x1+19,this.y1+12+25*i);
		g.drawLine(this.x1,this.y1+12+25*i,this.x1,this.y1+19+25*i);
		g.drawLine(this.x1+12,this.y1+12+25*i,this.x1+12,this.y1+19+25*i);
		g.drawLine(this.x1+25,this.y1+12+25*i,this.x1+25,this.y1+19+25*i);
		g.drawLine(this.x1+6,this.y1+19+25*i,this.x1+6,this.y1+25+25*i);
		g.drawLine(this.x1+19,this.y1+19+25*i,this.x1+19,this.y1+25+25*i);

		g.drawLine(this.x1,this.y1+25*i,this.x1+25,this.y1+25*i);
		g.drawLine(this.x1,this.y1+6+25*i,this.x1+25,this.y1+6+25*i);
		g.drawLine(this.x1,this.y1+12+25*i,this.x1+25,this.y1+12+25*i);
		g.drawLine(this.x1,this.y1+19+25*i,this.x1+25,this.y1+19+25*i);
		g.drawLine(this.x1,this.y1+25+25*i,this.x1+25,this.y1+25+25*i);
	}
	}
	else	{
	for (int i=0;i<this.length/25;i++)	{
		g.drawLine(this.x1+25*i,this.y1,this.x1+25*i,this.y1+6);
		g.drawLine(this.x1+12+25*i,this.y1,this.x1+12+25*i,this.y1+6);
		g.drawLine(this.x1+25+25*i,this.y1,this.x1+25+25*i,this.y1+6);
		g.drawLine(this.x1+6+25*i,this.y1+6,this.x1+6+25*i,this.y1+12);
		g.drawLine(this.x1+19+25*i,this.y1+6,this.x1+19+25*i,this.y1+12);
		g.drawLine(this.x1+25*i,this.y1+12,this.x1+25*i,this.y1+19);
		g.drawLine(this.x1+12+25*i,this.y1+12,this.x1+12+25*i,this.y1+19);
		g.drawLine(this.x1+25+25*i,this.y1+12,this.x1+25+25*i,this.y1+19);
		g.drawLine(this.x1+6+25*i,this.y1+19,this.x1+6+25*i,this.y1+25);
		g.drawLine(this.x1+19+25*i,this.y1+19,this.x1+19+25*i,this.y1+25);

		g.drawLine(this.x1+25*i,this.y1,this.x1+25+25*i,this.y1);
		g.drawLine(this.x1+25*i,this.y1+6,this.x1+25+25*i,this.y1+6);
		g.drawLine(this.x1+25*i,this.y1+12,this.x1+25+25*i,this.y1+12);
		g.drawLine(this.x1+25*i,this.y1+19,this.x1+25+25*i,this.y1+19);
		g.drawLine(this.x1+25*i,this.y1+25,this.x1+25+25*i,this.y1+25);
	}
	}
		}
	}
}
class Food	{
	static final int radius=5;
	int x, y;
	Color col=Color.white;
	boolean eaten=false;
	char type;
	int level;
	Food(int x, int y, char type, int level)	{
		this.x=x+10;
		this.y=y+10;
		this.type=type;
		this.level=level;
		if (this.type=='m')	{
			this.col=Color.magenta;
		}
		this.draw(Pacman.gfx);
	}
	public void draw(Graphics g)	{
		g.setColor(this.col);
		g.fillRect(this.x, this.y, radius, radius);
	}
	public void eat(boolean p)	{
		eaten=true;
		Pacman.gfx.setColor(Color.black);
		Pacman.gfx.fillRect(this.x, this.y, radius, radius);
		if (p)	{
			if (this.type=='a')
				Pacman.p.ammo+=3;
			else
				Pacman.p.mines++;
		}
		else	{
			if (this.type=='a')
				Pacman.p2.ammo+=3;
			else
				Pacman.p2.mines++;
		}
		SleepThread st=new SleepThread();
		st.init(this);
		st.start();
		if (Pacman.level==4)
			Pacman.sleepThreadVector.addElement(st);
	}
}
class SleepThread extends Thread	{
	Food f;
	public void run()	{
		try	{
			sleep(20000);
		}
		catch(Exception e)	{
			System.out.println("Caught red handed! Sleeping!");
		}
		f.eaten=false;
		if ((!Pacman.ended) && (Pacman.level==f.level))
			f.draw(Pacman.gfx);
	}
	public void init(Food f)	{
		this.f=f;
	}
}
class setPanel extends Panel	{
	Dimension myDimension=new Dimension(425,82);
	setPanel(int width, int height)	{
		myDimension.width=width;
		myDimension.height=height;
	}
	public Dimension getPreferredSize()	{
		return myDimension;
	}
	public Dimension getMinimumSize()	{
		return myDimension;
	}
}
class bullet extends Thread	{
	int x;
	int y;
	int serial;
	final int radius=5;
	Color col;
	char dir;
	Graphics g;
	boolean stopped=false;
	static int delay=3;
	bullet(int x, int y, boolean p, char dir)	{
		this.dir=dir;
		if (!p)
			this.col=Color.blue;
		else if (p)
			this.col=Color.yellow;
		else
			this.col=Color.red;
		if (dir=='r')	{
			this.x=x+25;
			this.y=y+10;
		}
		else if (dir=='u')	{
			this.x=x+10;
			this.y=y-5;
		}
		else if (dir=='l')	{
			this.x=x-5;
			this.y=y+10;
		}
		else if (dir=='d')	{
			this.x=x+10;
			this.y=y+25;
		}
		g=Pacman.gfx;
	}
	public void run()	{
		while(!stopped)	{
			g.setColor(Color.black);
			g.fillOval(this.x, this.y,this.radius, this.radius);
			if (dir=='r')	{
				if (checkRight())	{
					if (this.x<425)
						this.x+=1;
					else
						this.x=0;
				}
				else	{
					this.stopped=true;
					Pacman.bulletVector.removeElementAt(this.serial);
						for (int i=0;i<Pacman.bulletVector.size();i++)	{
							bullet b=(bullet)Pacman.bulletVector.elementAt(i);
							b.serial=i;
						}
				}
			}
			else if (dir=='l')	{
				if (checkLeft())	{
					if (this.x>-3)
						this.x-=1;
					else
						this.x=424;
				}
				else	{
					this.stopped=true;
					Pacman.bulletVector.removeElementAt(this.serial);
						for (int i=0;i<Pacman.bulletVector.size();i++)	{
							bullet b=(bullet)Pacman.bulletVector.elementAt(i);
							b.serial=i;
						}
				}
			}
			else if (dir=='u')	{
				if (checkUp())	{
					if (this.y>-3)
						this.y-=1;
					else
						this.y=395;
				}
				else	{
					this.stopped=true;
					Pacman.bulletVector.removeElementAt(this.serial);
						for (int i=0;i<Pacman.bulletVector.size();i++)	{
							bullet b=(bullet)Pacman.bulletVector.elementAt(i);
							b.serial=i;
						}
				}
			}
			else if (dir=='d')	{
				if (checkDown())	{
					if (this.y<395)
						this.y+=1;
					else
						this.y=0;
				}
				else	{
					this.stopped=true;
					Pacman.bulletVector.removeElementAt(this.serial);
						for (int i=0;i<Pacman.bulletVector.size();i++)	{
							bullet b=(bullet)Pacman.bulletVector.elementAt(i);
							b.serial=i;
						}
				}
			}
			char hitChecker=checkHit();
			if (hitChecker=='1')	{
				this.stopped=true;
				Pacman.p.health-=Pacmen.ammoDamage;
				Pacman.updateStatusBar();
				if (Pacman.p.health==0)
					Pacman.endGame(true);
				this.stop();
			}
			else if (hitChecker=='2')	{
				this.stopped=true;
				Pacman.p2.health-=Pacmen.ammoDamage;
				Pacman.updateStatusBar();
				if (Pacman.p2.health==0)
					Pacman.endGame(false);
				this.stop();
			}
			else	{
				g.setColor(this.col);
				g.fillOval(this.x, this.y, this.radius, this.radius);
			}
			checkMine();
			try	{
				sleep(delay);
			} catch(Exception e)	{}
			if (stopped)	{
				g.setColor(Color.black);
				g.fillOval(this.x, this.y,this.radius, this.radius);
			}
		}
	}
	public char checkHit()	{
		char hit='n';
		if ((this.x+5>Pacman.p.x) && (this.x<Pacman.p.x+25) && (this.y+5>Pacman.p.y) && (this.y<Pacman.p.y+25) && (!this.stopped))	{
					hit='1';
					this.stopped=true;
					Pacman.bulletVector.removeElementAt(this.serial);
						for (int i=0;i<Pacman.bulletVector.size();i++)	{
							bullet b=(bullet)Pacman.bulletVector.elementAt(i);
							b.serial=i;
						}
		}
		else if ((this.x+5>Pacman.p2.x) && (this.x<Pacman.p2.x+25) && (this.y+5>Pacman.p2.y) && (this.y<Pacman.p2.y+25) && (!this.stopped))	{
			hit='2';
					this.stopped=true;
					Pacman.bulletVector.removeElementAt(this.serial);
						for (int i=0;i<Pacman.bulletVector.size();i++)	{
							bullet b=(bullet)Pacman.bulletVector.elementAt(i);
							b.serial=i;
						}
		}
		return hit;
	}
	public boolean checkRight()	{
		boolean OK=true;
		Wall w;
		if (Pacman.level==1)	{
			for (int i=0;i<Pacman.level1.size();i++)	{
				w=(Wall)Pacman.level1.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x+5<w.x1)) && (this.y+10>w.y1) && (this.y<w.y1+w.length)) && !(this.x>w.x1))
						OK=false;
				} else	{
					if (((!(this.x+5<w.x1)) && (this.y+10>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x>w.x1))
					OK=false;
				}
			}
		}
		else if (Pacman.level==2)	{
			for (int i=0;i<Pacman.level2.size();i++)	{
				w=(Wall)Pacman.level2.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x+5<w.x1)) && (this.y+10>w.y1) && (this.y<w.y1+w.length)) && !(this.x>w.x1))
						OK=false;
				} else	{
					if (((!(this.x+5<w.x1)) && (this.y+10>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x>w.x1))
					OK=false;
				}
			}
		}
		else if (Pacman.level==3)	{
			for (int i=0;i<Pacman.level3.size();i++)	{
				w=(Wall)Pacman.level3.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x+5<w.x1)) && (this.y+10>w.y1) && (this.y<w.y1+w.length)) && !(this.x>w.x1))
						OK=false;
				} else	{
					if (((!(this.x+5<w.x1)) && (this.y+10>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x>w.x1))
					OK=false;
				}
			}
			if (this.x>=400)	{
				for (int i=0;i<Pacman.level3.size();i++)	{
					w=(Wall)Pacman.level3.elementAt(i);
					if (w.x1==0)	{
						if (w.vertical)	{
							if ((w.y1<this.y+10) && (w.y1+w.length>this.y))
								OK=false;
						}
						else	{
							if ((w.y1<this.y+10) && (w.y1+Wall.width>this.y))
								OK=false;
						}
					}
				}
			}
		}
		else if (Pacman.level==4)	{
			for (int i=0;i<Pacman.levelCustom.size();i++)	{
				w=(Wall)Pacman.levelCustom.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x+5<w.x1)) && (this.y+10>w.y1) && (this.y<w.y1+w.length)) && !(this.x>w.x1))
						OK=false;
				} else	{
					if (((!(this.x+5<w.x1)) && (this.y+10>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x>w.x1))
					OK=false;
				}
			}
			if (this.x>=400)	{
				for (int i=0;i<Pacman.levelCustom.size();i++)	{
					w=(Wall)Pacman.levelCustom.elementAt(i);
					if (w.x1==0)	{
						if (w.vertical)	{
							if ((w.y1<this.y+10) && (w.y1+w.length>this.y))
								OK=false;
						}
						else	{
							if ((w.y1<this.y+10) && (w.y1+Wall.width>this.y))
								OK=false;
						}
					}
				}
			}
		}
		return OK;
	}
	public boolean checkUp()	{
		boolean OK=true;
		Wall w;
		if (Pacman.level==1)	{
			for (int i=0;i<Pacman.level1.size();i++)	{
				w=(Wall)Pacman.level1.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y>w.y1+Wall.width)) && (this.x+10>w.x1) && (this.x<w.x1+w.length)) && !(this.y<w.y1))
						OK=false;
				} else	{
					if (((!(this.y>w.y1+w.length)) && (this.x+10>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y<w.y1))
						OK=false;
				}
			}
		}
		else if (Pacman.level==2)	{
			for (int i=0;i<Pacman.level2.size();i++)	{
				w=(Wall)Pacman.level2.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y>w.y1+Wall.width)) && (this.x+10>w.x1) && (this.x<w.x1+w.length)) && !(this.y<w.y1))
						OK=false;
				} else	{
					if (((!(this.y>w.y1+w.length)) && (this.x+10>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y<w.y1))
						OK=false;
				}
			}
		}
		else if (Pacman.level==3)	{
			for (int i=0;i<Pacman.level3.size();i++)	{
				w=(Wall)Pacman.level3.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y>w.y1+Wall.width)) && (this.x+10>w.x1) && (this.x<w.x1+w.length)) && !(this.y<w.y1))
						OK=false;
				} else	{
					if (((!(this.y>w.y1+w.length)) && (this.x+10>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y<w.y1))
						OK=false;
				}
			}
			if (this.y<=0)	{
				for (int i=0;i<Pacman.level3.size();i++)	{
					w=(Wall)Pacman.level3.elementAt(i);
					if ((w.y1==375) || ((w.y1+w.length==400) && (w.vertical)))	{
						if (w.vertical)	{
							if ((this.x<w.x1+25) && (this.x+10>w.x1))
								OK=false;
						}
						else	{
							if ((this.x<w.x1+w.length) && (this.x+10>w.x1))
								OK=false;
						}
					}
				}
			}
		}
		else if (Pacman.level==4)	{
			for (int i=0;i<Pacman.levelCustom.size();i++)	{
				w=(Wall)Pacman.levelCustom.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y>w.y1+Wall.width)) && (this.x+10>w.x1) && (this.x<w.x1+w.length)) && !(this.y<w.y1))
						OK=false;
				} else	{
					if (((!(this.y>w.y1+w.length)) && (this.x+10>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y<w.y1))
						OK=false;
				}
			}
			if (this.y<=0)	{
				for (int i=0;i<Pacman.levelCustom.size();i++)	{
					w=(Wall)Pacman.levelCustom.elementAt(i);
					if (w.y1==375)	{
						if (w.vertical)	{
							if ((this.x<w.x1+25) && (this.x+10>w.x1))
								OK=false;
						}
						else	{
							if ((this.x<w.x1+w.length) && (this.x+10>w.x1))
								OK=false;
						}
					}
				}
			}
		}
		return OK;
	}
	public boolean checkLeft()	{
		boolean OK=true;
		Wall w;
		if (Pacman.level==1)	{
			for (int i=0;i<Pacman.level1.size();i++)	{
				w=(Wall)Pacman.level1.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x>w.x1+Wall.width)) && (this.y+10>w.y1) && (this.y<w.y1+w.length)) && !(this.x<w.x1))
						OK=false;
				} else	{
					if (((!(this.x>w.x1+w.length)) && (this.y+10>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x<w.x1))
						OK=false;
				}
			}
		}
		else if (Pacman.level==2)	{
			for (int i=0;i<Pacman.level2.size();i++)	{
				w=(Wall)Pacman.level2.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x>w.x1+Wall.width)) && (this.y+10>w.y1) && (this.y<w.y1+w.length)) && !(this.x<w.x1))
						OK=false;
				} else	{
					if (((!(this.x>w.x1+w.length)) && (this.y+10>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x<w.x1))
						OK=false;
				}
			}
		}
		else if (Pacman.level==3)	{
			for (int i=0;i<Pacman.level3.size();i++)	{
				w=(Wall)Pacman.level3.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x>w.x1+Wall.width)) && (this.y+10>w.y1) && (this.y<w.y1+w.length)) && !(this.x<w.x1))
						OK=false;
				} else	{
					if (((!(this.x>w.x1+w.length)) && (this.y+10>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x<w.x1))
						OK=false;
				}
			}
			if (this.x<=0)	{
				for (int i=0;i<Pacman.level3.size();i++)	{
					w=(Wall)Pacman.level3.elementAt(i);
					if ((w.x1==400) || ((w.x1+w.length==425) && (!w.vertical)))	{
						if (w.vertical)	{
							if ((w.y1<this.y+10) && (w.y1+w.length>this.y))
								OK=false;
						}
						else	{
							if ((w.y1<this.y+10) && (w.y1+Wall.width>this.y))
								OK=false;
						}
					}
				}
			}
		}
		else if (Pacman.level==4)	{
			for (int i=0;i<Pacman.levelCustom.size();i++)	{
				w=(Wall)Pacman.levelCustom.elementAt(i);
				if (w.vertical)	{
					if (((!(this.x>w.x1+Wall.width)) && (this.y+10>w.y1) && (this.y<w.y1+w.length)) && !(this.x<w.x1))
						OK=false;
				} else	{
					if (((!(this.x>w.x1+w.length)) && (this.y+10>w.y1) && (this.y<w.y1+Wall.width)) && !(this.x<w.x1))
						OK=false;
				}
			}
			if (this.x<=0)	{
				for (int i=0;i<Pacman.levelCustom.size();i++)	{
					w=(Wall)Pacman.levelCustom.elementAt(i);
					if ((w.x1==400) || (w.x1+w.length==425))	{
						if (w.vertical)	{
							if ((w.y1<this.y+10) && (w.y1+w.length>this.y))
								OK=false;
						}
						else	{
							if ((w.y1<this.y+10) && (w.y1+Wall.width>this.y))
								OK=false;
						}
					}
				}
			}
		}
		return OK;
	}
	public boolean checkDown()	{
		boolean OK=true;
		Wall w;
		if (Pacman.level==1)	{
			for (int i=0;i<Pacman.level1.size();i++)	{
				w=(Wall)Pacman.level1.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y+5<w.y1)) && (this.x+10>w.x1) && (this.x<w.x1+w.length)) && !(this.y>w.y1))
						OK=false;
				} else	{
					if (((!(this.y+5<w.y1)) && (this.x+10>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y>w.y1))
						OK=false;
				}
			}
		}
		else if (Pacman.level==2)	{
			for (int i=0;i<Pacman.level2.size();i++)	{
				w=(Wall)Pacman.level2.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y+5<w.y1)) && (this.x+10>w.x1) && (this.x<w.x1+w.length)) && !(this.y>w.y1))
						OK=false;
				} else	{
					if (((!(this.y+5<w.y1)) && (this.x+10>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y>w.y1))
						OK=false;
				}
			}
		}
		else if (Pacman.level==3)	{
			for (int i=0;i<Pacman.level3.size();i++)	{
				w=(Wall)Pacman.level3.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y+5<w.y1)) && (this.x+10>w.x1) && (this.x<w.x1+w.length)) && !(this.y>w.y1))
						OK=false;
				} else	{
					if (((!(this.y+5<w.y1)) && (this.x+10>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y>w.y1))
						OK=false;
				}
			}
			if (this.y>=375)	{
				for (int i=0;i<Pacman.level3.size();i++)	{
					w=(Wall)Pacman.level3.elementAt(i);
					if (w.y1==0)	{
						if (w.vertical)	{
							if ((this.x<w.x1+25) && (this.x+10>w.x1))
								OK=false;
						}
						else	{
							if ((this.x<w.x1+w.length) && (this.x+10>w.x1))
								OK=false;
						}
					}
				}
			}
		}
		else if (Pacman.level==4)	{
			for (int i=0;i<Pacman.levelCustom.size();i++)	{
				w=(Wall)Pacman.levelCustom.elementAt(i);
				if (!w.vertical)	{
					if (((!(this.y+5<w.y1)) && (this.x+10>w.x1) && (this.x<w.x1+w.length)) && !(this.y>w.y1))
						OK=false;
				} else	{
					if (((!(this.y+5<w.y1)) && (this.x+10>w.x1) && (this.x<w.x1+Wall.width)) && !(this.y>w.y1))
						OK=false;
				}
			}
			if (this.y>=375)	{
				for (int i=0;i<Pacman.levelCustom.size();i++)	{
					w=(Wall)Pacman.levelCustom.elementAt(i);
					if (w.y1==0)	{
						if (w.vertical)	{
							if ((this.x<w.x1+25) && (this.x+10>w.x1))
								OK=false;
						}
						else	{
							if ((this.x<w.x1+w.length) && (this.x+10>w.x1))
								OK=false;
						}
					}
				}
			}
		}
		return OK;
	}
	public void checkMine()	{
		for (int i=0;i<Pacman.mineVector.size();i++)	{
			mine m=(mine)Pacman.mineVector.elementAt(i);
			if ((m.x+25>this.x) && (m.x<this.x+5) && (m.y+25>this.y) && (m.y<this.y+5) && (m.alive))	{
				g.setColor(Color.black);
				g.fillOval(this.x, this.y, this.radius, this.radius);
				this.stopped=true;
				m.explode(this.dir, true);
			}
		}
	}
}
class mine	{
	int x;
	int y;
	Color col;
	boolean p, alive;
	int serial;
	mine(int x, int y, boolean p, char dir)	{
		if (dir=='r')	{
			this.x=x-25;
			this.y=y;
		}
		else if (dir=='d')	{
			this.x=x;
			this.y=y-25;
		}
		else if (dir=='l')	{
			this.x=x+25;
			this.y=y;
		}
		else if (dir=='u')	{
			this.x=x;
			this.y=y+25;
		}
		this.p=p;
		if (!p)
			this.col=Color.blue;
		else
			this.col=Color.yellow;
		this.alive=true;
		this.draw();
	}
	public void draw()	{
		Pacman.gfx.setColor(this.col);
		Pacman.gfx.fillOval(this.x, this.y, 25,25);
		Pacman.gfx.setColor(Color.black);
		Pacman.gfx.drawString("MINE",this.x, this.y+18);
		MineThread mt=new MineThread();
		mt.init(this, Pacman.gfx, 900);
		mt.start();
	}
	public synchronized void explode(char dir, boolean debris)	{
		try	{
			Pacman.playSound('e');
		} catch(Exception e)	{System.out.println("NO SOUND EXPLODE");}
			Pacman.mineVector.removeElementAt(this.serial);
			this.alive=false;
			Pacman.gfx.setColor(this.col);
			Pacman.gfx.fillOval(this.x, this.y, 25,25);
			Pacman.gfx.setColor(Color.black);
			Pacman.gfx.setFont(new Font("Times",Font.ITALIC,7));
			Pacman.gfx.drawString("BOOM!",this.x, this.y+18);
			Pacman.gfx.setFont(Pacman.normalFont);
			for (int i=0;i<Pacman.mineVector.size();i++)	{
				mine m=(mine)Pacman.mineVector.elementAt(i);
				m.serial=i;
			}
		if (debris)	{
			bullet b=new bullet(this.x, this.y, this.p, 'u');
			if (!(dir=='d') && (b.checkUp()))	{
				b.serial=Pacman.bulletVector.size();
				b.start();
				Pacman.bulletVector.addElement(b);
			}
			b=new bullet(this.x, this.y, this.p, 'd');
			if (!(dir=='u') && (b.checkDown()))	{
				b.serial=Pacman.bulletVector.size();
				b.start();
				Pacman.bulletVector.addElement(b);
			}
			b=new bullet(this.x, this.y, this.p, 'r');
			if (!(dir=='l') && (b.checkRight()))	{
				b.serial=Pacman.bulletVector.size();
				b.start();
				Pacman.bulletVector.addElement(b);
			}
			b=new bullet(this.x, this.y, this.p, 'l');
			if (!(dir=='r') && (b.checkLeft()))	{
				b.serial=Pacman.bulletVector.size();
				b.start();
				Pacman.bulletVector.addElement(b);
			}
		}
		MineThread mt=new MineThread();
		mt.init(this,Pacman.gfx,500);
		mt.start();
	}
}
class MineThread extends Thread	{
	mine m;
	Graphics g;
	int delay;
	public void init(mine m, Graphics g, int sleepDelay)	{
		this.m=m;
		this.g=g;
		this.delay=sleepDelay;
	}
	public void run()	{
		try	{
			Thread.sleep(delay);
		} catch(Exception e)	{}
		g.setColor(Color.black);
		g.fillOval(m.x, m.y, 25, 25);
	}
}

Back to the PacWars applet page

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.