import java.util.*; import java.awt.*; //public class object10 implements oo{ public class object10 extends object{ long oldtime=0; private Image images[]=new Image[10]; int list[]=new int[1000]; int listnr=0; int imager=0; int IMAGER=3; boolean no=false; int ll=0; int looper=0; boolean hit=false; // is player insight? private int state=1; private int eventnr=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 object10(){ objnumber=10; 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+"10"+global.Extention,global.show); sound=global.loadSound(global.Server, global.Directory+"10.au"); } Date d=new Date();oldtime=d.getTime(); // for(int ii=1; ii<9; ii++){ for(int ii=1; ii<5; ii++){ images[ii]=global.loadImage(global.Server,global.Directory+"10_"+ii+global.Extention,global.show); } int nr=-1; listnr=0; nr=0; //System.out.println("Init in Object10!"); while(!found){ nr=global.grid.next(nr==0?0:nr%(global.WIDTH*global.STEPP), nr==0?0:nr/(global.WIDTH*global.STEPP),10); if(nr < 0) found=true; else{ //System.out.println("object FOUND : "+nr); // Add the position to the list list[listnr++]=nr; } nr++; } //System.out.println("Object 10init ---> add eventlist!"); if(listnr < 1) no=true; // No object 10 found on level else no=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(); } public void aftermove(){ int cw=0; // canon width=col int ch=0; // canon height=line int cd=0; // canon hit direction 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 object10 listnr: "+listnr); 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 10 aftermove cw= "+cw+" ch ="+ch+" image on cw,ch: "+global.grid_items[ch][cw]); //System.out.println("object 10 aftermove Player width: "+pw+" list width: "+cw); if(ch == ph){ //System.out.println("height=height Player width: "+pw+" list H: "+cw); stop=false; if(cw > pw){ //System.out.println(" Object 10 Hit from RIGHT"); //for(int ij=1; ij < (pw-ch)-1 && !stop && ch+ij < global.HEIGHT; ij++){ for(int ij=global.STEPP; ij <= (cw-pw) && !stop && cw-ij > 0; ij+=global.STEPP){ //System.out.println("10 Checking RIGHT : "+(ch+ ij)+" "+cw+" = "+global.grid_items[ch+ij][cw]); //if( ! insight(global.grid_items[ph][cw-ij])) if( ! insight(global.grid.getxy(cw-ij,ph))) stop=true; } if(!stop)hit=true; if(hit){ global.freeze=true; global.dontwalk=true; for(int i=global.STEPP; i < cw-pw; i++){ event2list[event2listnr++]=((ph)*global.WIDTH*global.STEPP)+(cw-i); //System.out.println("event2list added position: "+event2list[event2listnr-1]); } } }else{ //System.out.println(" Object 10 Hit from LEFT"); //for(int ij=1; ij < (pw-ch)-1 && !stop && ch+ij < global.HEIGHT; ij++){ for(int ij=global.STEPP; ij <= (pw-cw) && !stop && cw+ij < (global.WIDTH*global.STEPP)+global.STEPP; ij+=global.STEPP){ //System.out.println("Object 6 checking: "+ch+", "+(cw+ij)+" = "+global.grid_items[ch][cw+ij]); //if( ! insight(global.grid_items[ch][cw+ij])){ if( ! insight(global.grid.getxy(cw+ij,ch))){ stop=true; //System.out.println("Object obstructs LEFTcanon!"); } } if(!stop)hit=true; if(hit){ global.freeze=true; global.dontwalk=true; for(int i=global.STEPP; i < pw-cw; i++){ event2list[event2listnr++]=((ph)*global.WIDTH*global.STEPP)+(cw+i); //System.out.println("event2list added position: "+event2list[event2listnr-1]); } } } } else{ if(cw == pw){ //System.out.println("width = width Player height: "+ph+" list H: "+ch); stop=false; if(ph < ch){ //System.out.println(" Object 10 Hit from BELOW"); //for(int ij=1; ij < (pw-ch)-1 && !stop && ch+ij < global.HEIGHT; ij++){ for(int ij=global.STEPP; ij <= (ch-ph) && !stop && ch-ij > 0; ij+=global.STEPP){ //System.out.println("8 Checking : "+(ch+ ij)+" "+cw+" = "+global.grid_items[ch+ij][cw]); //if( ! insight(global.grid_items[ch-ij][cw])) if( ! insight(global.grid.getxy(cw,ch-ij))) stop=true; } if(!stop)hit=true; if(hit){ global.freeze=true; global.dontwalk=true; for(int i=global.STEPP; i < ch-ph; i++){ event2list[event2listnr++]=((ch-i)*global.WIDTH*global.STEPP)+pw; //System.out.println("vent2list added position: "+event2list[event2listnr-1]); } } }else{ //System.out.println(" Object 10 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(" Checking : "+(ch+ ij)+" "+cw+" = "+global.grid_items[ch+ij][cw]); //if( ! insight(global.grid_items[ch+ij][cw])) if( ! insight(global.grid.getxy(cw,ch+ij))) 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("vent2list added position: "+event2list[event2listnr-1]); } } } } } if(hit){ global.freeze=true; //System.out.println("OBJECT 10 HIT !!"); if(sound!=null && global.playsound)sound.play(); // Tell the event-routine that we are going to 'hit' state=2; } } }catch(Exception egeg){ System.out.println(" Exception aftermove in object10!"+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(){ if(no)return; Date d=new Date(); // if(d.getTime() < oldtime+500 && global.doboard)return; if(d.getTime() < oldtime+500)return; //System.out.println("time: "+d.getTime()); oldtime=d.getTime(); if(looper++ > 4)looper=1; if(images[looper]!=null ){ //System.out.println("show time: "+d.getTime()); image=images[looper]; // if(global.boardrow != -1){ global.boardrow=list[ll]==0?0:list[ll]/(global.WIDTH*global.STEPP); global.boardcol=list[ll]==0?0:list[ll]%(global.WIDTH*global.STEPP); global.boardwidth=-1; global.boardheight=-1; // } if(ll++ > listnr)ll=0; global.doboard=true; // global.dorefreshpos=true; } if(global.STEPP > 1){ int x=global.player.getX(); int y=global.player.getY(); if(x%global.STEPP == 0 && y%global.STEPP==0) aftermove(); } } public void event2(){ Image img; int c,h; // Slow down ..? 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 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; // if(global.boardrow != -1){ global.boardrow=h; global.boardcol=c; global.boardwidth=-1; global.boardheight=-1; // } global.doboard=true; eventnr=1; } } public void resetevent(){ //System.out.println("Restting object10"); Date d=new Date();oldtime=d.getTime(); listnr=0; state=1; eventnr=1; hit=false; global.freeze=false; no=true; } public void event(){ // put everything here like a 'run' method switch(state){ case 1: event1(); break; case 2: event2(); break; } // draw image } }