import java.util.*; import java.awt.*; public class object1000 implements GameObject{ long hittime=0; int teller=0; int objectframes=4; // [4]=direction, [16] frames, [3] = playerstates public Image image[][][]=new Image[4][16][3]; public Sound sound; public Global global; public String arg1=new String(""); public String arg2=new String(""); public String method=new String(""); public String retval=new String(""); public String list[]=new String[10]; int state=0; int animationframe=0; int objnumber=1000; int pos=0; boolean debug=false; String methods[]={ "add", "delete", "hit", "event1", "event2", "event", "resetevent", "left", "right", "down", "up", ""}; public void init(Global glbl){ global=glbl; if(debug)System.out.println("init object1000!"); for(int i=0; i < objectframes-1; i++){ for(int s=0; s < 2; s++){ image[0][i][s]=global.loadImage(global.Server, "/users/"+getNr()+"_0_"+i+"_"+s+global.Extention, global.game); image[1][i][s]=global.loadImage(global.Server, "/users/"+getNr()+"_1_"+i+"_"+s+global.Extention, global.game); image[2][i][s]=global.loadImage(global.Server, "/users/"+getNr()+"_2_"+i+"_"+s+global.Extention, global.game); image[3][i][s]=global.loadImage(global.Server, "/users/"+getNr()+"_3_"+i+"_"+s+global.Extention, global.game); } } sound=global.loadSound(global.Server, global.Directory+"1.au"); global.PLAYERFRAMES=objectframes-1; global.playerstate=0; for(int i=0; i<10;i++) list[i]=new String(""); } public Image getImage(int framenr,int dir){ // Use the frame number as well int f=framenr; if(framenr>objectframes-1)f=0; Image img=image[dir][f][global.playerstate]; return img; } public void execute(){ if(method.compareTo("add")==0) add(); if(method.compareTo("hit")==0) hit(); if(method.compareTo("event")==0) event(); if(method.compareTo("event1")==0) event1(); if(method.compareTo("event2")==0) event2(); if(method.compareTo("resetevent")==0) resetevent(); if(method.compareTo("left")==0) left(); if(method.compareTo("right")==0) right(); if(method.compareTo("up")==0) up(); if(method.compareTo("down")==0) down(); } public void setMethod(String s){ method=s; } public String getRetval(){ return retval; } public void setArg(int i, String value){ list[i]=value; } public void add(){ //System.out.println("arg1: "+list[0]+" "+list[1]); retval=arg1+arg2; } public boolean is(String meth){ boolean retval=false; int m=methods.length; for(int i=0; i < m && !retval; i++){ if(methods[i].compareTo(meth) == 0) retval=true; } return retval; } public void hit(){ if(global.playsound) if(sound!=null){ //System.out.println("Sound 1=null oplay!"); sound.play(); } state=1; if(debug)System.out.println(" Hit on object"+getNr()+" [user]"); } public void event2(){ } public void event1(){ } public String toString(){ return "object"+getNr()+""; } public int getNr(){return objnumber;} public void resetevent(){ global.playerstate=0; } public void event(){ // put everything here like a 'run' method switch(state){ case 1: event1(); break; case 2: event2(); break; } // draw image } public void tohit(int nextobj){ try{ global.setProperty("collide", "false"); System.out.println("To Hit(nextobj: "+nextobj+" : Dir="+(global.dir==0?"right":global.dir==1?"up":global.dir==2?"left":global.dir==3?"down":"")); if(global.gameobject[nextobj]!=null){ if(hittime+30 < global.getTime()){ hittime=global.getTime(); global.gameobject[nextobj].setMethod("hit"); global.gameobject[nextobj].setArg(0,""+global.playery); global.gameobject[nextobj].setArg(1,""+global.playerx); global.gameobject[nextobj].execute(); } } }catch(Exception e){ System.out.println( "Error objec"+getNr()+".Hit object: "+nextobj+" e:"+e.toString()); } } public void left(){ global.dir=2; // left direction if(global.preventmove(global.playery, global.playerx, global.dir))return; int nextobj=global.grid.getobject(global.playery, global.playerx-global.MAXFRAMES); if(nextobj == getNr()){ global.oldobject=1; global.playerstate=0; left_1(); }else{ switch(nextobj){ case 1: global.oldobject=1; global.playerstate=0; left_1(); break; default: tohit(nextobj); if(global.pass){ global.playerstate=0; left_1(); } global.pass=false; // do nothing! break; } } } public void right(){ global.dir=0; // right direction if(global.preventmove(global.playery, global.playerx, global.dir))return; int nextobj=global.grid.getobject(global.playery, global.playerx+global.MAXFRAMES); if(nextobj == getNr()){ global.oldobject=1; global.playerstate=0; right_1(); }else{ switch(nextobj){ case 1: global.oldobject=1; global.playerstate=0; right_1();break; default: tohit(nextobj); if(global.pass){ global.playerstate=0; right_1(); } global.pass=false; break; } } } public void up(){ global.dir=1; // up direciton if(global.preventmove(global.playery, global.playerx, global.dir))return; int nextobj=global.grid.getobject(global.playery-global.MAXFRAMES, global.playerx); if(nextobj == getNr()){ global.oldobject=1; global.playerstate=0; up_1(); }else{ switch(nextobj){ case 1: global.oldobject=1; global.playerstate=0; up_1();break; default: tohit(nextobj); if(global.pass){ global.playerstate=0; up_1(); } global.pass=false; break; } } } public void down(){ global.dir=3; // down direction if(global.preventmove(global.playery, global.playerx, global.dir))return; int nextobj=global.grid.getobject(global.playery+global.MAXFRAMES, global.playerx); if(nextobj == getNr()){ global.oldobject=1; global.playerstate=0; down_1(); }else{ switch(nextobj){ case 1: global.oldobject=1; global.playerstate=0; down_1();break; default: tohit(nextobj); if(global.pass){ global.playerstate=0; down_1(); } global.pass=false; break; } } } // // Objects // // *** // 1 = background // *** public void right_1(){ System.out.println("object: "+getNr()+" right_1"); global.grid.setyx(global.playery,global.playerx,global.oldobject); for(int i=0; i objectframes-1)animationframe=0; global.animationstack.add(global.frameticker++,global.playery, global.playerx+i, getNr(),animationframe,i==global.MAXFRAMES?"true":"false",global.dir, global.playery, global.playerx); } } public void left_1(){ global.grid.setyx(global.playery,global.playerx,global.oldobject); for(int i=0; i objectframes-1)animationframe=0; global.animationstack.add(global.frameticker++,global.playery, global.playerx-i, getNr(),animationframe,i==global.MAXFRAMES?"true":"false", global.dir, global.playery, global.playerx); } } public void up_1(){ global.grid.setyx(global.playery,global.playerx,global.oldobject); for(int i=0; i objectframes-1)animationframe=0; global.animationstack.add(global.frameticker++,global.playery-i,global.playerx, getNr(), animationframe ,i==global.MAXFRAMES?"true":"false",global.dir, global.playery, global.playerx); } } public void down_1(){ global.grid.setyx(global.playery,global.playerx,global.oldobject); for(int i=0; i objectframes-1)animationframe=0; global.animationstack.add(global.frameticker++,global.playery+i,global.playerx, getNr(), animationframe ,i==global.MAXFRAMES?"true":"false",global.dir,global.playery, global.playerx); } } }