Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tk.sketchistgames.graphics;
- import java.util.Random;
- import tk.sketchistgames.level.tile.Tile;
- public class Screen {
- private int width, height;
- public int[] pixels;
- public final int MAP_SIZE = 64;
- public final int MAP_SIZE_MASK = MAP_SIZE - 1;
- public int[] tiles = new int[MAP_SIZE * MAP_SIZE];
- public int xOffset, yOffset;
- private Random random = new Random();
- public Screen(int width, int height) {
- this.setWidth(width);
- this.setHeight(height);
- pixels = new int[width * height]; // 50,400 integers in array
- }
- public void clear() {
- for (int i = 0; i < pixels.length; i++) {
- pixels[i] = 0;
- }
- }
- public void renderTile(int xp, int yp, Tile tile) {
- xp -= xOffset;
- yp -= yOffset;
- for (int y = 0; y < tile.sprite.SIZE; y++) {
- int ya = y + yp;
- for (int x = 0; x < tile.sprite.SIZE; x++) {
- int xa = x + xp;
- if (xa < 0 || xa >= getWidth() || ya < 0 || ya >= getHeight()) {
- pixels[xa + (ya * getWidth())] = tile.sprite.pixels[x + y * tile.sprite.SIZE];
- }
- }
- }
- }
- public void setOffset(int xOffset, int yOffset){
- this.xOffset = xOffset;
- this.yOffset = yOffset;
- }
- public int getWidth() {
- return width;
- }
- public void setWidth(int width) {
- this.width = width;
- }
- public int getHeight() {
- return height;
- }
- public void setHeight(int height) {
- this.height = height;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement