Advertisement
Guest User

Untitled

a guest
Jul 31st, 2012
51
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None
  1. OUTPUT: http://i.imgur.com/jv5xR.png
  2.  
  3. import org.lwjgl.opengl.GL11;
  4. import org.newdawn.slick.opengl.Texture;
  5.  
  6. abstract class Block {
  7.     private Texture texture;
  8.    
  9.     protected int x;
  10.     protected int y;
  11.    
  12.     protected BlockType type;
  13.    
  14.     private static int blockWidth = 25;
  15.     private static int blockHeight = 25;
  16.    
  17.     public void setTexture(Texture tex) {
  18.         this.texture = tex;
  19.     }
  20.    
  21.     public void draw() {
  22.         texture.bind();
  23.  
  24.         int realX = x * blockWidth;
  25.         int realY = y * blockHeight;
  26.        
  27.         int textureW = blockWidth;
  28.         int textureH = blockHeight;
  29.        
  30.         GL11.glBegin(GL11.GL_QUADS);
  31.             GL11.glTexCoord2f(0, 0);
  32.             GL11.glVertex2f(realX, realY);
  33.            
  34.             GL11.glTexCoord2f(1, 0);
  35.             GL11.glVertex2f(realX + textureW, realY);
  36.            
  37.             GL11.glTexCoord2f(1, 1);
  38.             GL11.glVertex2f(realX + textureW, realY + textureH);
  39.            
  40.             GL11.glTexCoord2f(0, 1);
  41.             GL11.glVertex2f(realX, realY + textureH);
  42.         GL11.glEnd();
  43.     }
  44.    
  45. }
Advertisement
RAW Paste Data Copied
Advertisement