import java.util.*; import java.awt.*; // fire down //public class object9 implements oo{ public class object9 extends object{ boolean no=false; // Is cannon found in current level? int list[]=new int[1000]; int listnr=0; boolean hit=false; // is player insight? boolean busy=false; // if canon is being fired private int state=1; private int eventnr=0; boolean resetter=false; long oldtime=0; private int ANIMATION=8; private Image imgs[]=new Image[ANIMATION+1]; private int imgloop=0; int hitpass[]={ 1, 3, 13, 70, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 205, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 4, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 4, }; private int event1list=0; int list2nr =0; int event2listnr=0; int event2oldimg =-1; int event2oldpos; int event2list[]=new int[1000]; public object9(){ objnumber=9; methods[0]="hit"; methods[1]="resetevent"; methods[2]="action1"; methods[3]="action2"; methods[4]="action3"; methods[5]="action4"; methods[6]="event"; methods[7]="events1"; methods[8]="events2"; methods[9]="aftermove"; } public void init(Global glbl){ boolean found=false; global=glbl; if(image==null){ image=global.loadImage(global.Server,global.Directory+"9"+global.Extention,global.show); sound=global.loadSound(global.Server, global.Directory+"10.au"); } int nr=-1; listnr=0; nr=0; //System.out.println("Init in Object9!"); while(!found){ nr=global.grid.next(nr==0?0:nr%(global.WIDTH*global.STEPP), nr==0?0:nr/(global.WIDTH*global.STEPP),9); if(nr < 0) found=true; else{ //System.out.println("object 9 FOUND : "+nr); // Add the position to the list list[listnr++]=nr; } nr++; } //System.out.println("Object 9 init ---> add eventlist!"); if(listnr < 1)no=true;else no=false; resetter=false; } public void execute(){ if(method.compareTo("aftermove")==0) aftermove(); if(method.compareTo("hit")==0) hit(); if(method.compareTo("resetevent")==0) resetevent(); if(method.compareTo("event1")==0) event1(); if(method.compareTo("event2")==0) event2(); if(method.compareTo("event") == 0) event(); } // obje9 public void aftermove(){ if(no){ System.out.println("NO in aftermove on 9"); return; // found canon in current level? } int cw=0; // canon width=col int ch=0; // canon height=line int cd=0; // canon hit direction // int x=global.player.getX_for_aftermove(); // int y=global.player.getY_for_aftermove(); int x=global.player.getX(); int y=global.player.getY(); int pw=x==0?0:x; int ph=y==0?0:y; boolean stop=false; //System.out.println(" Aftermve object9 listnr: "+listnr); // if(busy)return; try{ for(int kd=0; kd < listnr && !hit; kd++){ cw=list[kd]==0?0:((list[kd])%(global.WIDTH*global.STEPP)); ch=list[kd]==0?0:((list[kd] )/ (global.WIDTH*global.STEPP)); //System.out.println("object 9 aftermove cw= "+cw+" ch ="+ch+" image on cw,ch: "+global.grid_items[ch][cw]); //System.out.println("object 9 aftermove Player width: "+pw+" list width: "+cw); if(cw == pw){ //System.out.println("width = width Player height: "+ph+" list H: "+ch); stop=false; if(ch < ph){ //System.out.println(" Object 9 Hit from above"); //for(int ij=1; ij < (pw-ch)-1 && !stop && ch+ij < global.HEIGHT; ij++){ for(int ij=global.STEPP; ij <= (ph-ch) && !stop && ch+ij < (global.HEIGHT*global.STEPP)+global.STEPP; ij+=global.STEPP){ //System.out.println("9 Checking : "+(ch+ ij)+" "+cw+" = "+global.grid_items[ch+ij][cw]); //if( ! insight(global.grid_items[ch+ij][cw])) if( ! insight(global.grid.getNr(global.grid_items[ch+ij][cw]))) stop=true; } if(!stop)hit=true; if(hit){ global.freeze=true; global.dontwalk=true; for(int i=global.STEPP; i < ph-ch; i++){ event2list[event2listnr++]=((ch+i)*global.WIDTH*global.STEPP)+pw; //System.out.println("event2list added position: "+event2list[event2listnr-1]); } } } if(hit){ if( sound!=null && global.playsound)sound.play(); global.freeze=true; // Tell the event-routine that we are going to 'hit' state=2; // busy=true; } } } }catch(Exception egeg){ System.out.println(" Exception aftermove in object9!"+egeg); } } public boolean insight(int nr){ boolean retval=false; for(int i=0; i < hitpass.length && !retval; i++){ //System.out.println("pass value: "+hitpass[i]+" ==> check with nr:"+nr); if(hitpass[i]==nr) retval=true; } //System.out.println("insight?: "+retval); return retval; } public void hit(){ } public void event1(){ Date d=new Date(); if((long)(d.getTime()) < oldtime+500)return; oldtime=(long)d.getTime(); // simulate move to check if we have crossed the 'line' (used when picking objects like 70) if(global.STEPP > 1){ int x=global.player.getX(); int y=global.player.getY(); if(x%global.STEPP==0 && y%global.STEPP==0){ aftermove(); } }else aftermove(); } public void event2(){ Image img; int c,h; // Slow down ..? //System.out.println("state 2 (event2 on 9)"); if(eventnr++ > -11){ // You are hit .. so freeze the application! global.freeze=true; if(list2nr++ > event2listnr-2){ global.freeze=false; // global.player.set(0,0); global.setInfo("You are hit by a canon!"); global.doreload=true; // ESCape // redo the level global.resetevent=true; // tell environment to execute resetevent resetter=true; state=1; } if(event2oldimg > -1){ c=event2oldpos%(global.WIDTH*global.STEPP); h=event2oldpos/(global.WIDTH*global.STEPP); global.grid_items[h][c]=event2oldimg; } c=event2list[list2nr]%(global.WIDTH*global.STEPP); h=event2list[list2nr]/(global.WIDTH*global.STEPP); event2oldpos=event2list[list2nr]; //System.out.println("c: "+c+" h="+h); event2oldimg=global.grid_items[h][c]; if(global.grid_items[h][c]==1) global.grid_items[h][c]=999; global.boardrow=h; global.boardcol=c; global.boardwidth=-1; global.boardheight=-1; global.doboard=true; global.aftermoves=true; eventnr=1; } } public void resetevent(){ if(resetter){ System.out.println("Restting object9"); listnr=0; state=1; eventnr=1; hit=false; global.freeze=false; busy=false; resetter=false; } } public void event(){ if(no){ return; // found canon in current level? } // put everything here like a 'run' method switch(state){ case 1: event1(); break; case 2: event2(); break; } // draw image } }