Guest User

Screen.java

a guest
Mar 21st, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package com.doamax.game.graphics;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.doamax.game.level.tile.Tile;
  6.  
  7. public class Screen {
  8.  
  9.     public int width, height;
  10.     public int[] pixels;
  11.     public final int MAP_SIZE = 8;
  12.     public final int MAP_SIZE_MASK = MAP_SIZE - 1;
  13.     public int[] tiles = new int[MAP_SIZE * MAP_SIZE];
  14.    
  15.     public int xOffset, yOffset;
  16.    
  17.     private Random random = new Random();
  18.    
  19.     public Screen(int width, int height){
  20.         this.width = width;
  21.         this.height = height;
  22.         pixels = new int[width * height];
  23.        
  24.         for (int i = 0; i < 8 * 8; i++){
  25.             tiles[i] = random.nextInt(0xffffff);
  26.         }
  27.     }
  28.    
  29.     public void clear(){
  30.         for(int i = 0; i < pixels.length; i++){
  31.             pixels[i] = 0;
  32.         }
  33.     }
  34.    
  35.     public void renderTile(int xp, int yp, Tile tile){
  36.         xp -= xOffset;
  37.         yp -= yOffset;
  38.         for (int y = 0; y < tile.sprite.SIZE; y++){
  39.             int ya = y + yp;
  40.             for (int x = 0; x < tile.sprite.SIZE; x++){
  41.                 int xa = x + xp;
  42.                 if(xa < 0 || xa >= width || ya < 0 || ya >= width) break;
  43.                 pixels[xa + ya * width] = tile.sprite.pixels[x + y * tile.sprite.SIZE];
  44.             }
  45.         }
  46.     }
  47.    
  48.     public void setOffset(int xOffset, int yOffset) {
  49.         this.xOffset = xOffset;
  50.         this.yOffset = yOffset;
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment