import java.util.*; import java.awt.*; // // Magnet to the Down // // Attracks object152 on the right // public class object107 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=3; private int eventnr=0; int o1=0; int i1; Image img_4_105; private int event1list=0; int list2nr =0; public object107(){ objnumber=107; 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+"107"+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; // Left push if(global.dir == -global.STEPP){ o=global.grid.getxy(x-global.STEPP,y+global.STEPP); } // Right push if(global.dir == global.STEPP){ o=global.grid.getxy(x+global.STEPP,y+global.STEPP); } // down if(global.dir == -global.STEPP*global.WIDTH){ o=global.grid.getxy(x, y-global.STEPP-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(){ 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),107); 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 y=global.HEIGHT*global.STEPP; y > jy+global.STEPP && !gotit;y-=global.STEPP){ int f=global.grid.getxy(jx,y); if(f==152){ int g=global.grid.getxy(jx, y-global.STEPP); if(jx==px &&y-global.STEPP == py){ }else{ switch(g){ case 1: // background case 177: // fire act the same! // make old position of 152 (iron) empty global.grid.setxy(jx,y,1); //advance one level global.grid.setxy(jx, y-global.STEPP, 152); display(); break; case 3: // water // throw global.grid.setxy(jx, y,1); // splash sound //show display(); break; case 4: // hole // make it walkable global.grid.setxy(jx, y,1); int i1=global.grid.getxy(jx,y-global.STEPP); // int s=((y+1)*global.WIDTH)+(jx-1); // int s=((y+1)*global.WIDTH)+(jx); int s=((y+global.STEPP)*global.WIDTH)+(jx); oo o; try{ o=(oo)global.loader.getObject(i1); }catch(Exception egw){ o=(oo)global.loader.getObject(1); } global.grid.setxy(jx, y-global.STEPP,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; } 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; } // draw image } }