import java.util.*; import java.awt.*; // Monkey that gets you when you are near it // // EXCEPT when it receives a banana(s)= 73 for 5 seconds // public class object72 extends object{ long oldtime=0; private Image images[]=new Image[10]; int list[]=new int[1000]; int listnr=0; private int state=1; boolean no=false; int looper=0; // display part of the monkey turning int ll=0; // ll = number of monkey public object72(){ objnumber=72; methods[0]="hit"; methods[1]="resetevent"; methods[2]="action1"; methods[3]="action2"; methods[4]="action3"; methods[5]="action4"; methods[6]="event"; methods[7]="event1"; methods[8]="event2"; methods[9]="aftermove"; } public void init(Global glbl){ boolean found=false; global=glbl; if(image==null){ image=global.loadImage(global.Server,global.Directory+"72_1"+global.Extention,global.show); sound=global.loadSound(global.Server, global.Directory+"72.au"); } Date d=new Date();oldtime=d.getTime(); for(int ii=1; ii<5; ii++){ images[ii]=global.loadImage(global.Server,global.Directory+"72_"+ii+global.Extention,global.show); } int nr=0; listnr=0; // global.setObjectState(72,"0"); global.popbag(72); while(!found){ // nr=global.grid.next(nr==0?0:nr%(global.WIDTH*global.STEPP), //nr==0?0:nr/(global.WIDTH*global.STEPP),72); nr=global.grid.next(nr==0?0:nr%(global.WIDTH*global.STEPP),nr==0?0:nr/(global.WIDTH*global.STEPP), 72); if(nr < 0) found=true; else{ // Add the position to the list list[listnr++]=nr; } nr++; } System.out.println("Object 72init ---> add eventlist!"+listnr); if(listnr < 1) no=true; // No object 72 found on level else no=false; } public void execute(){ if(method.compareTo("aftermove")==0) aftermove(); if(method.compareTo("hit")==0) hit(); if(method.compareTo("resetevent")==0) resetevent(); if(method.compareTo("event1")==0) event1(); if(method.compareTo("event2")==0) event2(); if(method.compareTo("event") == 0) event(); } public void aftermove(){ int cw=0; // canon width=col int ch=0; // canon height=line int cd=0; // canon hit direction int x=global.player.getX(); int y=global.player.getY(); int pw=x==0?0:x; int ph=y==0?0:y; boolean stop=false; try{ for(int kd=0; kd < listnr ; kd++){ cw=list[kd]==0?0:((list[kd])%(global.WIDTH*global.STEPP)); ch=list[kd]==0?0:((list[kd] )/ (global.WIDTH*global.STEPP)); if((ch == ph && (cw+global.STEPP ==pw || cw-global.STEPP == pw) ) || (cw == pw && ((ch+(global.STEPP)) == ph || ch-(global.STEPP) == ph )) ){ // String banana=global.getObjectState(72); boolean banana=global.inbag(72); if(!banana) state=2; } } }catch(Exception egeg){ System.out.println(" Exception aftermove in object72!"+egeg); } } public void hit(){ } public void event1(){ if(no)return; Date d=new Date(); if(d.getTime() < oldtime+1000)return; oldtime=d.getTime(); if(oldtime % 1000 < 50 && global.playsound)sound.play(); if(looper++ > 4)looper=1; if(images[looper]!=null ){ image=images[looper]; global.boardrow=list[ll]==0?0:list[ll]/(global.WIDTH*global.STEPP); global.boardcol=list[ll]==0?0:list[ll]%(global.WIDTH*global.STEPP); global.boardwidth=-1; global.boardheight=-1; if(ll++ > listnr)ll=0; global.doboard=true; } } public void event2(){ global.freeze=false; global.setInfo("The Monkey gets you!"); global.doreload=true; // ESCape // redo the level global.resetevent=true; // tell environment to execute resetevent state=0; } public void resetevent(){ Date d=new Date();oldtime=d.getTime(); listnr=0; state=1; global.freeze=false; // global.setObjectState(72,"0"); // global.popbag(72); no=true; } public void event(){ // put everything here like a 'run' method switch(state){ case 1: event1(); break; case 2: event2(); break; } // draw image } }