/* 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 #define ai0 #define ai1 #define ai2 #define tux //#define tux_g #undef tux_g #define bsd #define bill #define NOTRANS #undef TRANS import java.awt.*; import java.applet.*; import java.awt.event.*; import java.awt.image.*; public class Applet1 extends Applet implements KeyListener { #if NOLOOP private animation tux0; #endif #if LOOP private thread tux0; #endif #if ai0 private thread ai0; #endif #if ai1 private thread ai1; #endif #if ai2 private thread ai2; #endif private World world; private int worldnumber=0; private int movement=2, direction=3; Image images[][]; private int width = 624; private int height = 500; public void init(){ setBackground(Color.white); images = new Image[4][12]; #if NOTRANS #if tux images[0][0] = getImage(getDocumentBase(),"tux/e1.jpg"); images[0][1] = getImage(getDocumentBase(),"tux/e2.jpg"); images[0][2] = getImage(getDocumentBase(),"tux/e3.jpg"); images[0][3] = getImage(getDocumentBase(),"tux/n1.jpg"); images[0][4] = getImage(getDocumentBase(),"tux/n2.jpg"); images[0][5] = getImage(getDocumentBase(),"tux/n3.jpg"); images[0][6] = getImage(getDocumentBase(),"tux/s1.jpg"); images[0][7] = getImage(getDocumentBase(),"tux/s2.jpg"); images[0][8] = getImage(getDocumentBase(),"tux/s3.jpg"); images[0][9] = getImage(getDocumentBase(),"tux/w1.jpg"); images[0][10] = getImage(getDocumentBase(),"tux/w2.jpg"); images[0][11] = getImage(getDocumentBase(),"tux/w3.jpg"); #endif #endif #if TRANS #if tux images [0][0]=Transparent("tux/e1.jpg"); images [0][1]=Transparent("tux/e2.jpg"); images [0][2]=Transparent("tux/e3.jpg"); images [0][3]=Transparent("tux/n1.jpg"); images [0][4]=Transparent("tux/n2.jpg"); images [0][5]=Transparent("tux/n3.jpg"); images [0][6]=Transparent("tux/s1.jpg"); images [0][7]=Transparent("tux/s2.jpg"); images [0][8]=Transparent("tux/s3.jpg"); images [0][9]=Transparent("tux/w1.jpg"); images [0][10]=Transparent("tux/w2.jpg"); images [0][11]=Transparent("tux/w3.jpg"); #endif #endif #if bsd images[1][0] = getImage(getDocumentBase(),"bsd/e1.jpg"); images[1][1] = getImage(getDocumentBase(),"bsd/e2.jpg"); images[1][2] = getImage(getDocumentBase(),"bsd/e3.jpg"); images[1][3] = getImage(getDocumentBase(),"bsd/n1.jpg"); images[1][4] = getImage(getDocumentBase(),"bsd/n2.jpg"); images[1][5] = getImage(getDocumentBase(),"bsd/n3.jpg"); images[1][6] = getImage(getDocumentBase(),"bsd/s1.jpg"); images[1][7] = getImage(getDocumentBase(),"bsd/s2.jpg"); images[1][8] = getImage(getDocumentBase(),"bsd/s3.jpg"); images[1][9] = getImage(getDocumentBase(),"bsd/w1.jpg"); images[1][10] = getImage(getDocumentBase(),"bsd/w2.jpg"); images[1][11] = getImage(getDocumentBase(),"bsd/w3.jpg"); #endif #if tux_g images[2][0] = getImage(getDocumentBase(),"tux_g/e1.jpg"); images[2][1] = getImage(getDocumentBase(),"tux_g/e2.jpg"); images[2][2] = getImage(getDocumentBase(),"tux_g/e3.jpg"); images[2][3] = getImage(getDocumentBase(),"tux_g/n1.jpg"); images[2][4] = getImage(getDocumentBase(),"tux_g/n2.jpg"); images[2][5] = getImage(getDocumentBase(),"tux_g/n3.jpg"); images[2][6] = getImage(getDocumentBase(),"tux_g/s1.jpg"); images[2][7] = getImage(getDocumentBase(),"tux_g/s2.jpg"); images[2][8] = getImage(getDocumentBase(),"tux_g/s3.jpg"); images[2][9] = getImage(getDocumentBase(),"tux_g/w1.jpg"); images[2][10] = getImage(getDocumentBase(),"tux_g/w2.jpg"); images[2][11] = getImage(getDocumentBase(),"tux_g/w3.jpg"); #endif #if bill images[3][0] = getImage(getDocumentBase(),"bill/e1.jpg"); images[3][1] = getImage(getDocumentBase(),"bill/e2.jpg"); images[3][2] = getImage(getDocumentBase(),"bill/e3.jpg"); images[3][3] = getImage(getDocumentBase(),"bill/n1.jpg"); images[3][4] = getImage(getDocumentBase(),"bill/n2.jpg"); images[3][5] = getImage(getDocumentBase(),"bill/n3.jpg"); images[3][6] = getImage(getDocumentBase(),"bill/s1.jpg"); images[3][7] = getImage(getDocumentBase(),"bill/s2.jpg"); images[3][8] = getImage(getDocumentBase(),"bill/s3.jpg"); images[3][9] = getImage(getDocumentBase(),"bill/w1.jpg"); images[3][10] = getImage(getDocumentBase(),"bill/w2.jpg"); images[3][11] = getImage(getDocumentBase(),"bill/w3.jpg"); #endif world = new World(getGraphics(),worldnumber,width,height,movement); #if NOLOOP tux0= new animation(getGraphics(),world,images, 0,direction,0,272,116,1,1,width,height,movement); #endif addKeyListener(this); requestFocus(); } public void keyPressed (KeyEvent e){ int keyCode = e.getKeyCode(); switch(keyCode){ case KeyEvent.VK_DOWN: #if NOLOOP if (tux0.checkDown()) tux0.goDown (); #endif #if LOOP tux0.setDirection(2); #endif break; case KeyEvent.VK_UP: #if NOLOOP if (tux0.checkUp()) tux0.goUp(); #endif #if LOOP tux0.setDirection(1); #endif break; case KeyEvent.VK_RIGHT: #if NOLOOP if (tux0.checkRight()) tux0.goRight (); #endif #if LOOP tux0.setDirection(0); #endif break; case KeyEvent.VK_LEFT: #if NOLOOP if (tux0.checkLeft()) tux0.goLeft (); #endif #if LOOP tux0.setDirection(3); #endif break; } } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} public void paint(Graphics g){ world.teken(); tux0.teken(); tux0.teken(); } public void start(){ #if LOOP if (tux0==null){ tux0 = new thread(getGraphics(),world,images, 0,direction,0,272,116,1,1,width,height,movement); tux0.start(); } #endif #if ai0 if (ai0==null){ ai0 = new thread(getGraphics(),world,images, 1,0,0,260,182,1,1,width,height,movement); ai0.start(); } #endif #if ai1 if (ai1==null){ ai1 = new thread(getGraphics(),world,images, 3,0,0,296,260,1,1,width,height,movement); ai1.start(); } #endif #if ai2 if (ai2==null){ ai2 = new thread(getGraphics(),world,images, 3,0,0,314,182,1,1,width,height,movement); ai2.start(); } #endif } public void stop(){ #if LOOP if (tux0!=null){ tux0.stop(); tux0=null; } #endif #if ai0 if (ai0!=null){ ai0.stop(); ai0=null; } #endif #if ai1 if (ai1!=null){ ai1.stop(); ai1=null; } #endif #if ai2 if (ai2!=null){ ai2.stop(); ai2=null; } #endif } public Image Transparent(String file){ Image rawImage; int rawWidth; int rawHeight; Image modImage; int inTop; int inLeft; rawImage = Toolkit.getDefaultToolkit().getImage(file); MediaTracker tracker = new MediaTracker(this); tracker.addImage(rawImage,1); try{ if(!tracker.waitForID(1,10000)){ System.out.println("Load error."); System.exit(1); } }catch(InterruptedException e){System.out.println(e);} rawWidth = rawImage.getWidth(this); rawHeight = rawImage.getHeight(this); this.setVisible(true); int[] pix = new int[rawWidth * rawHeight]; try{ PixelGrabber pgObj = new PixelGrabber( rawImage,0,0,rawWidth,rawHeight, pix,0,rawWidth); if(pgObj.grabPixels() && ((pgObj.getStatus() & ImageObserver.ALLBITS) != 0)){ for(int cnt = 0; cnt < (rawWidth*rawHeight);cnt++){ if (pix[cnt] >= 0xFFFFFFFF) pix[cnt]=0x00FFFFFF; } } else System.out.println("Pixel grab not successful"); }catch(InterruptedException e){System.out.println(e);} modImage = this.createImage( new MemoryImageSource( rawWidth,rawHeight,pix,0,rawWidth)); return modImage; } };