/* 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) */ import java.awt.*; import java.applet.*; class animation extends Applet { // e n s w // e = 0 // n = 1 // s = 2 // w = 3 private int type,direction,frame,movement; private int xpos, ypos,borderX,borderY,borderB,borderH;; private Graphics g; private Image images [][]; //private int timetosleep=100; private int timetosleep=90; //private int timetosleep=50; private World world; public animation (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; // Just flushing all the pictures, dunno why, but I have to flush(); }; public void teken () { g.drawImage(images[type][direction * 3 +frame],xpos,ypos,62,62,this); }; public void flush(){ g.drawImage(images[type][0],100,100,62,62,this); g.drawImage(images[type][1],100,100,62,62,this); g.drawImage(images[type][2],100,100,62,62,this); g.drawImage(images[type][3],100,100,62,62,this); g.drawImage(images[type][4],100,100,62,62,this); g.drawImage(images[type][5],100,100,62,62,this); g.drawImage(images[type][6],100,100,62,62,this); g.drawImage(images[type][7],100,100,62,62,this); g.drawImage(images[type][8],100,100,62,62,this); g.drawImage(images[type][9],100,100,62,62,this); g.drawImage(images[type][10],100,100,62,62,this); g.drawImage(images[type][11],100,100,62,62,this); } // Animatie zelf public void wis() { g.setColor(Color.white); g.fillRect(xpos,ypos,62,62); } public void goDown (){ if (direction ==2) { direction=2; frame=1; wis(); ypos =ypos + movement; teken(); slaap(timetosleep); frame=2; wis(); ypos =ypos + movement; teken(); slaap(timetosleep); frame=0; wis(); ypos =ypos + movement; teken(); dotControl(); } else{ direction=2; frame=0; wis(); teken(); } } public void goUp (){ if (direction ==1) { direction=1; frame=1; wis(); ypos =ypos - movement; teken(); slaap(timetosleep); frame=2; wis(); ypos =ypos - movement; teken(); slaap(timetosleep); frame=0; wis(); ypos =ypos - movement; teken(); dotControl(); } else{ direction=1; frame=0; wis(); teken(); } } public void goLeft(){ if (direction ==3) { direction=3; frame=1; wis(); xpos =xpos - movement; teken(); slaap(timetosleep); frame=2; wis(); xpos =xpos - movement; teken(); slaap(timetosleep); frame=0; wis(); xpos =xpos - movement; teken(); dotControl(); } else{ direction=3; frame=0; wis(); teken(); } } public void goRight(){ if (direction ==0) { direction=0; frame=1; wis(); xpos =xpos + movement; teken(); slaap(timetosleep); frame=2; wis(); xpos =xpos + movement; teken(); slaap(timetosleep); frame=0; wis(); xpos =xpos + movement; teken(); dotControl(); } else{ direction=0; frame=0; wis(); teken(); } } // Bordercontrol // a.d.h.v. borderX,borderY,borderB,borderH;; public boolean checkLeft(){ if ((xpos -(movement*3)) <= borderX) { if (direction == 3) { return false;} else { return true;} } else { if (world.checkMoveLeft(xpos,ypos)) return true; else return false ;} } public boolean checkRight(){ if ((xpos +(movement*3)+62) >= (borderX+borderB)) { if (direction == 0) { return false;} else { return true;} } else { if (world.checkMoveRight(xpos,ypos)) return true; else return false ;} } public boolean checkUp(){ if ((ypos -(movement*3)) <= borderY) { if (direction == 1) { return false;} else { return true;} } else { if (world.checkMoveUp(xpos,ypos)) return true; else return false ;} } public boolean checkDown(){ if ((ypos +(movement*3)+62) >= (borderY+borderH)) { if (direction == 2) { return false;} else { return true;} } else { if (world.checkMoveDown(xpos,ypos)) return true; else return false ;} } // Algemene functies public void slaap(int millisec){ try{Thread.sleep(millisec);} catch(InterruptedException e){} } public void setDirection (int direction){ this.direction = direction; } //dotcontrol public void dotControl(){ if (type !=0 && type != 2){ world.aiMove(xpos,ypos); } else{ world.dotRemove(xpos,ypos); world.aiMove(xpos,ypos); } } }