home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-05-17 | 37.2 KB | 1,402 lines |
- //****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.net.URL;
-
- public class Pacman extends Applet {
- final static int appletWidth=425, appletHeight=440;
- static Pacmen p=null, p2=null;
- Wall w=null;
- static int level, score, lives;
- int size;
- //int loading=0, xLoading=0;
- //double kl=0;
- //boolean loadingDir=true;
- boolean started=false;
- static Vector level1, level2, level3, levelCustom;
- //MediaTracker pacImageTracker=null, DTracker=null, UTracker=null;
- static Graphics gfx;
- static boolean[][] customArray;
- static boolean mapEditorOn;
- Choice mapChoice, instructions, colorChoice, editorInstructions;
- setPanel choicePanel;
- ColorThread ct;
- //Pacmen.PacRight=null;
- //Pacmen.PacLeft=null;
- //Pacmen.PacUp=null;
- //Pacmen.PacDown=null;
- //static Image i1,i2,i3,i4;
- public void init() {
- //System.out.println("initialize MY ASS");
- //pacImageTracker=new MediaTracker(this);
- //pacLeftTracker=new MediaTracker(this);
- //DTracker=new MediaTracker(this);
- //UTracker=new MediaTracker(this);
- //i1=getImage(getCodeBase(),"PacRight.gif");
- //i2=getImage(getCodeBase(),"PacLeft.gif");
- //i3=getImage(getCodeBase(),"PacUp.gif");
- //i4=getImage(getCodeBase(),"PacDown.gif");
- //pacImageTracker.addImage(i1,1);
- //pacImageTracker.addImage(i2,1);
- //UTracker.addImage(i3,1);
- //DTracker.addImage(i4,1);
- //pacImageTracker.checkID(1,true);
- Pacmen.g=getGraphics();
- level1=new Vector();
- level2=new Vector();
- level3=new Vector();
- levelCustom=new Vector();
- gfx=getGraphics();
- ////////////////////////
- gfx.drawString("DRAW MY ASS",200,200);
- initLevel1();
- level=0;
- choicePanel=new setPanel(425,58);
- 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 for the");
- instructions.addItem("IT pac-person to tag the other one.");
- instructions.addItem("Player one starts being IT, and they");
- instructions.addItem("use the W, A, S, and D keys to move.");
- instructions.addItem("Player two uses the arrow keys");
- instructions.addItem("Copyright ⌐ 1999 David Kaplan");
- instructions.addItem("davkapl@aol.com");
- instructions.addItem("http://members.aol.com/davkapl");
- 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("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];
- ct=new ColorThread();
- //System.out.println("initialize MY ASS");
- }
- public void start() {
- //try {
- //pacImageTracker.waitForID(1);
- ///pacLeftTracker.waitForID(1);
- //DTracker.waitForID(1);
- //UTracker.waitForID(1);
- //} catch (Exception e) {}
- //System.out.println("start MY ASS");
- // gfx.drawString("PLEASE wklahjsldfhdlksnfkln",200,200);
- //while ((!pacImageTracker.checkAll(true))) {
- // System.out.println("loop MY ASS");
- // System.out.println(level);
- // System.out.println(pacImageTracker.checkAll(true));
- // System.out.println(DTracker.checkAll(true));
- // System.out.println(UTracker.checkAll(true));
- // if (pacImageTracker.checkAll(true))
- // System.out.println("TWO IS>>>IS WHAT I GOT");
- //try{
- // Thread.sleep(20);
- //} catch (Exception e){}
- repaint();
- // if (kl%10000==0) {
- // if (loadingDir) {
- // if (xLoading<270)
- // xLoading++;
- // else
- // loadingDir=!loadingDir;
- // }
- // else {
- // if (xLoading>0)
- // xLoading--;
- // else
- // loadingDir=!loadingDir;
- // }
- // }
- // if (kl%200000==0)
- // loading++;
- //}
- // while (!pacImageTracker.checkAll(true)) {
- // repaint();
- // }
- //level=1;
- //if ((pacImageTracker.checkAll(true))) {
- p=new Pacmen(375,350,true,true);
- p2=new Pacmen(25,25,false,false);
- //}
- }
- public void paint(Graphics g) {
- //if ((pacImageTracker.checkAll(true)) && (UTracker.checkAll(true)) && (DTracker.checkAll(true))) {
- g.setColor(Color.black);
- g.fillRect(0,0,appletWidth,appletHeight);
- // System.out.println("PLEASE ESPERA");
- //} else {
- // g.setColor(Color.green);
- // g.drawString("PLEASE WAIT",200,150);
- // g.setColor(Color.blue);
- // g.fillRect(40,180,40,30);
- // System.out.println("PLEASE ESPERA");
- //}
- if (level==1) {
- for (int i=0;i<level1.size();i++) {
- w=(Wall)level1.elementAt(i);
- w.draw(g);
- }
- }
- else if (level==2) {
- for (int i=0;i<level2.size();i++) {
- w=(Wall)level2.elementAt(i);
- w.draw(g);
- }
- }
- else if (level==3) {
- for (int i=0;i<level3.size();i++) {
- w=(Wall)level3.elementAt(i);
- w.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);
- }
- }
- 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);
- }
- if (!started) {
- g.setColor(Color.green);
- g.drawString("Click to begin",200,200);
- }
- g.setColor(Color.white);
- g.fillRect(0,appletHeight-40,appletWidth,40);
- g.setColor(Color.black);
- //if ((level>0) && ((pacImageTracker.checkAll(true)) && (!UTracker.checkAll(true)) && (!DTracker.checkAll(true))))
- if (level>0)
- Pacman.updateStatusBar();
- }
- public boolean keyDown(Event e,int key) {
- if (key==1004) {
- if (p.checkUp())
- p.dir='u';
- else
- p.waitingUp=true;
- }
- if (key==1005) {
- if (p.checkDown())
- p.dir='d';
- else
- p.waitingDown=true;
- }
- if (key==1006) {
- if (p.checkLeft())
- p.dir='l';
- else
- p.waitingLeft=true;
- }
- if (key==1007) {
- if (p.checkRight())
- p.dir='r';
- else
- p.waitingRight=true;
- }
- if (key==119) {
- if (p2.checkUp())
- p2.dir='u';
- else
- p2.waitingUp=true;
- }
- if (key==115) {
- if (p2.checkDown())
- p2.dir='d';
- else
- p2.waitingDown=true;
- }
- if (key==97) {
- if (p2.checkLeft())
- p2.dir='l';
- else
- p2.waitingLeft=true;
- }
- if (key==100) {
- if (p2.checkRight())
- p2.dir='r';
- else
- p2.waitingRight=true;
- }
- return super.keyDown(e,key);
- }
- public boolean keyUp(Event e, int key) {
- if (key==1004) {
- p.waitingUp=false;
- }
- if (key==1005) {
- p.waitingDown=false;
- }
- if (key==1006) {
- p.waitingLeft=false;
- }
- if (key==1007) {
- p.waitingRight=false;
- }
- if (key==119) {
- p2.waitingUp=false;
- }
- if (key==115) {
- p2.waitingDown=false;
- }
- if (key==97) {
- p2.waitingLeft=false;
- }
- if (key==100) {
- p2.waitingRight=false;
- }
- 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) {
- int a1=x/25;
- int a2=y/25;
- if (!(((a1==1) && (a2==1)) || ((a1==15) && (a2==14)))) {
- customArray[a1][a2]=!customArray[a1][a2];
- repaint();
- }
- }
- return super.mouseDown(e, x, y);
- }
- static public void updateStatusBar() {
- gfx.setColor(Color.white);
- gfx.fillRect(0,appletHeight-40,400,40);
- gfx.setColor(Color.black);
- if (!p.it) {
- gfx.drawString("Player One: You're it! Tag player two!",100,appletHeight-28);
- gfx.drawString("Player Two: Escape! Don't let player one get you!",100,appletHeight-17);
- } else {
- gfx.drawString("Player One: Escape! Don't let player two get you!",100,appletHeight-28);
- gfx.drawString("Player Two: You're it! Tag player one!",100,appletHeight-17);
- }
- }
- 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,75,true);
- level2.addElement(w);
- w=new Wall(75,225,100,true);
- level2.addElement(w);
- w=new Wall(325,75,75,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));
- }
- }
- }
- static public void tag(int x, int y) {
- p.it=!p.it;
- p2.it=!p2.it;
- gfx.setColor(Color.black);
- gfx.fillRect(p.x,p.y,25,25);
- gfx.fillRect(p2.x,p2.y,25,25);
- if (x<200) {
- if (p.it) {
- p.x=375;
- p.y=350;
- //p.c=Pacmen.itColor;
- //p2.c=Color.yellow;
- } else {
- p2.x=375;
- p2.y=350;
- //p.c=Color.yellow;
- //p2.c=Pacmen.itColor;
- }
- } else {
- if (p.it) {
- p.x=25;
- p.y=25;
- //p.c=Pacmen.itColor;
- //p2.c=Color.yellow;
- } else {
- p2.x=25;
- p2.y=25;
- //p.c=Color.yellow;
- //p2.c=Pacmen.itColor;
- }
- }
- if (p.it) {
- p.delay=Pacmen.itDelay;
- p2.delay=Pacmen.escapeDelay;
- } else {
- p.delay=Pacmen.escapeDelay;
- p2.delay=Pacmen.itDelay;
- }
- updateStatusBar();
- }
- public boolean action(Event e, Object arg) {
- if (e.target==mapChoice) {
- 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();
- 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);
- repaint();
- }
- if (i<4)
- newGame();
- }
- if (e.target==instructions) {
- if (instructions.getSelectedIndex()==8)
- try {
- getAppletContext().showDocument(new URL("http://members.aol.com/davkapl"));
- } catch(Exception malformedurl) {}
- }
- return super.action(e, arg);
- }
- public void newGame() {
- p.stop();
- p2.stop();
- p=new Pacmen(25,25,true,true);
- p2=new Pacmen(375,350,false,false);
- p.start();
- p2.start();
- repaint();
- updateStatusBar();
- }
- public void destroy() {
- }
- }
- 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(10);
- } 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 Image PacRight, PacUp, PacLeft, PacDown;
- //Color c=new Color(127,127,0);
- static Color itColor=new Color(255,255,0), itColor2=new Color(0,0,255);
- static Graphics g;
- char dir='r';
- boolean p;
- int x, y;
- int stage=44;
- boolean closing=true;
- static boolean toYellow=true, toGreen=false;
- final static int escapeDelay=8;
- final static int itDelay=6;
- static boolean alive=true;
- boolean it;
- static Font itFont=new Font("Geneva",Font.PLAIN,10);
- boolean waitingUp=false, waitingDown=false, waitingRight=false, waitingLeft=false;
- short delay;
- final static int pacWidth=25, pacHeight=25;
- Pacmen(int x, int y, boolean it, boolean p) {
- this.x=x;
- this.y=y;
- this.it=it;
- this.p=p;
- if (it) {
- this.delay=itDelay;
- //this.c=Color.orange;
- }
- else {
- this.delay=escapeDelay;
- //this.c=Color.yellow;
- }
- }
- public void run() {
- while (alive) {
- if (closing) {
- if (stage>0)
- stage-=2;
- else {
- stage+=2;
- closing=false;
- }
- }
- else {
- if (stage<44)
- stage+=2;
- else {
- stage-=2;
- closing=true;
- }
- }
- if (this.dir=='r') {
- //g.drawImage(PacRight,this.x,this.y,new Pacman());
- if (this.it) {
- 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);
- if (this.it) {
- g.setColor(Color.black);
- g.setFont(itFont);
- g.drawString("IT",this.x+9,this.y+17);
- }
- 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;
- 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==Pacman.p) {
- if ((this.x+25>Pacman.p2.x) && (this.x<Pacman.p2.x+25) && (this.y+25>Pacman.p2.y) && (this.y<Pacman.p2.y+25)) {
- Pacman.tag(this.x, this.y);
- }
- } else {
- if ((this.x+25>Pacman.p.x) && (this.x<Pacman.p.x+25) && (this.y+25>Pacman.p.y) && (this.y<Pacman.p.y+25)) {
- Pacman.tag(this.x, this.y);
- }
- }
- }
- }
- if (this.dir=='u') {
- //g.drawImage(PacUp, this.x, this.y, new Pacman());
- if (this.it) {
- 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);
- if (this.it) {
- g.setColor(Color.black);
- g.setFont(itFont);
- g.drawString("IT",this.x+9,this.y+17);
- }
- 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;
- 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==Pacman.p) {
- if ((this.x+25>Pacman.p2.x) && (this.x<Pacman.p2.x+25) && (this.y+25>Pacman.p2.y) && (this.y<Pacman.p2.y+25)) {
- Pacman.tag(this.x, this.y);
- }
- } else {
- if ((this.x+25>Pacman.p.x) && (this.x<Pacman.p.x+25) && (this.y+25>Pacman.p.y) && (this.y<Pacman.p.y+25)) {
- Pacman.tag(this.x, this.y);
- }
- }
- }
- }
- if (this.dir=='l') {
- //g.drawImage(PacLeft, this.x, this.y, new Pacman());
- if (this.it) {
- 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);
- if (this.it) {
- g.setColor(Color.black);
- g.setFont(itFont);
- g.drawString("IT",this.x+9,this.y+17);
- }
- 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;
- 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==Pacman.p) {
- if ((this.x+25>Pacman.p2.x) && (this.x<Pacman.p2.x+25) && (this.y+25>Pacman.p2.y) && (this.y<Pacman.p2.y+25)) {
- Pacman.tag(this.x, this.y);
- }
- } else {
- if ((this.x+25>Pacman.p.x) && (this.x<Pacman.p.x+25) && (this.y+25>Pacman.p.y) && (this.y<Pacman.p.y+25)) {
- Pacman.tag(this.x, this.y);
- }
- }
- }
- }
- if (this.dir=='d') {
- //g.drawImage(PacDown, this.x, this.y, new Pacman());
- if (this.it) {
- 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);
- if (this.it) {
- g.setColor(Color.black);
- g.setFont(itFont);
- g.drawString("IT",this.x+9,this.y+17);
- }
- 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;
- if (this.waitingRight) {
- if (checkRight())
- this.dir='r';
- }
- if (this.waitingLeft) {
- if (checkLeft())
- this.dir='l';
- }
- if (this.waitingUp) {
- if (checkUp())
- this.dir='u';
- }
- if (this==Pacman.p) {
- if ((this.x+25>Pacman.p2.x) && (this.x<Pacman.p2.x+25) && (this.y+25>Pacman.p2.y) && (this.y<Pacman.p2.y+25)) {
- Pacman.tag(this.x, this.y);
- }
- } else {
- if ((this.x+25>Pacman.p.x) && (this.x<Pacman.p.x+25) && (this.y+25>Pacman.p.y) && (this.y<Pacman.p.y+25)) {
- Pacman.tag(this.x, this.y);
- }
- }
- }
- }
- }
- }
- 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;
- }
- }
- 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 setPanel extends Panel {
- Dimension myDimension=new Dimension(425,58);
- setPanel(int width, int height) {
- myDimension.width=width;
- myDimension.height=height;
- }
- public Dimension getPreferredSize() {
- return myDimension;
- }
- public Dimension getMinimumSize() {
- return myDimension;
- }
- }