// Iceblox // By Karl Hörnell, April 8 1996 // Ported to Sharp Zaurus by Dennis Webb, June 28 2002 import java.awt.*; import java.awt.image.*; import java.net.*; public final class iceblox extends java.applet.Applet implements Runnable { int i,j,k; final int playX=240,playY=270,mainX=240,mainY=288,smalls=48,blockX=8,blockY=9; final int animP[]={7,8,9,8,10,11,12,11,4,5,6,5,1,2,3,2}; final int animF[]={32,33,34,35,36,35,34,33}; final int levFlame[]={2,3,4,2,3,4},levRock[]={5,6,7,8,9,10}; final int levSpeed[]={3,3,3,5,5,5},levIce[]={17,16,15,14,13,12}; final int effMax=5; int playArea[]; int gameState,counter,dir,inFront,inFront2,level,coins; int effLevel,lives=3; int x[],y[],dx[],dy[],motion[],look[],creature[],ccount[],actors,flames; int sideIX[]={0,-1,1,-10,10},coorDx[]={0,-30,30,0,0},coorDy[]={0,0,0,-30,30}; Image collection,offImage,playField,small[],title; Graphics offGraphics,playGraphics,tempG; MediaTracker tracker; ImageFilter filter; ImageProducer collectionProducer; long snooze=100,score; Thread game; Math m; public void init() { setBackground(Color.black); offImage=createImage(mainX,mainY); offGraphics=offImage.getGraphics(); offGraphics.setColor(Color.black); offGraphics.fillRect(0,0,mainX,mainY); playField=createImage(playX,playY); playGraphics=playField.getGraphics(); playGraphics.setColor(Color.black); tracker=new MediaTracker(this); collection = getImage(getCodeBase(),"iceblox.gif"); tracker.addImage(collection,0); try { tracker.waitForID(0); } catch(InterruptedException e) {} collectionProducer=collection.getSource(); small=new Image[smalls]; k=0;i=0;j=0; while (k6)&&(key==32)) gameState=0; else if ((gameState>6)&&(key==Event.ENTER)) gameState=0; return false; } public boolean keyUp(java.awt.Event e,int key) { dir=0; return false; } // To ensure Java 1.1 compatibility, request focus on mouseDown public boolean mouseDown(java.awt.Event e,int x, int y) { requestFocus(); return false; } public void prepareField() { int i; if (level>effMax) effLevel=effMax; else effLevel=level; offGraphics.setColor(Color.black); offGraphics.fillRect(0,0,mainX,mainY); playGraphics.setColor(Color.black); playGraphics.fillRect(0,0,playX,playY); offGraphics.setColor(Color.lightGray); offGraphics.fill3DRect(0,mainY-playY-4,mainX,4,true); offGraphics.setColor(Color.white); offGraphics.drawString("SCORE:",2,12); updateScore(0); offGraphics.drawString("LEVEL: "+(level+1),94,12); offGraphics.drawString("LIVES:",150,12); for (i=0;i1)&&(inFront<18)) // Crack ice { playArea[j+sideIX[dir]]++; if (inFront==9) // All cracked? { playGraphics.fillRect(x[i]+coorDx[dir]-30,y[i]+coorDy[dir]-30,30,30); playArea[j+sideIX[dir]]=0; updateScore(5); } else if (inFront==17) { playGraphics.fillRect(x[i]+coorDx[dir]-30,y[i]+coorDy[dir]-30,30,30); playArea[j+sideIX[dir]]=0; updateScore(100); coins++; } else playGraphics.drawImage(small[inFront+15],x[i]+coorDx[dir]-30,y[i]+coorDy[dir]-30,this); } } } if (motion[i]!=0) look[i]=animP[(motion[i]-1)*4+counter%4]; for (k=1;ky[0]) motion[i]=3; else motion[i]=4; } else if (((y[i]-y[0])<3)&&((y[0]-y[i])<3)) { if (x[i]>x[0]) motion[i]=1; else motion[i]=2; } if (playArea[j+sideIX[motion[i]]]!=0) motion[i]=0; } for (k=1;k20) { flames--; removeActor(i); } break; case 6: // Dummy break; case 7: // Skeleton if (ccount[i]<8) look[i]=39+ccount[i]; else if (ccount[i]<30) look[i]=47; else { lives--; if (lives<0) gameState=5; else { actors=1; flames=0; counter=0; dx[i]=6; dy[i]=6; creature[0]=1; look[0]=2; offGraphics.setColor(Color.black); offGraphics.fillRect(190,0,45,14); for (k=0;k4) { gameState=3; updateScore(1000); counter=0; coins=0; offGraphics.drawImage(playField,0,mainY-playY,this); } } public void happyPenguin() { if (counter>35) { level++; gameState=4; counter=0; } } public void clearField() { offGraphics.setColor(Color.black); offGraphics.fillRect(playX/2-(playX*counter/30),mainY-playY/2-(playY*counter/30), playX*counter/15,playY*counter/15); if (counter>14) gameState=0; } public void fixDeath() { offGraphics.setColor(Color.black); offGraphics.fillRect(0,0,mainX,mainY); offGraphics.setColor(Color.white); offGraphics.drawString("GAME OVER",95,100); offGraphics.drawString("You scored "+score,90,130); offGraphics.drawImage(small[2],105,150,this); counter=0; gameState=6; } public void gameOver() { if (counter>80) gameState=7; } public void drawIntro1() { level=0; score=0; lives=3; offGraphics.setColor(Color.black); offGraphics.fillRect(0,0,mainX,mainY); offGraphics.setColor(Color.white); offGraphics.drawImage(title,(mainX-224)/2,10,this); offGraphics.drawString("ACTORS AND OBJECTS",70,92); offGraphics.drawImage(small[2],65,100,this); offGraphics.drawString("Pixel Pete, the penguin",105,120); offGraphics.drawImage(small[34],45,135,this); offGraphics.drawImage(small[32],65,135,this); offGraphics.drawString("Evil flames",105,155); offGraphics.drawImage(small[16],65,170,this); offGraphics.drawString("Ice cube",105,190); offGraphics.drawImage(small[14],65,205,this); offGraphics.drawString("Solid rock",105,225); offGraphics.drawImage(small[24],65,240,this); offGraphics.drawString("Frozen gold coin",105,260); offGraphics.drawString("Press SPACE to start",63,280); counter=0; gameState=8; } public void waitIntro1() { offGraphics.setColor(Color.black); offGraphics.fillRect(45,135,50,30); offGraphics.drawImage(small[animF[(counter+2)&7]],45,135,this); offGraphics.drawImage(small[animF[counter&7]],65,135,this); if (counter>70) gameState=9; } public void drawIntro2() { offGraphics.setColor(Color.black); offGraphics.fillRect(0,75,mainX,230); offGraphics.setColor(Color.white); offGraphics.drawString("HOW TO PLAY",100,92); offGraphics.drawImage(small[2],70,100,this); offGraphics.drawString("Move up, down, left and right",110,112); offGraphics.drawString("with the directional keys",110,127); offGraphics.drawImage(small[10],0,135,this); offGraphics.drawImage(small[16],70,135,this); offGraphics.drawString("Walk against ice cubes",110,147); offGraphics.drawString("to move them out of the way",110,162); offGraphics.drawLine(30,145,68,145); offGraphics.drawLine(36,154,68,154); offGraphics.drawImage(small[10],10,170,this); offGraphics.drawImage(small[18],40,170,this); offGraphics.drawImage(small[16],70,170,this); offGraphics.drawString("Walk against blocked",110,182); offGraphics.drawString("ice cubes to crack them",110,197); offGraphics.drawImage(small[28],40,205,this); offGraphics.drawImage(small[9],70,205,this); offGraphics.drawString("Free the gold coins by",110,217); offGraphics.drawString("crushing the ice around them",110,232); offGraphics.drawImage(small[9],10,240,this); offGraphics.drawImage(small[32],70,240,this); offGraphics.drawLine(30,250,68,250); offGraphics.drawLine(30,259,64,259); offGraphics.drawString("And watch out",110,252); offGraphics.drawString("for the flames",110,267); gameState=10; counter=0; } public void waitIntro2() { offGraphics.setColor(Color.black); offGraphics.drawImage(small[1+(counter % 12)],70,100,this); offGraphics.fillRect(70,240,30,30); offGraphics.drawImage(small[animF[counter&7]],70,240,this); if (counter>80) gameState=11; } public void drawIntro3() { offGraphics.setColor(Color.black); offGraphics.fillRect(0,75,mainX,230); offGraphics.setColor(Color.white); offGraphics.drawString("SCORING",110,92); offGraphics.drawImage(small[10],40,100,this); offGraphics.drawImage(small[18],70,100,this); offGraphics.drawString("Breaking ice,",110,112); offGraphics.drawString("5 points",110,127); offGraphics.drawImage(small[33],0,135,this); offGraphics.drawImage(small[16],20,135,this); offGraphics.drawImage(small[9],80,135,this); offGraphics.drawLine(54,145, 78,145); offGraphics.drawLine(54,154,74,154); offGraphics.drawString("Putting out flame",110,147); offGraphics.drawString("with ice, 50 points",110,162); offGraphics.drawImage(small[10],40,170,this); offGraphics.drawImage(small[27],70,170,this); offGraphics.drawString("Freeing coin,",110,182); offGraphics.drawString("100 points",110,197); for (j=0;j<5;j++) offGraphics.drawImage(small[15],30-9*j,205,this); offGraphics.drawImage(small[39],70,205,this); offGraphics.drawString("Taking all coins and advancing",110,217); offGraphics.drawString("to next level, 1000 points",110,232); gameState=12; counter=0; } public void waitIntro3() { offGraphics.setColor(Color.black); offGraphics.fillRect(0,135,20,30); offGraphics.drawImage(small[animF[counter&7]],0,135,this); offGraphics.drawImage(small[16],20,135,this); if (counter>70) gameState=7; } public void removeActor(int i) { int j; for (j=i;j