import java.util.*; import java.awt.*; // // Train going right public class object156 extends object{ long oldtime=0l; boolean display=false; private int state=1; int nr; public object156(){ objnumber=156; methods[0]="hit"; methods[1]="reset"; methods[2]="event1"; methods[3]="event2"; methods[4]="aftermove"; methods[5]="event"; } public void init(Global glbl){ boolean found=false; global=glbl; image=global.loadImage(global.Server,global.Directory+"156"+global.Extention,global.show); int nr=-1; nr=0; nr=global.grid.next(0,0 ,156); global.storedobject155=0; } 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("event2")==0) event2(); if(method.compareTo("event") == 0) event(); } public void aftermove(){ } public void hit(){ } public void event1(){ Date d=new Date(); if((long)(d.getTime()) < oldtime+200)return; oldtime=(long)d.getTime(); int py=(global.player.get())/(global.WIDTH*global.STEPP); int px=(global.player.get())%(global.WIDTH*global.STEPP); int p=(py*(global.WIDTH*global.STEPP))+px; nr=global.grid.next(nr<1?0:nr%(global.WIDTH*global.STEPP), nr<1?0:nr/(global.WIDTH*global.STEPP),156); int nry=nr>0?nr/(global.WIDTH*global.STEPP):0; if(nry > 0)nry=nry/global.STEPP; int nrx=nr%(global.WIDTH*global.STEPP); if(nr>-1){ // look on the right int o1=global.grid.get(nr-global.STEPP); // is there track? if(o1 == 154 ){ global.grid.set(nr, 154); global.grid.set(nr-global.STEPP, 156); nr-=global.STEPP; display=true; } // the end of track .. there is NO object if(o1 == 1){ // if(p == nr-global.STEPP-global.STEPP && global.storedobject155==0){ if(px == (nrx-global.STEPP) && py==nry && global.storedobject155==0){ global.PLAYERSTATE=global.PLAYERNOTHING; global.storedobject155=10000; global.freeze=true; }else{ // Check if we have object if(global.storedobject155!=0){ if(global.storedobject155 == 10000){ global.player.set(nr-global.STEPP); global.PLAYERSTATE=global.WALKING; global.storedobject155=0; global.freeze=false; }else{ // we have object // but is there no player around" // if( p != nr-global.STEPP-global.STEPP){ if( px == (nrx-global.STEPP) && py == nry ){ }else{ global.grid.set(nr-global.STEPP, global.storedobject155); global.storedobject155=0; } } } } global.grid.set(nr,154); // Advanced 155 one further since otherwise 155 thinks it is a the end of the track and takes away object again! global.grid.set(nr+global.STEPP,155); display=true; } // the end of track .. is there object if(o1 > 1 && o1 != 154){ if(global.storedobject155==0){ // We pick up object global.storedobject155=o1; global.grid.set(nr-global.STEPP,1); global.grid.set(nr,155); display=true; }else{ // we can't put the object // so turn around global.grid.set(nr,155); display=true; } } // the end of track .. is there empty space and do we contain object // the end of track .. is there player? if(display){ // if(global.boardrow != -1){ global.boardrow=nr==0?0:nr/(global.WIDTH*global.STEPP); // Display the full length so start at the correct position! global.boardcol=(nr+global.STEPP)==0?0:(nr+global.STEPP)%(global.WIDTH*global.STEPP); // increasing width is no good since it is hitting side anyway! global.boardwidth=global.PARTDRAW_WIDTH; global.boardheight=global.PARTDRAW_HEIGHT; // } global.doboard=true; display=false; } } } public void event2(){ } public void reset(){ state=1; } public void resetevent(){ if(global.object==156 && global.perform) state=1; } public void event(){ // put everything here like a 'run' method //System.out.println("state: "+state); switch(state){ case 1: event1(); break; case 2: event2(); break; } // draw image } }