// Iceblox // By Karl Hörnell, April 8 1996 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=390,playY=330,mainX=390,mainY=348,smalls=48,blockX=13,blockY=11; 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[]={35,33,31,29,27,25}; 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,-15,15},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; return false; } public boolean keyUp(java.awt.Event e,int key) { dir=0; return false; } public void prepareField() { int i,j,p,q; 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),125,12); offGraphics.drawString("SPARE LIVES:",220,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(300,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",175,100); offGraphics.drawString("You scored "+score,160,130); offGraphics.drawImage(small[2],190,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",145,97); offGraphics.drawImage(small[2],140,110,this); offGraphics.drawString("Pixel Pete, the penguin",180,130); offGraphics.drawImage(small[34],120,150,this); offGraphics.drawImage(small[32],140,150,this); offGraphics.drawString("Evil flames",180,170); offGraphics.drawImage(small[16],140,190,this); offGraphics.drawString("Ice cube",180,210); offGraphics.drawImage(small[14],140,230,this); offGraphics.drawString("Solid rock",180,250); offGraphics.drawImage(small[24],140,270,this); offGraphics.drawString("Frozen gold coin",180,290); offGraphics.drawString("Press SPACE to start",138,330); counter=0; gameState=8; } public void waitIntro1() { offGraphics.setColor(Color.black); offGraphics.fillRect(120,150,50,30); offGraphics.drawImage(small[animF[(counter+2)&7]],120,150,this); offGraphics.drawImage(small[animF[counter&7]],140,150,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",165,97); offGraphics.drawImage(small[2],140,110,this); offGraphics.drawString("Move up, down, left and right",180,122); offGraphics.drawString("with the K, M, A and D keys",180,137); offGraphics.drawImage(small[10],70,150,this); offGraphics.drawImage(small[16],140,150,this); offGraphics.drawString("Walk against ice cubes",180,162); offGraphics.drawString("to move them out of the way",180,177); offGraphics.drawLine(110,160,136,160); offGraphics.drawLine(116,169,136,169); offGraphics.drawImage(small[10],80,190,this); offGraphics.drawImage(small[18],110,190,this); offGraphics.drawImage(small[16],140,190,this); offGraphics.drawString("Walk against blocked",180,202); offGraphics.drawString("ice cubes to crack them",180,217); offGraphics.drawImage(small[28],110,230,this); offGraphics.drawImage(small[9],140,230,this); offGraphics.drawString("Free the gold coins by",180,242); offGraphics.drawString("crushing the ice around them",180,257); offGraphics.drawImage(small[9],80,270,this); offGraphics.drawImage(small[32],140,270,this); offGraphics.drawLine(110,280,126,280); offGraphics.drawLine(110,289,130,289); offGraphics.drawString("And watch out",180,282); offGraphics.drawString("for the flames",180,297); gameState=10; counter=0; } public void waitIntro2() { offGraphics.setColor(Color.black); offGraphics.drawImage(small[1+(counter % 12)],140,110,this); offGraphics.fillRect(140,270,30,30); offGraphics.drawImage(small[animF[counter&7]],140,270,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",180,97); offGraphics.drawImage(small[10],110,110,this); offGraphics.drawImage(small[18],140,110,this); offGraphics.drawString("Breaking ice,",180,122); offGraphics.drawString("5 points",180,137); offGraphics.drawImage(small[33],60,150,this); offGraphics.drawImage(small[16],80,150,this); offGraphics.drawImage(small[9],140,150,this); offGraphics.drawLine(112,160,126,160); offGraphics.drawLine(112,169,130,169); offGraphics.drawString("Putting out flame",180,162); offGraphics.drawString("with ice, 50 points",180,177); offGraphics.drawImage(small[10],110,190,this); offGraphics.drawImage(small[27],140,190,this); offGraphics.drawString("Freeing coin,",180,202); offGraphics.drawString("100 points",180,217); for (j=0;j<5;j++) offGraphics.drawImage(small[15],100-9*j,230,this); offGraphics.drawImage(small[39],140,230,this); offGraphics.drawString("Taking all coins and advancing",180,242); offGraphics.drawString("to next level, 1000 points",180,257); gameState=12; counter=0; } public void waitIntro3() { offGraphics.setColor(Color.black); offGraphics.fillRect(60,150,20,30); offGraphics.drawImage(small[animF[counter&7]],60,150,this); offGraphics.drawImage(small[16],80,150,this); if (counter>70) gameState=7; } public void removeActor(int i) { int j; for (j=i;j