Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: Java  |  size: 1.24 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Override
  2.         public void render(GameContainer container, Graphics g) throws SlickException {
  3.                
  4.        
  5.                 int w = container.getWidth();
  6.                 int h = container.getHeight();
  7.  
  8.                
  9.                 // Fill the world Colours
  10.                 g.setColor(Color.darkGray);
  11.                 g.fillRect(0, 0, w, h);
  12.                
  13.                 // Push transform matrix
  14.                 g.pushTransform();
  15.                 // Work out the translation to center the world on screen and for zooming
  16.                 float center_x = (float) ((w/2) - (world.getWidth()  * zoom) /2);
  17.                 float center_y = (float) ((h/2) - (world.getHeight() * zoom) /2);
  18.                
  19.                 g.translate(center_x, center_y);
  20.                 g.scale(zoom, zoom);
  21.                
  22.                 g.translate(viewer_x, viewer_y);
  23.                
  24.                 g.pushTransform();
  25.                
  26.                 g.setColor(Color.black);
  27.                 g.setLineWidth(2);
  28.                
  29.                 float x = -(viewer_x + (center_x / zoom));
  30.                 float y = -(viewer_y + (center_y / zoom));
  31.                 float w2 = w /zoom ;
  32.                 float h2 = h /zoom;
  33.                
  34.                 world.drawClip.setBounds( x, y, w2, h2);
  35.  
  36.                 g.setWorldClip(x, y, w2, h2);
  37.                
  38.                 if (zoom < 0.8)
  39.                         world.disableRotation();
  40.                 else
  41.                         world.enableRotation();
  42.                
  43.                 world.draw(g);
  44.  
  45.                
  46.                 g.popTransform();
  47.                 g.popTransform();
  48.                
  49.                
  50.                
  51.                
  52.                 g.setColor(Color.magenta);
  53.                 g.drawString("Ant Arena", 10, 25);
  54.                
  55.                
  56.                 g.setColor(Color.magenta);
  57.                 g.drawString("Zoom: " + zoom, 10, 50);
  58.                
  59.         }