import java.util.*; import java.awt.*; //public class object2 implements oo{ public class object2 extends object{ public Sound splash; public Sound throwing; public Image img_4_2; // when object gets pushed over hole int o1=0; int i1=0; int teller=0; int pos=0; boolean walk=false; int state=0; boolean debug=false; int x; int y; public object2(){ methods[0]="hit"; methods[1]="event"; methods[2]="event1"; methods[3]="action1"; methods[4]="resetevent"; methods[5]="action3"; methods[6]="action4"; methods[7]="action205"; methods[8]="action206"; methods[9]="action207"; methods[10]="action208"; methods[11]="action209"; methods[12]="action210"; methods[13]="action211"; methods[14]="action212"; methods[15]="action213"; methods[16]="action214"; methods[17]="action215"; methods[18]="action216"; methods[19]="action217"; methods[20]="action218"; methods[21]="action74"; //ice methods[22]="action177"; //fire objnumber=2; } public void init(Global glbl){ global=glbl; if(debug)System.out.println("init object2 "); if(image == null){ image=global.loadImage(global.Server, global.Directory+"2"+global.Extention, global.show); img_4_2=global.loadImage(global.Server, "/maze/4_2"+global.Extention,global.show); sound=global.loadSound(global.Server, global.Directory+"2.au"); splash=global.loadSound(global.Server, global.Directory+"3.au"); throwing=global.loadSound(global.Server, global.Directory+"5_4.au"); } // for(int i=0; i<1000;i++) // list[i]=new String(""); general=new General(global,getNr()); } public Image getImage(){return image;} public void execute(){ if(method.compareTo("action1")==0) action1(); if(method.compareTo("action3")==0) action3(); if(method.compareTo("event")==0) event(); if(method.compareTo("resetevent")==0) resetevent(); if(method.compareTo("event1")==0) event1(); if(method.compareTo("action4")==0) action4(); if(method.compareTo("action205")==0) action205(); if(method.compareTo("action206")==0) action206(); if(method.compareTo("action207")==0) action207(); if(method.compareTo("action208")==0) action208(); if(method.compareTo("action209")==0) action209(); if(method.compareTo("action210")==0) action210(); if(method.compareTo("action211")==0) action211(); if(method.compareTo("action212")==0) action212(); if(method.compareTo("action213")==0) action213(); if(method.compareTo("action214")==0) action214(); if(method.compareTo("action215")==0) action215(); if(method.compareTo("action216")==0) action216(); if(method.compareTo("action217")==0) action217(); if(method.compareTo("action218")==0) action218(); if(method.compareTo("action74")==0) // ice action74(); if(method.compareTo("action177")==0) //fire action177(); if(method.compareTo("hit")==0){ hit(); return; } } /* public void setMethod(String s){ method=s; } */ public String getRetval(){ return retval; } /* public void setArg(int i, String value){ list[i]=value; } */ /* public boolean is(String meth){ boolean retval=false; int m=methods.length; for(int i=0; i < m && !retval; i++){ if(methods[i].compareTo(meth) == 0) retval=true; } return retval; } */ public void hit(){ global.waitforme=true; if(sound!=null && global.playsound)sound.play(); i1=general.getImageBehind(); o1=general.getBehind(); String l="action"+o1; if(debug)System.out.println("Action: "+l); if(is(l)){ setMethod(l); execute(); } } public String toString(){ return "object2"; } public void action1(){ if(debug)System.out.println("Action1 ==> move stone!!!"); state=1; } public void action74(){ if(general!=null)general.resetice(); state=74; } public void event74(){ if(general!=null) state=general.ice(state); } // Action methods public void event1(){ if(general != null) state=general.push(state); } public void action3(){ if(global.playsound) splash.play(); global.PLAYERSTATE=1; state=general.throwit(state); global.freeze=false; /*System.out.println("(object2)setting dir to 0!"); global.dir=0; */ global.aftermoves=true; global.State=global.NOTHING; global.resetevent=true; global.waitforme=false; state=33; } public void action3tje(){ int x=0; int y=0; // when stone is pushed into water x=global.player.getX(); y=global.player.getY(); global.grid.setxy(x, y,1); // Left if(global.dir == -global.STEPP){ global.grid.setxy(x-global.STEPP, y,1); global.player.set(x-global.STEPP,y); } // Right if(global.dir == global.STEPP){ global.grid.setxy(x+global.STEPP, y,1); global.player.set(x+global.STEPP,y); } // down if(global.dir == global.STEPP*global.WIDTH){ global.grid.setxy(x, y+global.STEPP,1); global.player.set(x, y+global.STEPP); } // up if(global.dir == -global.STEPP*global.WIDTH){ global.grid.setxy(x, y-global.STEPP,1); global.player.set(x, y-global.STEPP); } global.freeze=false; /* System.out.println("(object2)setting dir to 0!"); global.dir=0; */ global.aftermoves=true; state=33; } public void action4(){ global.PLAYERSTATE=1; if(global.playsound) throwing.play(); state=40; } public void event40(){ state=general.push(state); // state + 1 is returned -> event41 } public void evntje40(){ global.freeze=true; // Stone pushing!! int P=1; int x=0; int y=0; // when stone is pushed into hole // if((teller++ % global.ANIFREEZE) != 1) return; // Last frame? if(pos++ > global.STEPP-2){ pos=0; state=41; global.stap=0; teller=0; } // Move image of player if(global.stap < global.STEPP)global.stap++;else global.stap=0; // hole pushing x=global.player.getX(); y=global.player.getY(); // global.grid.setxy(x,y,1); // Left if(global.dir == -global.STEPP){ global.grid.setxy(x-P, y,1); global.grid.setxy(x-global.STEPP-(P-1), y,1); global.grid.setxy(x-global.STEPP-P, y,2); global.player.set(x-P,y); } // Right if(global.dir == global.STEPP){ global.grid.setxy(x+P, y,1); global.grid.setxy(x+global.STEPP+(P-1), y,1); global.grid.setxy(x+global.STEPP+P, y,2); global.player.set(x+P,y); } // down if(global.dir == global.STEPP*global.WIDTH){ global.grid.setxy(x, y+P,1); global.grid.setxy(x, y+global.STEPP+(P-1),1); global.grid.setxy(x, y+global.STEPP+P,2); global.player.set(x, y+P); } // up if(global.dir == -global.STEPP*global.WIDTH){ global.grid.setxy(x, y-P,1); global.grid.setxy(x, y-global.STEPP-(P-1),1); global.grid.setxy(x, y-global.STEPP-P,2); global.player.set(x, y-P); } global.State=global.PUSH; } public void event30(){ } public void action205(){action3();} public void action206(){action3();} public void action207(){action3();} public void action208(){action3();} public void action209(){action3();} public void action210(){action3();} public void action211(){action3();} public void action212(){action3();} public void action213(){action3();} public void action214(){action3();} public void action215(){action3();} public void action216(){action3();} public void action217(){action3();} public void action218(){action3();} public void event(){ // put everything here like a 'run' method switch(state){ case 1: event1(); break; case 2: event2();break; case 40: event40(); break; case 41: event41(); break; case 30: event30(); break; case 31: event31(); break; case 43: global.State=global.NOTHING; global.freeze=false; /* System.out.println("(object2)setting dir to 0!"); global.dir=0; */ global.PLAYERSTATE=0; state=44; break; // ice case 74:event74();break; } // draw image } public void action177(){ if(global.playsound) splash.play(); global.PLAYERSTATE=1; state=general.throwit(state); global.freeze=false; } public void event2(){ global.freeze=false; global.resetevent=true; global.waitforme=false; /* System.out.println("(object2)setting dir to 0!"); global.dir=0; */ global.aftermoves=true; global.State=global.NOTHING; state=3; } // After hole -> Leave empty! public void event41(){ x=global.player.getX(); y=global.player.getY(); if(global.dir == -global.STEPP){ x-=global.STEPP; } // Right if(global.dir == global.STEPP){ x+=global.STEPP; } // down if(global.dir == global.STEPP*global.WIDTH){ y+=global.STEPP; } // up if(global.dir == -global.STEPP*global.WIDTH){ y-=global.STEPP; } global.grid.setxy(x, y,1); int s=((y+global.STEPP)*global.WIDTH)+x; if(o1==4){ oo o; try{ o=(oo)global.loader.getObject(i1); }catch(Exception egw){ o=(oo)global.loader.getObject(1); } if(o!=null){ if(o.getImage()!=null){ global.show.changeBackground(img_4_2, o.getImage(), s); } // if image else{ global.show.changeBackground(img_4_2, s); } } // global.show.changeBackground(img_4_2, image, s); } /* System.out.println("(object2)setting dir to 0!"); global.dir=0; */ state=43; global.boardrow=-1; global.boardcol=-1; global.doboard=true; global.resetevent=true; global.waitforme=false; global.aftermoves=true; } // After water -> stone in water public void event31(){ x=global.player.getX(); y=global.player.getY(); if(global.dir == -global.STEPP){ global.grid.setxy(x-global.STEPP, y,3); } // Right if(global.dir == global.STEPP){ global.grid.setxy(x+global.STEPP, y,3); } // down if(global.dir == global.STEPP*global.WIDTH){ global.grid.setxy(x, y+global.STEPP,3); } // up if(global.dir == -global.STEPP*global.WIDTH){ global.grid.setxy(x, y-global.STEPP,3); } global.freeze=false; /* System.out.println("(object2)setting dir to 0!"); global.dir=0; */ global.PLAYERSTATE=0; global.aftermoves=true; global.State=global.NOTHING; state=33; } // public void resetevent(){ if(global.perform) if(global.STEPP==1) state=0; else state=1; //System.out.println( "RESETEVENT (object2) state in object2: "+state); } public int getNr(){return objnumber;} }