// // // // // Show // // // // Display the stuff // // GUI of the Game // // import java.awt.*; import java.awt.image.*; import java.net.*; import java.io.*; import java.util.*; import java.awt.event.*; // // // public class Show extends Panel implements Runnable, KeyListener, MouseListener, MouseMotionListener, ActionListener, FocusListener{ // // // int MAXHEIGHT=(int)(Toolkit.getDefaultToolkit().getScreenSize().height); int MAXWIDTH=(int)(Toolkit.getDefaultToolkit().getScreenSize().width); boolean lastmenustate=true; // What was the last menu state? long mousetime=0l; long eventtime=0l; long starttime=0l; int drawer=1; // Used to determine if we need to double buffer -> remove flickering on Linux/Sol4intel int framecounter=0; int oldframecounter=0; // Frames Per Second show public int storedcounter=0; private int levelintro=0; // Do we need to show help info? long keytime=0; int resetter=0; String oldusers=" "; int oldstap=02352352; int oldsec=0235235; Image xi; // used to getImage only once = performance Image adi=createImage(10,10); // // Image fontimage; myFont font; myFont fontfieldlist; public String OBJECTSTATE; object0 playerobject; object1 backgroundobject; // Timer timer; long drawtime=System.currentTimeMillis(); long olddrawtime=drawtime-10; long playbacktime=System.currentTimeMillis(); long oldplaybacktime=playbacktime; long runningtime=0l; FIFO keystack=new FIFO(); int oldx=-1; int oldy=-1; // Did we move a particular side? int testx=0; int testy=0; int oldtestx=0; // Used to RESET the position int oldtesty=0; int testdirx=0; int testdiry=0; int testk1=0; int RESETTESTTIME=3000; int SPEED=11; // HighResTimer timer; long frametime=0; long oldtime=-1000; long FRAMERATE=10; String backupkeys; Image backupbackground; int backup[][]; int backupbasket[]=new int[10]; int backupplayerx=-1; int backupplayery=-1; int backuplevel=0; Image undobackground; int undo[][]; int undobasket[]=new int[10]; int undoplayerx=-1; int undoplayery=-1; int undolevel=-1; int undostep=0; long undotime=0; long backuptime=0; int arrow=0; int k1=0; // keyboard entry long tijd=0 ; // check if we launch event int keycounter=0; boolean debug=false; boolean already=false; // used to identified if we are already walking/pushing ? boolean loading=true; // Are we in load-screen? animation during load boolean looping=false; // Are we in mainloop? boolean first=false; // first used in events .. int STARTX=0; // global coordinates on screen int STARTY=0; int SIZE=40; // default size will change with use of MAXHEIGHT // Maybe in the future we will use dynamic screens int WSIZE=40; // Width and Height of objects are different int HSIZE=80; int EVENTLOOP=0; // How many times we loop in run-loop before we launch events? //int EVENTLOOP=3; // How many times we loop in run-loop before we launch events? Date date=new Date(); // used for unique URL connections (otherwise it may be cached!) Date datum; long starttijd; long stoptijd; boolean refreshed=true; // Display status of network to player. Refreshed = false means that screen is going to be drawn Global global; // In Between Class -> Communication class begin applet; // Applet which we use the canvas from Keyboard keyboard; boolean isKey=false; Image boximage; // Image to backup from rectangular draw in multiplayboard int boxx=-1; int boxy=-1; // Graphics variables (double buffered) Image offscreen=null; Image offscreenboard=null; Graphics graphics; Graphics graphicsboard; int sidemenu_x=700; int sidemenu_y=500; int sidemenu_w=200; TextField hidden; // used to catch keyboard entries from! Image border; Image loadball; Image keysimage; // display the use of keys Image keysimage2; // display the use of keys Image mouseimage; // Display mouse action for multiplay int anistep=1; long anitime=0; // Time to display the animation Image animationimage[]=new Image[15]; // animated Image targetimage; Image targetimage2; // load/.getImage()s Image intros[]=new Image[12]; // separate gifs int introcount=0; int introloop=0; int INTROLOOP=3; Image intro; // animaged gif Image imgscores; Image imgshow; Image imgshow_2; Image imghintscores; Image imgrightsmall; Image imgleftsmall; Image imgupsmall; Image imgdownsmall; Image imgright; Image imghintright; Image imgleft; Image imghintleft; Image imgup; Image imghintup; Image imgdown; Image imghintdown; Image imgtest; Image imghinttest; Image imgreset; Image imghintreset; Image imgblank; Image imghintblank; Image imgnormal; Image imghintnormal; Image imglevels; Image imghintlevels; // Image imgfast; Image imgfastest; Image imghintfast; Image imghintfastest; Image imgteamplay; Image imghintteamplay; Image imgsingleplay; Image imghintsingleplay; Image imgplaysound; Image imghintplaysound; Image imgnoplaysound; Image imghintnoplaysound; Image imgundo; Image imghintundo; Image imgescape; Image imghintescape; Image imgbackup; Image imghintbackup; Image imgrestore; Image imghintrestore; //Image load; Image load[]=new Image[14]; int loadchange=0; // Images of objects Image image[]=new Image[2]; // Used to show the playerimages // user images Image user_front[][]=new Image[15][6]; Image user_back[][]=new Image[15][6]; Image user_left[][]=new Image[15][6]; Image user_right[][]=new Image[15][6]; int animationstep=-1; // Steps in animation int stepper=0; // inbetween animation int stepx; int stepy; int STEP=6; int step=Math.round(((SIZE*1)/(STEP+1))); // move speed Thread looper; // animation loops and main loop! Thread loader; // loads images and objects levels etc.. Network network; // Reads writestack and inserts into readstack int actmenu=-12; Menu menu[]=new Menu[12]; boolean loaded=false; // are we loaded? // Keycodes --> Change when user wants AWDS - keys .. Implemented later! int oldplayerx=-1; // old player position .. check if move has been done ! int oldplayery=-1; // Text used in game .. implement multi-langual later Image text[]=new Image[100]; // // ----- MENU // TextField chattext; // java.awt.List chat; myListBox chat; // java.awt.List info; myListBox info; // java.awt.List fieldlist; Image fieldlistfont; myListBox fieldlist; java.awt.Label Level; ImageButton playsound; ImageButton allscores; ImageButton showit; ImageButton right; ImageButton left; ImageButton up; ImageButton down; ImageButton blank; ImageButton test; ImageButton reset; ImageButton slow; ImageButton slowest; ImageButton normal; ImageButton fast; ImageButton levels; ImageButton fastest; ImageButton teamplay; ImageButton singleplay; ImageButton undobutton; ImageButton escapebutton; ImageButton backupbutton; ImageButton restore; // Team Play ImageButton multibutton; Image multiimage; // // Colors // Color backgroundcolor=new Color(0,60,0); Color menucolor=new Color(0,60,0); Color emailforeground=Color.black; Color passwordforeground=Color.black; Color createlabelcolor=Color.white; Color chattextforegroundcolor=new Color(0,255,0); Color chattextbackgroundcolor=new Color(0,60,0); Color chatforegroundcolor=new Color(0,200,0); Color chatbackgroundcolor=new Color(0,60,0); Color infoforegroundcolor=new Color(0,200,0); Color infobackgroundcolor=new Color(0,0,0); Color fieldlistforegroundcolor=new Color(0,200,0); Color fieldlistbackgroundcolor=new Color(0,60,0); // // CONSTRUCTOR // Show(begin appletje){ setVisible(false); applet=appletje; setLayout(null); // No layout manager so we can freely move applet.thread.first=true; // Data Store global=new Global(this); playerobject=new object0(); playerobject.init(global); backgroundobject=new object1(); backgroundobject.init(global); global.isturn=false; global.standalone=false; //global.isnetwork=false; // are we in teamplay? global.isnetwork=true; // are we in teamplay? /* global.UP=UP; global.DOWN=DOWN; global.RIGHT=RIGHT; global.LEFT=LEFT; */ /* Dimension dimension=null; if(offscreen == null || graphicsboard == null){ if(applet == null){ // This works when you have an applet wi if(offscreen == null || graphics == null){ dimension=getSize(); offscreen=createImage(dimension.width,dimension.height); graphics=offscreen.getGraphics(); offscreenboard=createImage(dimension.width,dimension.height); graphicsboard=offscreenboard.getGraphics(); } // offscreen != null }else{ // applet != null dimension=getSize(); offscreen=applet.buffer; graphics=offscreen.getGraphics(); offscreenboard=createImage(dimension.width,dimension.height); graphicsboard=offscreenboard.getGraphics(); } // applet ! = null } // offscreen */ offscreen=applet.createImage(800,600); graphics=offscreen.getGraphics(); offscreenboard=applet.createImage(800,600); if(offscreenboard!=null) graphicsboard=offscreenboard.getGraphics(); // Focus-field used for keyboard access hidden=new TextField(); hidden.addFocusListener(this); hidden.addKeyListener(this); hidden.setBounds(0,0,1,1); // Place it outside drawing so there is no little dot ;-) // -1,-1,-1,-1 // Does not work on 1.1 (netscape 4.79) on Solaris // so we end up using 0,0,1,1 hidden.requestFocus(); add(hidden); // Current directory (both server and standalone) global.Server=applet.getCodeBase().toString(); if(global.Server.indexOf("http") > -1) global.standalone=false; else global.standalone=true; global.javaversion=System.getProperty("java.version") ; global.osname=System.getProperty("file.separator"); //System.out.println("JAVA VERSION : "+global.javaversion); //System.out.println("OS NAME: "+global.osname); //System.out.println("Global.Server value: "+global.Server+" --- is standalone(http) : "+global.standalone); if(global.osname.indexOf("/") > 0 || global.osname.indexOf("|") > -0 || global.osname.equals("/")){ // System.out.println("Unix / MAC"); SPEED=5; global.CHATSIZE=(int)(12); global.TEXTSIZE=12; global.nonwindows=true; global.CHATLINESIZE=3*global.TEXTSIZE; }else{ global.nonwindows=false; SPEED=11; global.CHATSIZE=9; global.TEXTSIZE=12; global.CHATLINESIZE=2*global.TEXTSIZE; } global.chatfont=new Font("Terminal", Font.BOLD, global.CHATSIZE); global.textfont=new Font("Terminal", Font.BOLD, global.TEXTSIZE); backup=new int[global.HEIGHT*10][global.WIDTH*10]; backupbackground=createImage(1,1); undo=new int[global.HEIGHT*10][global.WIDTH*10]; undobackground=createImage(1,1); // fontimage=global.loadImage(global.Server, "images/font3.gif", this); fontimage=global.loadImage(global.Server, "images/font.gif", this); fieldlistfont=global.loadImage(global.Server, "images/fieldlistfont.gif", this); // font=new myFont(fontimage, 16, this); font=new myFont(fontimage, 6, this); // fontfieldlist=new myFont(fieldlistfont,16,this); fontfieldlist=new myFont(fieldlistfont,15,this); // Level is miscalculated if(global.standalone ){ global.level--; } // Set game state to LOAD --- game states are essential !!! global.State=global.LOAD; // Use mouselistener to get focus on hidden field so we can catch keyboard addMouseListener(this); addMouseMotionListener(this); // global the Threads .. use the global function // since this will ensure that it happens in an 1.1 applet global(); } // // Threads // public void global(){ // global threads <--- HERE AND NOT IN init() !!! if(looper == null){ looper = new Thread(this); looper.start(); looping=true; } loadImages(); // Get the images adi=imgrightsmall; arrow=1; // default right arrow if(global.standalone || global.parametered){ global.all=4; // global.State=global.MENU_OK; global.State=global.MENU7; } else{ global.State=global.MENU1; } /* timer = new HighResTimer(); timer.setDelay(SPEED); timer.setAutoCorrection(true, 10); timer.startTimer(); */ // timer=new Timer(); } // Default stop thread public void stop(){ if(looper != null){ looping=false; looper=null; } if(loader != null){ loading=false; loader=null; } } // Actions public void drawboard(){ board(0,0,global.WIDTH,global.HEIGHT); // draw the board if(chattext!=null && global.nonwindows) chattext.requestFocus(); hidden.requestFocus(); if(fieldlist!=null){ //System.out.println("drawboard . fieldlist.repaint"); fieldlist.repaint(); } global.State=global.RUNNING; } public void running(){ global.slider=0; int x=global.player.getX(); int y=global.player.getY(); if(global.standalone)hidden.requestFocus(); if(fieldlist!=null){ //System.out.println("runnin g fieldlist.repaint"); fieldlist.repaint(); } if(graphics != null){ graphics.setColor(backgroundcolor); graphics.fillRect(0,0,global.WIDTH*SIZE,global.HEIGHT*SIZE); //System.out.println("in running! Drawtime"); //System.out.println(drawtime-olddrawtime ); if(offscreenboard != null ) graphics.drawImage(offscreenboard, STARTX,STARTY, this); } global.State=global.NOTHING; } public void changing(){ menu(false); global.mpclear(); keystack.clear(); Next(); global.State=global.RUN; global.doreload=true; if(chattext!=null && global.nonwindows) chattext.requestFocus(); hidden.requestFocus(); if(fieldlist!=null) fieldlist.repaint(); } public void dorefreshpos(){ if(global.doreload)return; if(global.boardrow > -1 && global.boardcol > -1){ refreshpos(global.boardrow, global.boardcol); } global.boardrow=-1; global.boardcol=-1; global.boardwidth=-1; global.boardheight=-1; global.doboard=false; global.dorefreshpos=false; } public void doboard(){ if(global.doreload || global.State == global.DONOTHING)return; //System.out.println("Between levels .. : "+global.level+" ."); if(global.boardrow > -1 && global.boardcol > -1){ global.boardrow/=global.STEPP; global.boardcol/=global.STEPP; if(global.boardwidth==-1 || global.boardheight==-1){ board(global.boardrow, global.boardcol,global.PARTDRAW_WIDTH,global.PARTDRAW_HEIGHT ); }else{ board(global.boardrow, global.boardcol,global.boardwidth,global.boardheight); } } else{ board(0,0, global.WIDTH, global.HEIGHT); } // reset board variables global.boardrow=-1; global.boardcol=-1; global.boardwidth=-1; global.boardheight=-1; // backup(); global.doboard=false; } // // RUN // // This is where all the logic is ;-) public void run(){ boolean done=false; int menuloop=0; int x=global.player.getX(); int y=global.player.getY(); long thetime; int tijd=0 ; // check if we launch event int pos, img, room; // little boards Thread.currentThread().setPriority(Thread.MAX_PRIORITY); boolean justdoit=false; boolean justok=false; boolean notshown=true; long startTime = System.currentTimeMillis(); // Another trick to find out if we are looping // MAIN // ROUTINE // ----------------------------------------------------- while(Thread.currentThread() == looper ){ Date d=new Date(); x=global.player.getX(); y=global.player.getY(); //if(debug)System.out.println("Game state: "+global.State); if(global.State == global.MENU_WAIT_OK){ Date d3=new Date(); if(starttime < 1)starttime=d3.getTime(); //System.out.println("Starttime: "+d3.getTime()); if(starttime+100 < d3.getTime()){ System.out.println("MENU_OK change!"); global.State=global.MENU_OK; } } if(global.State == global.MENU_OK){ //System.out.println("MENU_OK FOUND IN global.STATE (show)"); global.doreload=false; setVisible(false); try{ menu(false); }catch(Exception ef){ } applet.repaint(); // global stacker! // Reads from Stack // Acts on moves // Moves are seperated so that you can // display in paint routine // global isnetwork! // WE CAN ONLY DO ONE SETSPEED AT A TIME if(applet.runningspeed < 6){ SPEED=30; } // --> OLD info runningspeed .. //System.out.println(" SPEED: "+applet.runningspeed+" calc: "+SPEED); if(applet.drawtime < 30) SPEED=30; SPEED=50-applet.drawtime; if(debug)System.out.println(" SPEED DRAWTIME: "+applet.drawtime+" calc: "+SPEED+" Nice walk? "+global.nicewalk); System.out.println("global.extra: "+ global.extra); if(global.extra.length() > 0){ String soundy=""; if(global.extra.length() > 1) soundy=global.extra.substring(0,1); //System.out.println("Sound string: "+soundy); if(soundy.indexOf("0")> -1){ // System.out.println("SOUND is off!"); global.playsound=false; }else{ // System.out.println("SOUND is ON"); global.playsound=true; } String speedy=""; try{ if(global.extra!=null) if(global.extra.length() > 3); speedy=global.extra.substring(1,2); }catch(Exception e){} //System.out.println("Speed string: "+speedy); if(speedy.indexOf("5") > -1){ global.nicewalk=true; } if(speedy.indexOf("1") > -1){ global.nicewalk=false; } } if(playsound!=null){ if(global.playsound){ playsound.setImage(imgnoplaysound); playsound.setHintImage(imghintnoplaysound); } else{ playsound.setImage(imgplaysound); playsound.setHintImage(imghintplaysound); } } //System.out.println("Nicewalk: "+global.nicewalk); // Changed after comments on javagaming.org about lack of animation // if(global.nicewalk){ // //setSpeed(8,5,SPEED); // setSpeed(5,8,SPEED); // }else{ // setSpeed(1,40,SPEED); // // } setSpeed(5,8,SPEED); // // WE DON'T DO CHAT BECAUSE IT IS GLUMSY SHOWN AND NOT NEEDED // Maybe turn on when we have good multiplayer // // /* if(network == null && !global.standalone){ try{ //System.out.println( "L A U N C H N E T W R K"); network=new Network(global); network.start(); global.isnetwork=true; }catch(Exception ega){ //System.out.println("network init exc: "+ega.toString()); } }else { global.turn=1; global.isturn=true; } try{ if(chattext!=null && global.nonwindows) chattext.requestFocus(); hidden.requestFocus(); if(fieldlist!=null){ //System.out.println("UPDATE fieldlist.repaint"); fieldlist.repaint(); } }catch(Exception eggee){ //don't show anything System.out.println("Show ERROR: chattxt!"); } */ global.State=global.CHANGE; } if(global.State > (global.MENU-1) && !loaded){ loaded=true; System.out.println("show thread setVisible true ..."); applet.loaded=true; applet.setVisible(true); applet.validate(); setVisible(true); repaint(); } // if menu if(global.State < global.MENU1 ){ if( (global.RState == global.TEST || global.RState == global.AUTOMATEDRUN) && global.testlevel==global.level && keystack.isEmpty()){ int k1=testk1; global.finished=false; testx=global.player.getX(); testy=global.player.getY(); int yyy=testy==0?0:testy/global.STEPP; int xxx=testx==0?0:testx/global.STEPP; if(yyy==global.testoldy && xxx == global.testoldx){ // maybe we stopped in mid-test ... assume we need same key if(global.resettime+(1500) < d.getTime()){ justdoit=true; } if(global.resettime+(RESETTESTTIME*2) < d.getTime()){ global.resettime=d.getTime(); global.RState=0; if(!global.standalone) global.turn=-23325; for(int ii=0; ii 50){ justok=true; } }catch(Exception eegeg){} if(justok){ board(0,0,global.WIDTH,global.HEIGHT); // draw the board runningtime=d.getTime(); keystack.push(""+k1); global.teammove=0; global.teammovex=0; global.teammovey=0; global.teamkey=0; global.mp[yyy][xxx]=0; global.testoldx=xxx; global.testoldy=yyy; justok=false; } } } // waiting or not? } // if oldx!=x && oldy!=y } if(global.State == global.RUN ){ drawboard(); } if(global.State == global.RUNNING ){ running(); } // Stop the game! if(global.State == global.STOP) stop(); if(global.State == global.CHANGE) changing(); if(global.doboard){ doboard(); } if(global.dorefreshpos) dorefreshpos(); // // if(true){ if((oldstap!=global.stap || global.STEPP==1) && (!global.teamplay || global.RState==global.AUTOMATEDRUN || global.RState==global.TEST ) && global.State != global.DONOTHING){ oldstap=global.stap; already=true; // if(drawtime-olddrawtime > 200){ //System.out.println("Going to paint the current position!"); board(y==0?0:y/global.STEPP, x==0?0:x/global.STEPP , global.PARTDRAW_WIDTH, global.PARTDRAW_HEIGHT); olddrawtime=drawtime; // } already=false; } // Execute the run method of every object // Get network stuff if(global.doreload){ setVisible(false); applet.validate(); if(graphics != null){ graphics.setColor(backgroundcolor); graphics.fillRect(0,0,global.WIDTH*SIZE,global.HEIGHT*SIZE); } applet.thread.first=true; applet.showprogress=false; global.freeze=true; global.dontwalk=true; global.State=global.RELOADING; reload(); global.doreload=false; } } // if STATE != Menu // React on keys // BUT check it only on certain times! // Otherwise the animation sequence is not finished // and direction is changed during the animation // EVEN WHEN the global.freeze is true !!!! (?why?) date=new Date(); keytime=date.getTime(); int kx=global.player.getX(); int ky=global.player.getY(); if(debug) if(keytime-oldtime < global.KEYWAIT)System.out.println("Key wait!"); // Using the % == 0 ensures that animation is done if(!keystack.isEmpty() &&!global.freeze && kx%global.STEPP==0 && ky%global.STEPP==0 ){ k1=Integer.parseInt(keystack.pop()); oldtime=keytime; if(k1 == global.UP) global.dir=-global.WIDTH*global.STEPP; if(k1 == global.DOWN) global.dir=global.WIDTH*global.STEPP; if(k1 == global.RIGHT) global.dir=global.STEPP; if(k1 == global.LEFT) global.dir=-global.STEPP; // keyboard reactions if(global.key(global.dir)){ // this is done when we throw something in water // so .. when we don't do anything :) // but board needs to be cleaned up afterwards board(y==0?0:y/global.STEPP, x==0?0:x/global.STEPP , global.PARTDRAW_WIDTH, global.PARTDRAW_HEIGHT); } } // Single play help instruction if(global.level==1 && !global.teamplay && global.State < global.MENU1 && !global.keypressed){ if( (int)(date.getTime()-global.playtime)%1000 < 100){ board(0,0, global.WIDTH, global.HEIGHT ); if(chattext!=null&& global.nonwindows) chattext.requestFocus(); hidden.requestFocus(); if(fieldlist!=null) fieldlist.repaint(); } } /* // Multiplay help show if(global.level==1000 && global.teamplay && global.State < global.MENU1 && !global.mousepressed){ if( (date.getTime()-global.playtime)%1000 < 100){ board(0,0, global.WIDTH, global.HEIGHT ); } } */ // when you are known user and not on first level .. we still need to know if we need to put you on keyboard conrol // MAIN PAINT ROUTINE CALLED repaint(); // try{Thread.sleep(SPEED);}catch(Exception e){} if(isVisible()){ int displaytime=(int)(System.currentTimeMillis()-drawtime); //System.out.println("Displaytime:"+displaytime); drawtime=System.currentTimeMillis(); int sleeper=SPEED-displaytime; if(global.nonwindows) sleeper=5; else if(sleeper < 1) sleeper=11; try{ Thread.sleep(sleeper); }catch(Exception e){} } /* if(timer !=null){ synchronized(timer) { try { timer.wait(); } catch(Exception e) {} } } */ } // while } // All run method from all objects // // EVENTS // // Change this so that it doesn't use eventlists .. let the objects handle it themselves! // public void events(){ String enr; int t,idx1,idx2,s; String obj; String tim; String str; int px,py; int r=0; int ti; t=0; int n=0; for(int i=0;i 1 && (int)(System.currentTimeMillis()-eventtime) > 500 ){ if(n > 1 && (int)(System.currentTimeMillis()-eventtime) > 100 ){ eventtime=System.currentTimeMillis(); o=(oo)global.loader.getObject(n); }else o=(oo)global.loader.getObject(n); o.setMethod("event"); try{ //if(debug)System.out.println("Event on : "+o+" nr: "+i); o.execute(); }catch(Exception eegeg){ System.out.println("Show(Events) IN EXECUTE EVENT error: "+eegeg.toString());} if(global.resetevent){ //System.out.println("Resetevent called after execute event on :"+n); global.resetevent=false; o.setMethod("resetevent"); o.execute(); } }catch(Exception e){ // System.out.println("exception catched in all_events loop: "+e.toString()); } } px=global.player.getX(); py=global.player.getY(); if(global.State < global.MENU1){ if(global.aftermoves){ oldplayerx=px; oldplayery=py; global.aftermoves(); global.aftermoves=false; } } } // // Get the part of the background that is below the tile // pos = tile-pos // public Image getBackground(int pos){ Image cbackground=createImage(WSIZE,HSIZE); Graphics cgraphics=cbackground.getGraphics(); int x,y; //System.out.println("pos: "+pos); if(global.STEPP > 1){ // Strange that we must react differently when stepp > 1 y=pos==0?0: (int) Math.floor((pos/(global.WIDTH*global.STEPP))/global.STEPP); //System.out.println("y = "+y); int t=((global.WIDTH*global.STEPP)*global.STEPP); int www=y*t; int ddd=pos-www; //System.out.println("(W*S)*S:"+t+" Y*t: "+(ddd)); //System.out.println("pos:"+pos+" - ("+ddd+") : "+ ddd+"needs to be divided by stepp(5)"); x=(ddd)/global.STEPP; // x=((pos-global.WIDTH)%((global.WIDTH)*global.STEPP)); // x=x==0?0:x/global.STEPP; if(x 500){ playback(); oldplaybacktime=playbacktime; } } if(oldtime > 1000 && global.storedobject155 != 10000 && global.storedobject157 != 10000){ int t=(int)(keytime-oldtime); if( t > 10000 && t < 20000 && !global.PLAYBACK && global.PLAYERSTATE != 2){ global.PLAYERSTATE=2; global.boardrow=-1;global.boardcol=-1;global.doboard=true; } if( t > 20000 && !global.PLAYBACK && global.PLAYERSTATE!=3){ global.PLAYERSTATE=3; global.boardrow=-1;global.boardcol=-1;global.doboard=true; } } try{ /* if(offscreen == null || graphicsboard == null){ if(applet == null){ // This works when you have an applet wi if(offscreen == null || graphics == null){ offscreen=createImage(dimension.width,dimension.height); graphics=offscreen.getGraphics(); offscreenboard=createImage(dimension.width,dimension.height); graphicsboard=offscreenboard.getGraphics(); } // offscreen != null }else{ // applet != null offscreen=applet.buffer; graphics=offscreen.getGraphics(); offscreenboard=createImage(dimension.width,dimension.height); graphicsboard=offscreenboard.getGraphics(); } // applet ! = null } // offscreen */ //System.out.println("Global.buystate: "+global.BUYSTATE); if(global.State > (global.MENU-1) || (global.BUYSTATE) ){ if(global.BUYSTATE){ global.State=global.MENU_BUY; global.BUYSTATE=false; } //System.out.println("Menu loop:"+global.menus); for(menuloop=1; menuloop OLD info runningspeed .. //System.out.println(" SPEED: "+applet.runningspeed+" calc: "+SPEED); if(applet.drawtime < 30) SPEED=30; SPEED=50-applet.drawtime; if(debug)System.out.println(" SPEED DRAWTIME: "+applet.drawtime+" calc: "+SPEED+" Nice walk? "+global.nicewalk); if(global.extra.length() > 0){ String soundy=global.extra.substring(0,1); //System.out.println("Sound string: "+soundy); if(soundy.indexOf("0")> -1){ // System.out.println("SOUND is off!"); global.playsound=false; }else{ // System.out.println("SOUND is ON"); global.playsound=true; } String speedy=global.extra.substring(1,2); //System.out.println("Speed string: "+speedy); if(speedy.indexOf("5") > -1){ global.nicewalk=true; } if(speedy.indexOf("1") > -1){ global.nicewalk=false; } } if(global.playsound){ playsound.setImage(imgnoplaysound); playsound.setHintImage(imghintnoplaysound); } else{ playsound.setImage(imgplaysound); playsound.setHintImage(imghingplaysound); } //System.out.println("Nicewalk: "+global.nicewalk); // if(global.nicewalk){ // //setSpeed(8,5,SPEED); // setSpeed(5,8,SPEED); // }else{ // setSpeed(1,40,SPEED); // // } // // Changed after comments on javagaming.org on lack of animation setSpeed(5,8,SPEED); if(network == null && !global.standalone){ try{ //System.out.println( "L A U N C H N E T W R K"); network=new Network(global); network.start(); global.isnetwork=true; }catch(Exception ega){ //System.out.println("network init exc: "+ega.toString()); } }else { global.turn=1; global.isturn=true; } try{ if(chattext!=null && global.nonwindows) chattext.requestFocus(); hidden.requestFocus(); if(fieldlist!=null){ //System.out.println("UPDATE fieldlist.repaint"); fieldlist.repaint(); } }catch(Exception eggee){ //don't show anything System.out.println("Show ERROR: chattxt!"); } global.State=global.CHANGE; } */ // standard states (no menus!) if(global.State < global.MENU1 && offscreen != null){ try{ graphics.setColor(backgroundcolor); }catch(Exception eeee){ System.out.println("Show -> setColor on gBraphics : "+eeee.toString()); } // Between levels if( (global.State == global.CHANGE || global.State == global.RELOADING ) && isVisible()){ showchanging(); return; } // NEVER USED? if(global.State == global.STOP){ graphics.drawString("STOP", global.WIDTH/2, global.HEIGHT/2); return; } // PERFORM EVENTS events(); if(global.teamplay && global.all != 4 && !global.standalone){ shownetworkwait(); refreshed=false; //System.out.println("Setting refreshed-1-"); }else{ if(global.teamplay && !refreshed ){ //System.out.println("Board draw after mousemove-1-"); board(0,0, global.WIDTH, global.HEIGHT ); refreshed=true; } } if(global.teamplay && global.turn != -2 && global.turn != global.room){ refreshed=false; //System.out.println("Setting refreshed -2- "); }else{ if(global.teamplay && !refreshed ){ //System.out.println("Board draw after mousemove-2-?"); board(0,0, global.WIDTH, global.HEIGHT ); refreshed=true; } } if(graphicsboard!=null){ Date rdate=new Date(); int sec=(int)((rdate.getTime()-global.playtime)/1000); if(sec!=oldsec){ oldsec=sec; // SHOW THE TIME int timex=0; int timey=((global.HEIGHT+2)*SIZE)+12; // graphicsboard.setColor(Color.black); graphicsboard.setColor(backgroundcolor); graphicsboard.fillRect(global.WIDTH*SIZE,0, 300, 50); users=""; users2=""; for(int oi9=0; oi9<2;oi9++) { if(global.roomname!=null) if(global.roomname[oi9].length() > 0) users+=" ["+(oi9+1)+"]"+global.roomname[oi9]; } for(int oi9=2; oi9<4;oi9++) { if(global.roomname!=null) if(global.roomname[oi9].length() > 0) users2+=" ["+(oi9+1)+"]"+global.roomname[oi9]; } graphicsboard.setFont(global.infofont); graphicsboard.setColor(fieldlistforegroundcolor); long used=global.usedMemory(); // graphicsboard.drawString("Time:"+sec+" Steps: "+global.steptaken+"|"+used,global.WIDTH*SIZE,12); // graphicsboard.drawString("Score: "+global.score+(global.buy?"|$!":"") ,global.WIDTH*SIZE,22); font.drawString(offscreenboard, "Time:"+sec, (global.WIDTH*SIZE)+10,0, null); font.drawString(offscreenboard, "Steps:"+global.steptaken, (global.WIDTH*SIZE)+10, 21,null); font.drawString(offscreenboard, "Score:"+global.score, (global.WIDTH*SIZE)+10,37,null); font.drawString(offscreenboard, "Level:"+global.level+" ", (global.WIDTH*SIZE)+10,51,null); if(global.teamplay && users.length() > 0){ graphicsboard.setColor(fieldlistbackgroundcolor); graphicsboard.fillRect(global.WIDTH*SIZE,22, 300, 32); graphicsboard.setColor(fieldlistforegroundcolor); graphicsboard.drawString("Users: "+users ,global.WIDTH*SIZE,32); if(users2.length() > 0){ graphicsboard.setColor(fieldlistbackgroundcolor); graphicsboard.fillRect(global.WIDTH*SIZE,42, 300, 22); graphicsboard.setColor(fieldlistforegroundcolor); graphicsboard.drawString(users2 ,global.WIDTH*SIZE,42); } } graphicsboard.setFont(global.textfont); graphicsboard.setColor(Color.white); } } // OFFSCREEN DOUBLE BUFFER DISPLAY try{ if(global.gridloaded && offscreenboard !=null){ if(drawer > 0|| global.drawer > 0 || global.doboard || drawtime-olddrawtime > 200){ g.drawImage( offscreenboard,STARTX,STARTY,this); olddrawtime=drawtime; } drawer=0;global.drawer=0; }else{ if(drawer > 0|| global.drawer > 0 || global.doboard || drawtime-olddrawtime > 200){ g.drawImage(offscreen, STARTX, STARTY, this); // double buffer olddrawtime=drawtime; } drawer=0;global.drawer=0; } }catch(Exception eeee){ System.out.println("Exception gridload drawing offscreenboard/offscreen"+eeee.toString()); } } // global.global.State < Menu else{ try{ //System.out.println( "DrawTime: "+drawtime); //System.out.println("Update (show-3) state: "+global.State); if(drawer > 0|| global.drawer > 0 || global.doboard || drawtime-olddrawtime > 200 ){ olddrawtime=drawtime; g.drawImage(offscreen, STARTX, STARTY, this); // double buffer } drawer=0;global.drawer=0; }catch(Exception eggeeg){ System.out.println(" offscreen drawing error exception in update: "+eggeeg.toString()); } } // state.menu }catch(Exception e){ System.out.println("update catch error: "+e.toString()); } } public void paint(Graphics g){ update(g); } // ----- // Network Wait information // ---- public void shownetworkwait(){ if(global.RState != global.TEST && global.RState != global.AUTOMATEDRUN){ graphicsboard.setColor(backgroundcolor); graphicsboard.fillRect(0,0,800,600); } graphicsboard.setColor(Color.gray); graphicsboard.fillRect(200,200,200,42); graphicsboard.setColor(Color.black); graphicsboard.fillRect(212,208,180,25); graphicsboard.setColor(Color.white); graphicsboard.drawString(" CHECKING NETWORK",232,225); } // // Load all the images AFTER the grid has load // public void loadImages(){ // level load before int g=0; int sizey=SIZE/2; /* imgnormal=global.loadImage(global.Server, "images/imgnormal.gif",this); imghintnormal=global.loadImage(global.Server, "images/imgnormal_2.gif",this); imgfastest=global.loadImage(global.Server, "images/imgfastest.gif",this); imghintfastest=global.loadImage(global.Server, "images/imgfastest_2.gif",this); */ imglevels=global.loadImage(global.Server, "images/levelsbutton"+global.Extention,this); imghintlevels=global.loadImage(global.Server, "images/levelsbutton_2"+global.Extention,this); imgnormal=global.loadImage(global.Server, "images/normalbutton"+global.Extention,this); imghintnormal=global.loadImage(global.Server, "images/normalbutton_2"+global.Extention,this); imgfastest=global.loadImage(global.Server, "images/fasterbutton"+global.Extention,this); imghintfastest=global.loadImage(global.Server, "images/fasterbutton_2"+global.Extention,this); imgteamplay=global.loadImage(global.Server, "images/imgteamplay.gif",this); imghintteamplay=global.loadImage(global.Server, "images/imgteamplay_2.gif",this); imgsingleplay=global.loadImage(global.Server,"images/imgsingleplay.gif",this); imghintsingleplay=global.loadImage(global.Server,"images/imgsingleplay_2.gif",this); /* imgescape=global.loadImage(global.Server, "images/imgescape.gif",this); imghintescape=global.loadImage(global.Server, "images/imgescape_2.gif",this); */ imgescape=global.loadImage(global.Server, "images/escapebutton"+global.Extention,this); imghintescape=global.loadImage(global.Server, "images/escapebutton_2"+global.Extention,this); /* imgundo=global.loadImage(global.Server, "images/undo.gif",this); imghintundo=global.loadImage(global.Server, "images/undo_2.gif",this); */ imgundo=global.loadImage(global.Server, "images/undobutton"+global.Extention,this); imghintundo=global.loadImage(global.Server, "images/undobutton_2"+global.Extention,this); /* imgbackup=global.loadImage(global.Server, "images/backup.gif",this); imghintbackup=global.loadImage(global.Server, "images/backup_2.gif",this); */ imgbackup=global.loadImage(global.Server, "images/backupbutton"+global.Extention,this); imghintbackup=global.loadImage(global.Server, "images/backupbutton_2"+global.Extention,this); // imgbackup_big=global.loadImage(global.Server, "images/backup_big.gif",this); /* imgrestore=global.loadImage(global.Server, "images/restore.gif",this); imghintrestore=global.loadImage(global.Server, "images/restore_2.gif",this); */ imgrestore=global.loadImage(global.Server, "images/restorebutton"+global.Extention,this); imghintrestore=global.loadImage(global.Server, "images/restorebutton_2"+global.Extention,this); // imgrestore_big=global.loadImage(global.Server, "images/restore_big.gif",this); /* imgplaysound=global.loadImage(global.Server, "images/sound.gif",this); imghintplaysound=global.loadImage(global.Server, "images/sound_2.gif",this); */ imgplaysound=global.loadImage(global.Server, "images/soundbutton"+global.Extention,this); imghintplaysound=global.loadImage(global.Server, "images/soundbutton_2"+global.Extention,this); /* imgnoplaysound=global.loadImage(global.Server, "images/nosound.gif",this); imghintnoplaysound=global.loadImage(global.Server, "images/nosound_2.gif",this); */ imgnoplaysound=global.loadImage(global.Server, "images/nosoundbutton"+global.Extention,this); imghintnoplaysound=global.loadImage(global.Server, "images/nosoundbutton_2"+global.Extention,this); // arrows on board in team-play imgrightsmall=global.loadImage(global.Server, "images/imgrightsmall.gif",this); imgleftsmall=global.loadImage(global.Server, "images/imgleftsmall.gif",this); imgupsmall=global.loadImage(global.Server, "images/imgupsmall.gif",this); imgdownsmall=global.loadImage(global.Server, "images/imgdownsmall.gif",this); imgleft=global.loadImage(global.Server, "images/imgleft.gif",this); imghintleft=global.loadImage(global.Server, "images/imgleft_2.gif",this); imgup=global.loadImage(global.Server, "images/imgup.gif",this); imghintup=global.loadImage(global.Server, "images/imgup_2.gif",this); imgright=global.loadImage(global.Server, "images/imgright.gif",this); imghintright=global.loadImage(global.Server, "images/imgright_2.gif",this); imgup=global.loadImage(global.Server, "images/imgup.gif",this); imghintup=global.loadImage(global.Server, "images/imgup_2.gif",this); imgdown=global.loadImage(global.Server, "images/imgdown.gif",this); imghintdown=global.loadImage(global.Server, "images/imgdown_2.gif",this); imgtest=global.loadImage(global.Server, "images/imgtest.gif",this); imghinttest=global.loadImage(global.Server, "images/imgtest_2.gif",this); imgreset=global.loadImage(global.Server, "images/imgreset.gif",this); imghintreset=global.loadImage(global.Server, "images/imgreset_2.gif",this); imgblank=global.loadImage(global.Server, "images/imgblank.gif",this); imghintblank=global.loadImage(global.Server, "images/imgblank_2.gif",this); /* imgscores=global.loadImage(global.Server, "images/imgscores.gif",this); imghintscores=global.loadImage(global.Server, "images/imgscores_2.gif",this); imgshow=global.loadImage(global.Server, "images/imgshow.gif",this); imgshow_2=global.loadImage(global.Server, "images/imgshow_2.gif",this); */ imgscores=global.loadImage(global.Server, "images/scoresbutton"+global.Extention,this); imghintscores=global.loadImage(global.Server, "images/scoresbutton_2"+global.Extention,this); imgshow=global.loadImage(global.Server, "images/showbutton"+global.Extention,this); imgshow_2=global.loadImage(global.Server, "images/showbutton_2"+global.Extention,this); /* global.backgroundmusic=global.loadSound(global.Server, "/maze/00.au"); global.backgroundsound=global.loadSound(global.Server, "/maze/0.au"); */ // global.backgroundsoundbase=global.backgroundsound; // // global.level should be read in BEFORE so that we have the good level // global.Directory="/maze/level/"+(global.level)+"/"; if(debug)System.out.println("globalING LEVEL NUMBER: "+global.level); g=1; try{ image[g]=global.loadImage(global.Server, global.Directory+g+global.Extention,this); }catch(Exception eg){image[g]=null;} if(image[g]==null){ global.Directory="/maze/"; } //System.out.println("Directory: "+global.Directory); int kl=0; int kk=0; for(kl=0; kl<4;kl++){ // wait-state .. when playerstate == Sleep , think, pee etc.. :) if(kl > global.PUSHING){ //System.out.println("Loading playerstate: "+kl); user_front[0][kl]=global.loadImage(global.Server, "upload/10000"+"_1_1_"+kl+global.Extention, this); user_left[0][kl]=global.loadImage(global.Server, "upload/10000"+"_4_1_"+kl+global.Extention, this); user_back[0][kl]=global.loadImage(global.Server, "upload/10000"+"_3_1_"+kl+global.Extention, this); user_right[0][kl]=global.loadImage(global.Server, "upload/10000"+"_2_1_"+kl+global.Extention, this); }else{ // Walk and Push for(kk=0; kk 1000){ global.introstate=100; } if(global.State == global.CHANGE) return; Image offscreen_tmp=createImage(10,10); Image crop=createImage(1,1); Graphics graphics_tmp=null; Image tmp=createImage(10,10); // directional image (arrows) int x=global.player.getX(); int y=global.player.getY(); // Player pos int onr=0; // object number oo o; // temp object int h_start=(r==0?nrw==global.WIDTH?0:r:r==1?r-1:r-2)*global.STEPP; int w_start=(c==0?c:c==1?c-1:c-2)*global.STEPP; int h_end=(h_start)+((nrh+1)*global.STEPP); int w_end=(w_start)+(nrw*global.STEPP); int ssize=SIZE/global.STEPP; if(nrw==global.WIDTH){ global.dontwalk=false; // TESTING IF WE CAN LIVE WITHOUT UNFREEZING HERE // global.freeze=false; if(fieldlist!=null){ fieldlist.select(global.level-1); } } offscreen_tmp=createImage((nrw*SIZE), (((nrh+2)*SIZE)+SIZE)); if(offscreen_tmp!=null) graphics_tmp=offscreen_tmp.getGraphics(); // // draw Backgrond // if(graphics_tmp != null && global.background!=null){ if( global.STEPP==1){ //WORKS with global.STEPP if(global.background != null) graphics_tmp.drawImage(global.background,-(w_start*SIZE),(-(h_start*SIZE))-SIZE,this); } else{ if(global.background!=null) graphics_tmp.drawImage(global.background,-((w_start/global.STEPP)*SIZE),(-((h_start/global.STEPP)*SIZE))-SIZE,this); } } if(graphics != null){ int hh=0; int hhi=0; int ww=0; int wwi=0; for(hh=h_start; hh < h_end+(global.STEPP+1) && hh < (global.HEIGHT+(global.STEPP+1))*global.STEPP; hh++,hhi++){ for(ww=w_start,wwi=0; ww < w_end && ww < (global.WIDTH+2)*global.STEPP ; ww++, wwi++){ onr=global.grid_items[hh][ww]; // object number // determine if you are a player or object if(hh == y && ww == x ){ // o=(oo)global.loader.getObject(0); o=(oo)playerobject; }else{ if(onr > 1) try{ drawer++; // Tell the 'world' that we have drawn something o=(oo)global.loader.getObject(onr); }catch(Exception egw){ o=(oo)global.loader.getObject(1); } else o=null; } // draw object if(o!=null){ xi=o.getImage(); if(xi!=null){ if(graphics_tmp !=null){ graphics_tmp.drawImage(xi, ((wwi*ssize)), ((hhi*ssize)), WSIZE, HSIZE, applet); } // if graphics_tmp != null } // if image else{ // System.out.println(" IMAGE IS NULL! "+onr+" o.toString: "+o.toString()); } } // if object // MULTIPLAYER! // Draw arrows if there are any if(hh%global.STEPP == 0 && ww%global.STEPP == 0 && global.mp[hh==0?0:hh/global.STEPP][ww==0?0:ww/global.STEPP]!=0){ switch(global.mp[hh==0?0:hh/global.STEPP][ww==0?0:ww/global.STEPP]){ case 1: //right; di=imgrightsmall; break; case 2: //left; di=imgleftsmall; break; case 3: //up; di=imgupsmall; break; case 4: //down; di=imgdownsmall; break; } if(di!=null && graphics_tmp!=null) graphics_tmp.drawImage(di, ((wwi*ssize)), ((hhi*ssize)), WSIZE, HSIZE, applet); } // are there arrows? } // for pos }// for row crop=createImage((nrw==global.WIDTH?nrw:c+nrw>global.WIDTH?((nrw+c)==(global.WIDTH+4)?3:(global.teamplay?3:5)):5)*SIZE, (nrh==global.HEIGHT?nrh+2:6)*SIZE -(nrh==global.HEIGHT?0:r+nrh==global.HEIGHT+3?SIZE:(SIZE/2)) ); if(crop!=null){ Graphics gr=crop.getGraphics(); if(offscreen_tmp != null){ gr.drawImage(offscreen_tmp,0, (nrh==global.HEIGHT?0:r<2?0:-SIZE),this); } }else{offscreen_tmp=null;} // Debug // graphicsboard.drawImage(crop, 0,0,this); // PUT cropped image on the board if(graphicsboard!=null && crop != null){ graphicsboard.drawImage(crop,( nrw==global.WIDTH?w_start:(c>1?c-2:0))*SIZE,( (nrh==global.HEIGHT?r:(r>1?r-1:r<2?0:r)) *SIZE ),this); // debug cropped image drawing back to the screen //graphicsboard.fillRect(0,500,1024,800); //graphicsboard.drawImage(crop,0,500,this); } // tIME test if(global.level==1 && !global.keypressed && !global.teamplay ){ Date date=new Date(); long dd=(date.getTime() - global.playtime); if( (int)(dd)%1000 < 100){ //System.out.println("Room : "+global.room+" Usernr: "+global.usernr+" Score: "+global.score); if( levelintro++ < 2){ /* if(keysimage != null) graphicsboard.drawImage(keysimage, 260,135, this); */ if(targetimage2!=null) graphicsboard.drawImage(targetimage2, 460,375, this); }else{ levelintro=1; // if(keysimage != null)graphicsboard.drawImage(keysimage, 260,135, this); if(targetimage != null)graphicsboard.drawImage(targetimage, 460,375, this); } if(chattext!=null&& global.nonwindows) chattext.requestFocus(); hidden.requestFocus(); if(fieldlist!=null) fieldlist.repaint(); } } /* // tIME test if(global.level==1000 && !global.mousepressed && global.teamplay && global.RState != global.AUTOMATEDRUN ){ long dd=(System.currentTimeMillis() - anitime); if(dd% 100 < 30){ if(dd > 800){ if(anistep++ > 13)anistep=1; anitime=System.currentTimeMillis();; } if(animationimage[anistep]!=null){ graphicsboard.setColor(backgroundcolor); graphicsboard.fillRect(140,325,370,175); graphicsboard.drawImage(animationimage[anistep], 150,335, this); graphicsboard.setColor(Color.white); } } } */ } // is there a graphics display if(nrw==global.WIDTH && applet.loaded ){ menu(true); //System.out.println("Set PROGRESSIONBAR to FALSE"); global.showprogressionbar=false; applet.thread.first=true; setVisible(true); applet.setVisible(true); applet.validate(); if(!global.first){ if(chattext!=null&& global.nonwindows) chattext.requestFocus(); hidden.requestFocus(); // if(fieldlist!=null) // fieldlist.repaint(); global.first=true; } } if(graphics_tmp != null) graphics_tmp.dispose(); } // // // SEE board .. maybe can be incorporated somehow .. // // public void refreshpos(int r,int c){ if(global.State == global.CHANGE) return; Image offscreen_tmp=createImage(10,10); Image crop=createImage(1,1); Graphics graphics_tmp=null; Image tmp=createImage(10,10); // directional image (arrows) // Image di=createImage(10,10); Image di=createImage(10,10); int x=global.player.getX(); int y=global.player.getY(); // Player pos int onr=0; // object number oo o; // temp object int nrw=1; int nrh=1; int h_start=r-global.STEPP; int w_start=c; int h_end=h_start+1; int w_end=w_start; if(h_start < 0) return; int ssize=SIZE/global.STEPP; offscreen_tmp=createImage(SIZE, 3*SIZE); if(offscreen_tmp!=null) graphics_tmp=offscreen_tmp.getGraphics(); // // draw Backgrond // if(graphics_tmp != null && global.background!=null){ if( global.STEPP==1){ //WORKS with global.STEPP graphics_tmp.drawImage(global.background,-(w_start*SIZE),(-(h_start*SIZE))-SIZE,this); } else{ graphics_tmp.drawImage(global.background,-((w_start/global.STEPP)*SIZE),(-((h_start/global.STEPP)*SIZE))-SIZE,this); } } if(graphics != null){ int hh=0; int hhi=0; int ww=0; int wwi=0; for(hh=h_start; hh < h_end+(1*global.STEPP+1) && hh < (global.HEIGHT+1)*global.STEPP; hh+=global.STEPP,hhi+=global.STEPP){ for(ww=w_start,wwi=0; ww < w_end+1 && ww < (global.WIDTH+1)*global.STEPP ; ww++, wwi++){ onr=global.grid_items[hh][ww]; // object number // determine if you are a player or object if(hh == y && ww == x ){ o=(oo)global.loader.getObject(0); }else{ if(onr > 1) try{ o=(oo)global.loader.getObject(onr); }catch(Exception egw){ o=(oo)global.loader.getObject(1); } else o=null; } // draw object if(o!=null){ xi=o.getImage(); if(xi!=null){ if(graphics_tmp !=null){ graphics_tmp.drawImage(xi, ((wwi*ssize)), ((hhi*ssize)), WSIZE, HSIZE, applet); } // if graphics_tmp != null } // if image else{ System.out.println(" IMAGE IS NULL! "+onr+" o.toString: "+o.toString()); } } // if object // MULTIPLAYER! // Draw arrows if there are any if(hh%global.STEPP == 0 && ww%global.STEPP == 0 && global.mp[hh==0?0:hh/global.STEPP][ww==0?0:ww/global.STEPP]!=0){ switch(global.mp[hh==0?0:hh/global.STEPP][ww==0?0:ww/global.STEPP]){ case 1: //right; di=imgrightsmall; break; case 2: //left; di=imgleftsmall; break; case 3: //up; di=imgupsmall; break; case 4: //down; di=imgdownsmall; break; } graphics_tmp.drawImage(di, ((wwi*ssize)), ((hhi*ssize)), WSIZE, HSIZE, applet); } // are there arrows? } // for pos }// for row crop=createImage(SIZE, 2*SIZE); if(crop!=null){ Graphics gr=crop.getGraphics(); if(offscreen_tmp != null){ gr.drawImage(offscreen_tmp,0, -SIZE,this); } }else{offscreen_tmp=null;} // PUT cropped image on the board if(graphicsboard!=null && crop != null){ graphicsboard.drawImage(crop,(w_start==0?0:w_start/global.STEPP)*SIZE,((h_start==0?0:h_start/global.STEPP)*SIZE)+SIZE+ssize ,this); } } // is there a graphics display } /// --- REFRESHpos /* // OBSOLETED !! // Make image transparent // leave it in since we can use the pixelgrabber for other aspects maybe! // Some reports say it is WAY TO SLOW !!!!!! // public Image trans(Image bi) { int width = bi.getWidth( this); int height= bi.getHeight( this); int[] pgPixels = new int[height* width]; PixelGrabber pg = new PixelGrabber(bi, 0, 0, width, height, pgPixels, 0,width); try { pg.grabPixels(); } catch (InterruptedException e) { e.printStackTrace(); } // try for (int y = 0; y > 24; int r = (pgPixels[i] & 0x00ff0000) >> 16; int g = (pgPixels[i] & 0x0000ff00) >> 8; int b = pgPixels[i] & 0x000000ff; if (r >= 210 && g >= 0 && b >= 210) { a = 0; pgPixels[i] = a | (r << 16) | (g << 8) | b; } // if pink? } // for x } // for y Image _i = createImage(new MemoryImageSource(width, height, pgPixels, 0,width)); return _i; }//trans */ // // Next level! // public void Next(){ global.showprogressionbar=true; global.Directory="/maze/level"+(global.level+1)+"/"; int g=1; global.first=false; image[g]=global.loadImage(global.Server, global.Directory+g+global.Extention,this); if(image[g]==null){ global.Directory="/maze/"; image[g]=global.loadImage(global.Server, global.Directory+g+global.Extention,this); } // Close events and stuff global.resets(); // Clear objects global.clears(); // Re-Initialize objects global.inits(); // Next Level global.level++; fieldlist.select(global.level-1); global.init(); if(chattext!=null&& global.nonwindows) chattext.requestFocus(); hidden.requestFocus(); if(fieldlist!=null) fieldlist.repaint(); } public void viewscores(){ try{ applet.getAppletContext().showDocument(new URL(global.Server+"overview.php?usernr="+global.usernr), "overview"); }catch(Exception egf){ System.out.println("Error opening: "+global.Server+"overview.php -> "+egf.toString()); } } public void reload(){ global.showprogressionbar=true; global.mousepressed=false; global.keypressed=false; // Store before reload reloading(); } // // ESCape // public void reloading(){ oldusers=" "; global.resetevent=false; global.waitforme=false; setVisible(false); applet.validate(); if(global.RState == global.TEST){ for(int ii=0; ii listbox creation"); } }else{ System.out.println( "ERROR WITH CUSTOM LISTBOX! ---> Font unavailable"); } /* info=new java.awt.List(); info.setBounds((global.WIDTH*SIZE), 5*sizey, 7*sizex, sizex*5); info.setFont(global.chatfont); info.setName("info"); info.setBackground(infobackgroundcolor); info.setForeground(infoforegroundcolor); info.setVisible(false); if(debug)System.out.println("info.setVisible(flase!"); add(info); */ if(font != null){ try{ info=new myListBox(font,offscreenboard, this,false,8); }catch(Exception e){ System.out.println("error creating listbox: "+e.toString()); } if(info!=null){ info.setName("info"); info.setVisible(false); info.setBackground(backgroundcolor); // info.setBounds((global.WIDTH*SIZE), 5*sizey, 7*sizex, sizex*5); // info.setBounds((global.WIDTH*SIZE), 2*sizey, 7*sizex, sizex*5); // info.setBounds((global.WIDTH*SIZE), 80, 120, 50); info.setBounds(0,0,1,1); info.addActionListener(this); add(info); }else{ System.out.println( "ERROR WITH CUSTOM LISTBOX! ---> listbox creation"); } }else{ System.out.println( "ERROR WITH CUSTOM LISTBOX! ---> Font unavailable"); } right=new ImageButton(imgright,imghintright,"arrowright",this,"Right"); // right.setBounds((global.WIDTH*SIZE), 8*sizey, B, B); right.setBounds(0,0,1,1); right.setVisible(false); right.addActionListener(this); add(right); left=new ImageButton(imgleft,imghintleft,"arrowleft",this, "Left"); // left.setBounds((global.WIDTH*SIZE)+B*1, 8*sizey, B, B); left.setBounds(0,0,1,1); left.setVisible(false); left.addActionListener(this); add(left); up=new ImageButton(imgup,imghintup,"arrowup",this, "Up"); // up.setBounds((global.WIDTH*SIZE)+B*2, 8*sizey, B, B); up.setBounds(0,0,1,1); up.setVisible(false); up.addActionListener(this); add(up); down=new ImageButton(imgdown,imghintdown,"arrowdown",this, "Down"); // down.setBounds((global.WIDTH*SIZE)+B*3, 8*sizey, B, B); down.setBounds(0,0,1,1); down.setVisible(false); down.addActionListener(this); add(down); test=new ImageButton(imgtest,imghinttest,"thetest",this, "Test"); // test.setBounds((global.WIDTH*SIZE)+B*3, 9*sizey, B, B); test.setBounds(0,0,1,1); test.setVisible(false); test.addActionListener(this); add(test); reset=new ImageButton(imgreset,imghintreset,"thereset",this, "Reset"); // reset.setBounds((global.WIDTH*SIZE)+B*2, 9*sizey, 100, B); reset.setBounds(0,0,1,1); reset.setVisible(false); reset.addActionListener(this); add(reset); blank=new ImageButton(imgblank,imghintblank,"arrowblank",this, "Blank"); // blank.setBounds((global.WIDTH*SIZE), 9*sizey, B, B); blank.setBounds(0,0,1,1); blank.setVisible(false); blank.addActionListener(this); add(blank); teamplay=new ImageButton(imgteamplay,imghintteamplay,"teamplay",this,"Team"); // teamplay.setBounds((global.WIDTH*SIZE), 10*sizey, B, B); teamplay.setBounds(0,0,1,1); teamplay.setVisible(false); teamplay.addActionListener(this); // add(teamplay); singleplay=new ImageButton(imgsingleplay,imghintsingleplay,"singleplay",this,"Single"); // singleplay.setBounds((global.WIDTH*SIZE)+B, 10*sizey, B, B); singleplay.setBounds(0,0,1,1); singleplay.setVisible(false); singleplay.addActionListener(this); // add(singleplay); // ----------------------- // START OF PANEL // ----------------------- int D=80; escapebutton=new ImageButton(imgescape,imghintescape,"escape",this,"Escape"); // escapebutton.setBounds((global.WIDTH*SIZE), 11*sizey,B, B); escapebutton.setBounds((global.WIDTH*SIZE), D ,C, B); escapebutton.setVisible(false); escapebutton.addActionListener(this); add(escapebutton); undobutton=new ImageButton(imgundo,imghintundo,"undo",this,"Undo"); // undobutton.setBounds((global.WIDTH*SIZE), 12*sizey,B, B); undobutton.setBounds((global.WIDTH*SIZE), D+B ,C, B); undobutton.setVisible(false); undobutton.addActionListener(this); add(undobutton); backupbutton=new ImageButton(imgbackup,imghintbackup,"levelbackup",this, "Backup"); // backupbutton.setBounds((global.WIDTH*SIZE)+(B*2), 12*sizey,B, B); // backupbutton.setBounds((global.WIDTH*SIZE), 4*sizey,80, B); backupbutton.setBounds((global.WIDTH*SIZE), D+(B*2) ,C, B); backupbutton.setVisible(false); backupbutton.addActionListener(this); add(backupbutton); restore=new ImageButton(imgrestore,imghintrestore,"levelrestore",this, "Restore"); // restore.setBounds((global.WIDTH*SIZE)+80,4*sizey,100, B); restore.setBounds((global.WIDTH*SIZE), D+(B*3), C , B); restore.setVisible(false); restore.addActionListener(this); add(restore); // NOT VISIBLE ... YET //System.out.println("All scores image:"+imghintscores); allscores=new ImageButton(imgscores, imghintscores,"allscores",this,"Scores"); allscores.setBounds(global.WIDTH*SIZE, D+(B*4) , C ,B); allscores.setVisible(false); allscores.addActionListener(this); add(allscores); showit=new ImageButton(imgshow, imgshow_2,"showit",this,"Showit"); showit.setBounds((global.WIDTH*SIZE), D+(B*5), C ,B); showit.setVisible(false); showit.addActionListener(this); add(showit); // playsound=new ImageButton(imgnoplaysound,imghintnoplaysound,"playsound",this, "Sound"); playsound=new ImageButton(imgnoplaysound,imghintnoplaysound,"playsound",this, "Sound"); if(global.playsound){ playsound.setImage(imgnoplaysound); playsound.setHintImage(imghintnoplaysound); } else{ playsound.setImage(imgplaysound); playsound.setHintImage(imghintplaysound); } // playsound.setBounds((global.WIDTH*SIZE),13*sizey,B, B); playsound.setBounds((global.WIDTH*SIZE), D+(B*6) , C, B); playsound.setVisible(false); playsound.addActionListener(this); add(playsound); fastest=new ImageButton(imgfastest,imghintfastest,"fastest",this,"Fastest"); // fastest.setBounds((global.WIDTH*SIZE)+B, 11*sizey, B, B); fastest.setBounds((global.WIDTH*SIZE), D+(B*7) ,C, B); fastest.setVisible(false); fastest.addActionListener(this); add(fastest); normal=new ImageButton(imgnormal,imghintnormal,"normal",this, "Regular"); normal.setVisible(false); normal.addActionListener(this); add(normal); levels=new ImageButton(imglevels,imghintlevels,"levels",this, "Regular"); // normal.setBounds((global.WIDTH*SIZE)+(B*2), 11*sizey, B, B); levels.setBounds((global.WIDTH*SIZE), D+(B*8) , C, B); levels.setVisible(false); levels.addActionListener(this); add(levels); /* fieldlist=new java.awt.List(); fieldlist.setName("fieldlist"); fieldlist.setBounds((global.WIDTH*SIZE), 15*sizey, 9*sizex, sizex*3); fieldlist.setVisible(false); if(debug)System.out.println("fieldlist.setVisible(flase!"); fieldlist.setFont(global.textfont); fieldlist.setBackground(fieldlistbackgroundcolor); fieldlist.setForeground(fieldlistforegroundcolor); add(fieldlist); fieldlist.addActionListener(this); */ if(font != null){ try{ // With selector bar fieldlist=new myListBox(fontfieldlist,offscreenboard, this,true,16); }catch(Exception e){ System.out.println("error creating listbox: "+e.toString()); } if(fieldlist!=null){ fieldlist.setName("fieldlist"); fieldlist.setVisible(false); // fieldlist.setBounds((global.WIDTH*SIZE), 15*sizey, (8*sizex), sizex*4); fieldlist.setBounds(0,0,1,1); // turn of horizontal scrollbar fieldlist.setHorizontal(false); fieldlist.setBackground(backgroundcolor); fieldlist.addActionListener(this); add(fieldlist); }else{ System.out.println( "ERROR WITH CUSTOM LISTBOX! ---> listbox creation"); } }else{ System.out.println( "ERROR WITH CUSTOM LISTBOX! ---> Font unavailable"); } // Not necesary ? if(fieldlist!=null){ for(int lvl=1; lvl 1){ normal.setBounds(0,0,1,1); fastest.setBounds((global.WIDTH*SIZE), 8*sizey,C, B); } else{ normal.setBounds((global.WIDTH*SIZE), 8*sizey, C, B); fastest.setBounds(0,0,1,1); } */ if(global.playsound){ playsound.setImage(imgnoplaysound); playsound.setHintImage(imghintnoplaysound); } else{ playsound.setImage(imgplaysound); playsound.setHintImage(imghintplaysound); } } // Store Extra // -- If we are connected to the network // Store information like sound / fast/slow for next time // public void storeextra(){ if(global.playsound) global.extra="1"; else global.extra="0"; // Number of steps global.extra+=global.STEPP; Date date=new Date(); String result=global.execute("storeextra.php?usernr="+global.usernr+"&extra="+global.extra+"&time="+date.getTime()); } // change between levels public void showchanging(){ applet.thread.first=true; setVisible(false); applet.validate(); // wait .. otherwise flickering try{ looper.sleep(20); }catch(Exception eegeg){} } public void escape(){ global.showtext=""; global.PLAYBACK=false; if(global.teamplay)return; global.showprogressionbar=true; global.playbackkeys=""; if(global.RState == global.TEST){ for(int ii=0; ii 0) global.playback=result; else global.playback=global.playbackkeys; escape(); // Show playback global.PLAYBACK=true; } public void playback(){ int key=0; if(global.freeze)return; try{ String part=global.playback.substring( global.playbacknr, ++global.playbacknr); // System.out.println("Part: "+part+ "("+global.playback+")"); if(part.length() > 0) key=Integer.parseInt(part); //System.out.println("Key action playback : "+key); switch(key){ case 1: global.dir=(global.STEPP);break; case 2: global.dir=(-global.STEPP); break; case 3: global.dir=(-global.WIDTH*global.STEPP);break; case 4: global.dir=(global.WIDTH*global.STEPP);break; } if(key > 0){ global.key(global.dir); int x=global.player.getX(); int y=global.player.getY(); board(y==0?0:y/global.STEPP, x==0?0:x/global.STEPP , global.PARTDRAW_WIDTH, global.PARTDRAW_HEIGHT); } }catch(Exception egeg){ System.out.println("error in playback .. playback=false! ("+egeg.toString()+")"); global.PLAYBACK=false; } } //======= // // EVENT LISTENERS // // ===== // Keyevents // public void keyPressed(KeyEvent k){ // Make sure that we don't catch chattext actions if(k.toString().indexOf("chat") > -1){ //k.consume(); return; } if(global.PLAYBACK || global.freeze || global.dontwalk){k.consume();return;} if(global.State == global.RELOADING || global.State == global.CHANGE || global.State == global.LOADING){k.consume(); return;} if(global.PLAYERSTATE > 2) global.PLAYERSTATE=1; if(global.State < global.MENU1-1){ if(!global.keypressed){ global.keypressed=true; board(0,0,global.WIDTH,global.HEIGHT); // draw the board } k1=k.getKeyCode(); if(global.teamplay){k.consume(); return; } if(k1 == global.UP || k1 ==global. DOWN || k1 == global.LEFT || k1 == global.RIGHT){ for(int i=0;i -1 ){ // special commands if(chattext.getText().indexOf("!@!") > -1 ){ //System.out.println("Special action (debug?)"); }else{ if(debug)System.out.println("Add text to Chatstack!: "+chattext.getText()); hidden.requestFocus(); String chat_text=URLEncoder.encode(chattext.getText()); global.ChatStack.push("-10"+(char)17+chat_text+(char)17+global.room+(char)18); // clear chatline chattext.setText(""); } } if(ae.toString().indexOf("fieldlist") > -1){ String s=ae.getActionCommand(); if(debug)System.out.println("ActionCommand: "+s); String t=s.substring(s.indexOf("Level ")+6); if(debug)System.out.println("Level: "+t); ij=Integer.parseInt(t); if(debug)System.out.println("Level : "+ij); menu(false); first=false; // reset event-route global.slider=0; global.level=ij-1; fieldlist.select(global.level-1); global.State=global.CHANGE; } /* if(ae.toString().indexOf("singleplay") > -1 && global.teamplay){ global.all=4; // All users present global.showprogressionbar=true; // applet.setVisible(false); // applet.validate(); setVisible(false); applet.validate(); // Clear complete mp stack // Clear the multiplay arrows for(int ii=0; ii -1){ global.showprogressionbar=true; // Speed is dependent on the users preference global.isnetwork=true; // applet.setVisible(false); // applet.validate(); setVisible(false); applet.validate(); setSpeed(1,40,SPEED); menu(false); first=false; // reset event-route global.slider=0; if(!global.standalone){ global.turn=-23209; global.State=global.MENU_TEAM; }else{ // standalone global.level=999; global.teamplay=true; global.team=10000; // assume 10000 user global.room=1; // first room global.turn =-2; global.State=global.CHANGE; } } */ if(ae.toString().indexOf("fastest") > -1){ global.showprogressionbar=true; // applet.setVisible(false); // applet.validate(); setVisible(false); int B=52; int C=100; int D=80; int sizey=B; normal.setBounds((global.WIDTH*SIZE), D+(B*7), C, B); fastest.setBounds(0,0,1,1); applet.validate(); setSpeed(1,40,SPEED); storeextra(); global.freeze=false; } if(ae.toString().indexOf("levels") > -1){ System.out.println("Levels selected"); // avoid image display of arrow in first level global.keypressed=true; global.State=global.MENU_LEVELS; } if(ae.toString().indexOf("normal") > -1){ global.showprogressionbar=true; // applet.setVisible(false); // applet.validate(); setVisible(false); applet.validate(); int B=52; int sizey=B; int C=100; int D=80; fastest.setBounds((global.WIDTH*SIZE), D+(B*7), C, B); normal.setBounds(0,0,1,1); if(!global.standalone){ // setSpeed(8,5,SPEED); setSpeed(5,8,SPEED); } else{ // setSpeed(8,5,SPEED); setSpeed(5,8,SPEED); } storeextra(); escape(); global.freeze=false; } if(ae.toString().indexOf("escape") > -1 ){ escape(); } if(ae.toString().indexOf("undo") > -1 && undoplayerx > -1 && undolevel==global.level){ undo(); } if(ae.toString().indexOf("levelbackup") > -1 ){ backup(); } if(ae.toString().indexOf("allscores") > -1){ // viewscores(); // avoid image display of arrow in first level global.keypressed=true; global.State=global.MENU_SCORES; } if(ae.toString().indexOf("showit") > -1){ //? ShowIt(); } if(ae.toString().indexOf("levelrestore") > -1&& backupplayerx > -1 && global.level == backuplevel){ restore(); } if(ae.toString().indexOf("playsound") > -1){ if(!global.playsound){ playsound.setImage(imgnoplaysound); playsound.setHintImage(imghintnoplaysound); global.playsound=true; }else{ playsound.setImage(imgplaysound); playsound.setHintImage(imghintplaysound); global.playsound=false; } storeextra(); } if(ae.toString().indexOf("arrowright") > -1){ arrow=1; adi=imgrightsmall; // Check if we need to display help what we do with the // Arrow if(global.level==1000){ if(global.introstate==1){ global.introstate=2; right.setVisible(false); } } } if(ae.toString().indexOf("arrowleft") > -1){ arrow=2; adi=imgleftsmall; } if(ae.toString().indexOf("arrowup") > -1){ arrow=3; adi=imgupsmall; } if(ae.toString().indexOf("arrowdown") > -1){ arrow=4; adi=imgdownsmall; } if(ae.toString().indexOf("arrowblank") > -1){ arrow=0; adi=null; } // Reset during TEST // if(ae.toString().indexOf("thereset") > -1 && global.RState == global.TEST){ if(ae.toString().indexOf("thereset") > -1 ){ global.RState=0; global.introstate=100; right.setVisible(true); setVisible(false); applet.validate(); // if we are allready testing and want to re-start for(int ii=0; ii -1 && global.RState != global.AUTOMATEDRUN ){ global.introstate=100; right.setVisible(true); reset.setVisible(true); // reset active setVisible(false); applet.validate(); // if we are allready testing and want to re-start if(global.RState == global.TEST){ for(int ii=0; ii