import java.util.*; import java.awt.*; // // Mystery box // // When pushed against object .. object disappears into box // When pushed against background .. object re-appears or you move the box // // public class object169 extends object{ int state=0; boolean debug=false; int inbox=1; int o1=0; // behind int i1=0; // imagebehind int x; int y; public General general; public Sound throwing; // object that cannot be put in magic box int notallow[]={13,152,3,4, 99, 133, 132, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 177, 205, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 }; public boolean allowed(int a){ boolean retval=true; for(int i=0; i < notallow.length && retval; i++) if(notallow[i]==a) retval=false; return retval; } public object169(){ objnumber=169; methods[0]="hit"; methods[1]="resetevent"; methods[2]="event"; } public void init(Global glbl){ global=glbl; if(image == null){ image=global.loadImage(global.Server, global.Directory+"169"+global.Extention, global.show); } throwing=global.loadSound(global.Server, global.Directory+"169.au"); general=new General(global,getNr()); } public void execute(){ if(method.compareTo("event")==0) event(); if(method.compareTo("resetevent")==0) resetevent(); if(method.compareTo("hit")==0){ hit(); return; } } // Hit the crate/wood public void hit(){ global.waitforme=true; global.resetevent=false; o1=general.getBehind(); i1=general.getImageBehind(); System.out.println("o1: "+o1); int x=global.player.getX(); int y=global.player.getY(); if(global.dir == -global.STEPP){ x-=(global.STEPP*2); } // Right if(global.dir == global.STEPP){ x+=(global.STEPP*2); } // down if(global.dir == global.STEPP*global.WIDTH){ y+=(global.STEPP*2); } // up if(global.dir == -global.STEPP*global.WIDTH){ y-=(global.STEPP*2); } if(o1==1){ if(inbox == 1){ state=1; }else{ // there is something in box // pop out! global.grid.setxy(x,y,inbox); inbox=1; global.boardrow=global.boardcol=-1; global.doboard=true; } }else{ if( allowed(o1) ){ inbox=o1; global.grid.setxy(x,y, 1); global.boardrow=global.boardcol=-1; global.doboard=true; } } } // Action 1 -> background behind the crate/wood public void action1(){ state=1; } public void action300(){ action3(); } // Push the crate in the water -> make walkable water public void action3(){ state=40; } // Push the crate/wood in the hole -> Make walkable hole public void action4(){ if(global.playsound) throwing.play(); state=40; } public void event(){ switch(state){ case 1: event1(); break; case 2: event2();break; case 3: break; case 40: event40(); break; case 41: event41(); break; case 43: global.boardrow=-1; global.boardcol=-1; global.doboard=true; state=44; break; case 30: break; case 31: break; // ice case 74:event74();break; } // draw image } // Action methods public void event1(){ if(general != null) state=general.push(state); else System.out.println("General is null"); } public void event2(){ global.freeze=false; global.aftermoves=true; global.resetevent=true; global.waitforme=false; state=3; } public void event40(){ state=general.push(state); // state + 1 is returned -> event41 } // After hole -> Leave empty! public void event41(){ global.freeze=false; state=43; // do nothing global.resetevent=true; // Reset the event global.waitforme=false; // Ready with pushing global.aftermoves=true; // We can execute the aftermoves } public void action74(){ if(general!=null)general.resetice(); state=74; } public void event74(){ if(general!=null) state=general.ice(state); } // Action methods public void action177(){ if(general != null) state=general.throwit(state); } // public void resetevent(){ inbox=1; if(global.object==getNr() && global.perform) if(global.STEPP==1) state=0; else state=1; } }