Advertisement
Guest User

Untitled

a guest
Jun 25th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. package yuriah.map;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics2D;
  5. import java.awt.Image;
  6.  
  7. import javax.swing.ImageIcon;
  8.  
  9. public class Map {
  10.  
  11. public static Image wall;
  12.  
  13. public static Image ground;
  14.  
  15. private static final int OPEN = 0;
  16.  
  17. private static final int BLOCKED = 1;
  18.  
  19. private static final int WIDTH = 23;
  20.  
  21. private static final int HEIGHT = 16;
  22.  
  23. public static final int TILE_SIZE = 30;
  24.  
  25. public static int[][] map = new int[WIDTH][HEIGHT];
  26.  
  27. MapLoader mapl;
  28.  
  29. public Map() {
  30. mapl = new MapLoader();
  31.  
  32. for (int x = 0; x < 23; x++) {
  33. //map[x][0] = BLOCKED;
  34. map[x][15] = BLOCKED;
  35.  
  36.  
  37. }
  38.  
  39. for (int y = 0; y < 16; y++) {
  40. //map[0][y] = BLOCKED;
  41. //map[22][y] = BLOCKED;
  42. map[2][y] = BLOCKED;
  43.  
  44. }
  45.  
  46. map[2][7] = OPEN;
  47. }
  48.  
  49. public void paint(Graphics2D g) {
  50. wall = new ImageIcon(getClass().getResource("wall.png")).getImage();
  51. ground = new ImageIcon(getClass().getResource("ground.png")).getImage();
  52. Image image = null;
  53. for (int x = 0; x < WIDTH; x++) {
  54. for (int y = 0; y < HEIGHT; y++) {
  55. g.setColor(Color.darkGray);
  56. if (map[x][y] == BLOCKED) {
  57. image = wall;
  58. g.setColor(Color.gray);
  59. } else if (map[x][y] == OPEN) {
  60. image = ground;
  61. }
  62.  
  63. g.drawImage(image, x * TILE_SIZE, y * TILE_SIZE, null);
  64. //g.fillRect(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
  65. //g.setColor(g.getColor().darker());
  66. //g.drawRect(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
  67. }
  68. }
  69. }
  70.  
  71. public boolean blocked(float x, float y) {
  72. return map[(int) x][(int) y] == BLOCKED;
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement