import java.awt.*; import java.applet.*; public class blocky extends Applet implements Runnable { double you[] = new double[3]; double movement[] = new double[2]; boolean started=false,left=false,right=false,up=false,down=false; double theothers[][] = new double[100][6]; long moves=0; boolean playing=true; int fishsize; public void init(){ moves=0; setBackground(Color.blue); } public void start(){ for(int a=0;a<100;a++){theothers[a][3]=1;} Thread t = new Thread(this); t.start(); you[0]=300; you[1]=200; you[2]=20; } public void paint(Graphics g){ g.setColor(Color.green); g.fillRect((int)you[0],(int)you[1],(int)you[2],(int)you[2]/2); g.setColor(Color.black); g.drawRect((int)you[0],(int)you[1],(int)you[2],(int)you[2]/2); for(int a=0;a<100;a++){ if(theothers[a][3]==0){ fishsize=(int)(theothers[a][2]/10); if(fishsize==10){g.setColor(Color.pink);} if(fishsize== 9){g.setColor(Color.magenta);} if(fishsize== 8){g.setColor(Color.red);} if(fishsize== 7){g.setColor(Color.orange);} if(fishsize== 6){g.setColor(Color.yellow);} if(fishsize== 5){g.setColor(Color.white);} if(fishsize== 4){g.setColor(Color.lightGray);} if(fishsize== 3){g.setColor(Color.gray);} if(fishsize== 2 ){g.setColor(Color.darkGray);} if(fishsize== 1){g.setColor(Color.black);} g.fillRect((int)theothers[a][0],(int)theothers[a][1],(int)theothers[a][2],(int)theothers[a][2]/2); g.setColor(Color.black); g.drawRect((int)theothers[a][0],(int)theothers[a][1],(int)theothers[a][2],(int)theothers[a][2]/2); } } g.setColor(Color.black); g.drawString(you[2] + " ",300,60); } public boolean keyDown(Event e, int key) { if (key == Event.LEFT){ left = true; right = false; if(!started)started=true; } if (key == Event.RIGHT){ left = false; right = true; if(!started)started=true; } if (key == Event.UP){ up = true; down = false; if(!started)started=true; } if (key == Event.DOWN){ down = true; up = false; if(!started)started=true; } return true; } public void run() { while(playing) done: { if(started){ moves++; if(moves%35==0){ for(int a=0;a<100;a++){ if(theothers[a][3]==1){ theothers[a][5]=(int)(Math.random()*2); theothers[a][4]=(Math.random()*2)+.5; theothers[a][3]=0; theothers[a][2]=((int)(Math.random()*110)); theothers[a][1]=((int)(Math.random()*(400-((int)(theothers[a][2]/2)))))+1; theothers[a][0]=theothers[a][5]==0 ? 0-theothers[a][2] : 600; break; } } } for(int a=0;a<100;a++){ if(theothers[a][0]>600) theothers[a][3]=1; theothers[a][0] += theothers[a][5]==0 ? theothers[a][4] : -theothers[a][4]; } for(int x=(int)you[0];x<=(int)(you[0]+you[2]);x++){ for(int y=(int)you[1];y<=(int)(you[1]+(you[2]/2));y++){ for(int a=0;a<100;a++){ if(theothers[a][3]==0){ if( x>=theothers[a][0] && x<=(theothers[a][0]+theothers[a][2]) && y>=theothers[a][1] && y<=(theothers[a][1]+(theothers[a][2]/2))){ if(you[2]>theothers[a][2]){ you[2]+=theothers[a][2]/10.0; theothers[a][3]=1; break done;} else playing=false; } } } } } if(!(left ^ right) && movement[0]!=0) movement[0]/=1.1; if(!(up ^ down) && movement[1]!=0) movement[1]/=1.1; if(left ){movement[0]-=2;} if(right){movement[0]+=2;} if(up ){movement[1]-=2;} if(down ){movement[1]+=2;} left=false; right=false; up=false; down=false; if(movement[0]!=0) you[0]+=((Math.abs(movement[0]))/movement[0])*(Math.sqrt(Math.abs(movement[0]))); if(movement[1]!=0) you[1]+=((Math.abs(movement[1]))/movement[1])*(Math.sqrt(Math.abs(movement[1]))); if(you[0]<=0.0){ you[0]=1.0; movement[0]=0.0; } if(you[0]>=600-you[2]){ you[0]=599.0-you[2]; movement[0]=0.0; } if(you[1]<=0.0){ you[1]=1.0; movement[1]=0.0; } if(you[1]>=400.0-you[2]/2){ you[1]=399.0-you[2]/2; movement[1]=0.0; } } repaint(); try{Thread.sleep(50);} catch(InterruptedException e){} } } }