Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package yuriah.map;
- import java.awt.Color;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import javax.swing.ImageIcon;
- public class Map {
- public static Image wall;
- public static Image ground;
- private static final int OPEN = 0;
- private static final int BLOCKED = 1;
- private static final int WIDTH = 23;
- private static final int HEIGHT = 16;
- public static final int TILE_SIZE = 30;
- public static int[][] map = new int[WIDTH][HEIGHT];
- MapLoader mapl;
- public Map() {
- mapl = new MapLoader();
- for (int x = 0; x < 23; x++) {
- //map[x][0] = BLOCKED;
- map[x][15] = BLOCKED;
- }
- for (int y = 0; y < 16; y++) {
- //map[0][y] = BLOCKED;
- //map[22][y] = BLOCKED;
- map[2][y] = BLOCKED;
- }
- map[2][7] = OPEN;
- }
- public void paint(Graphics2D g) {
- wall = new ImageIcon(getClass().getResource("wall.png")).getImage();
- ground = new ImageIcon(getClass().getResource("ground.png")).getImage();
- Image image = null;
- for (int x = 0; x < WIDTH; x++) {
- for (int y = 0; y < HEIGHT; y++) {
- g.setColor(Color.darkGray);
- if (map[x][y] == BLOCKED) {
- image = wall;
- g.setColor(Color.gray);
- } else if (map[x][y] == OPEN) {
- image = ground;
- }
- g.drawImage(image, x * TILE_SIZE, y * TILE_SIZE, null);
- //g.fillRect(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
- //g.setColor(g.getColor().darker());
- //g.drawRect(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
- }
- }
- }
- public boolean blocked(float x, float y) {
- return map[(int) x][(int) y] == BLOCKED;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement