/* Written by Ramses Smeyers (rsmeyers@khk.org). Copyright (C) 2000 Ramses Smeyers This software may be used and distributed according to the terms of the GNU Public License, incorporated herein by reference. tux, tux_g and bsd taken from xtux by David Lawrence (philaw@camtech.net.au) bill taken from xbill by Brian Wellington and Matias Duarte images prepared by Dolphin (wim@hal.theo.kuleuven.ac.be) */ #define NOLOOP //#define LOOP #undef LOOP import java.awt.*; import java.applet.*; public class thread extends Thread { private int type,direction,frame,movement; private int xpos, ypos,borderX,borderY,borderB,borderH;; private Graphics g; private Image images [][]; private animation Animation; private double r1; private World world; private boolean go,back,other,exitthis; private int directionbackup; public thread (Graphics g,World world,Image[][] images,int type, int direction,int frame ,int xpos,int ypos, int borderX, int borderY, int borderB, int borderH,int movement) { this.type = type; this.direction = direction; this.frame = frame; this.g = g; this.xpos = xpos; this.ypos = ypos; this.images = images; this.borderX = borderX; this.borderY = borderY; this.borderB = borderB; this.borderH = borderH; this.movement = movement; this.world = world; Animation= new animation(g,world,images, type,direction,frame,xpos,ypos,borderX,borderY,borderB,borderH,movement); Animation.teken(); }; public void run(){ #if LOOP if (type==0 || type = 2) { while (true){ switch(direction){ case 0: go = Animation.checkRight(); if (go) Animation.goRight(); break; case 1: go = Animation.checkUp(); if (go) Animation.goUp(); break; case 2: go = Animation.checkDown(); if (go) Animation.goDown(); break; case 3: go = Animation.checkLeft(); if (go) Animation.goLeft(); break; } } } else{ #endif r1=Math.random(); r1 = 4*r1; direction = (int)r1; Animation.setDirection(direction); while (true){ go = false; switch(direction){ case 0: go = Animation.checkRight(); if (go) Animation.goRight(); break; case 1: go = Animation.checkUp(); if (go) Animation.goUp(); break; case 2: go = Animation.checkDown(); if (go) Animation.goDown(); break; case 3: go = Animation.checkLeft(); if (go) Animation.goLeft(); break; } directionbackup = direction; other=false; if (go){ switch(direction){ case 0: if (richtingCheck(1) || richtingCheck(2)) other=true; break; case 1: if (richtingCheck(3) || richtingCheck(0)) other=true; break; case 2: if (richtingCheck(3) || richtingCheck(0)) other=true; break; case 3: if (richtingCheck(1) || richtingCheck(2)) other=true; break; } } if (other) { while (true){ r1=Math.random(); r1 = 4*r1; direction = (int)r1; Animation.setDirection(direction); exitthis = false; switch(directionbackup){ case 0: if (direction != 3 && richtingCheck(direction)) exitthis=true; break; case 1: if (direction != 2 && richtingCheck(direction)) exitthis=true; break; case 2: if (direction != 1 && richtingCheck(direction)) exitthis=true; break; case 3: if (direction != 0 && richtingCheck(direction)) exitthis=true; break; } if (exitthis==true) break; } } if (!go){ // the for lus is for fall back onnly when // AI character is locked for (int i=1;i<10;i++){ r1=Math.random(); r1 = 4*r1; direction = (int)r1; Animation.setDirection(direction); exitthis = false; switch(directionbackup){ case 0: if (direction != 0 && direction != 3 && richtingCheck(direction)) exitthis=true; break; case 1: if (direction != 1 && direction != 2 && richtingCheck(direction)) exitthis=true; break; case 2: if (direction != 2 && direction != 1 && richtingCheck(direction)) exitthis=true; break; case 3: if (direction != 3 && direction != 0 && richtingCheck(direction)) exitthis=true; break; } if (exitthis==true) break; } } } #if LOOP } #endif } public boolean richtingCheck(int direction){ switch(direction){ case 0: back = Animation.checkRight(); break; case 1: back = Animation.checkUp(); break; case 2: back = Animation.checkDown(); break; case 3: back = Animation.checkLeft(); break; } return back; } #if LOOP public void setDirection (int direction){ this.direction = direction; Animation.setDirection(direction); } public void teken(){ Animation.teken(); } public void goLeft(){ Animation.goLeft(); } #endif }