import java.util.*; import java.awt.*; // // Magnet to the right // // Attracks object152 on the right // public class object105 extends object{ long oldtime=0; int list[]=new int[1000]; int list3[]=new int[1000]; int list3nr=0; int listnr=0; boolean hit=false; boolean isrunning=false; boolean stored=false; private int state=0; private int eventnr=0; boolean changed=false; int o1=0; int i1; Image img_4_105; private int event1list=0; int list2nr =0; public object105(){ objnumber=105; methods[0]="hit"; methods[1]="reset"; methods[2]="event"; methods[3]="event1"; methods[4]="event2"; methods[5]="aftermove"; methods[6]="action1"; } public void init(Global glbl){ boolean found=false; global=glbl; image=global.loadImage(global.Server,global.Directory+"105"+global.Extention,global.show); img_4_105=global.loadImage(global.Server,global.Directory+"4_105"+global.Extention,global.show); sound=global.loadSound(global.Server, global.Directory+"105.au"); state=3; general=new General(global,getNr()); } public void execute(){ if(method.compareTo("aftermove")==0) aftermove(); if(method.compareTo("hit")==0) hit(); if(method.compareTo("reset")==0) reset(); if(method.compareTo("event1")==0) event1(); if(method.compareTo("event") == 0) event(); if(method.compareTo("action1")==0) action1(); } public void event1(){ if(general != null) state=general.push(state); } public void action1(){ /* // Check if there is no 152 object to the right (attached) int x=global.player.getX(); int y=global.player.getY(); int o=0; // Right push if(global.dir == global.STEPP){ o=global.grid.getxy(x+global.STEPP+global.STEPP, y); } // down if(global.dir == global.STEPP*global.WIDTH){ o=global.grid.getxy(x+global.STEPP, y+global.STEPP); } // up if(global.dir == -global.STEPP*global.WIDTH){ o=global.grid.getxy(x+global.STEPP, y-global.STEPP); } if(o!=152) */ state=1; } public void hit(){ global.waitforme=true; if(sound!=null && global.playsound)sound.play(); i1=general.getImageBehind(); o1=general.getBehind(); String l="action"+o1; if(is(l)){ setMethod(l); execute(); } } public void aftermove(){ } public void display(){ if(changed){ global.boardrow=-1; global.boardcol=-1; global.doboard=true; } } public void event3(){ Date d=new Date(); if((long)(d.getTime()) < oldtime+500)return; oldtime=(long)d.getTime(); boolean found=false; int px=global.player.getX(); int py=global.player.getY(); int nr=0; boolean gotit=false; while(!found){ nr=global.grid.next(nr==0?0:nr%(global.WIDTH*global.STEPP), nr==0?0:nr/(global.WIDTH*global.STEPP),105); if(nr < 0) found=true; else{ if(global.playsound)sound.play(); int jy=nr==0?0:(int)Math.floor(nr/(global.WIDTH*global.STEPP)); int jx=nr%(global.WIDTH*global.STEPP); gotit=false; for(int x=global.WIDTH*global.STEPP; x > jx+global.STEPP && !gotit; x-=global.STEPP){ int f=global.grid.getxy(x,jy); if(f==152){ int g=global.grid.getxy(x-global.STEPP, jy); if(x-global.STEPP == px&& jy == py){ }else{ switch(g){ case 1: // background case 177: // fire act the same! // make old position of 152 (iron) empty global.grid.setxy(x, jy,1); changed=true; //advance one level global.grid.setxy((x-global.STEPP), jy, 152); display(); break; case 3: // water // throw global.grid.setxy(x, jy,1); changed=true; // splash sound //show display(); break; case 4: // hole // make it walkable global.grid.setxy(x, jy,1); int i1=global.grid.getxy(x-global.STEPP, jy); changed=true; // int s=((jy+1)*global.WIDTH)+(x-global.STEPP); // int s=((jy+(global.STEPP > 1 ? 1:0)*global.WIDTH)+(x); int s=((jy+global.STEPP)*global.WIDTH)+(x-global.STEPP); oo o; try{ o=(oo)global.loader.getObject(i1); }catch(Exception egw){ o=(oo)global.loader.getObject(1); } global.grid.setxy(x-global.STEPP, jy,1); if(o!=null){ if(o.getImage()!=null){ global.show.changeBackground(img_4_105, o.getImage(), s); } // if image else global.show.changeBackground(img_4_105, s); } display(); break; default:changed=false; break; } gotit=false; } } } } nr++; } } public void reset(){ listnr=0; state=3; stored=false; eventnr=1; hit=false; isrunning=false; } public void event2(){ global.freeze=false; global.resetevent=true; global.waitforme=false; global.aftermoves=true; global.State=global.NOTHING; state=3; } public void resetevent(){ if(global.perform) if(global.STEPP==1) state=3; else state=1; } public void event(){ // put everything here like a 'run' method switch(state){ case 1: event1(); break; case 2:event2();break; case 3: event3(); break; // all the time } // draw image } }