Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- import java.awt.Image;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import javax.swing.ImageIcon;
- public class map
- {
- protected int[][] tileMap;
- protected int height;
- protected int width;
- private Image FLOOR;
- private Image WALL;
- private Image GOAL;
- public map(String mapFile)
- {
- FLOOR=new ImageIcon("sprites/floor.png").getImage();
- WALL=new ImageIcon("sprites/wall.png").getImage();
- GOAL=new ImageIcon("sprites/goal.png").getImage();
- try
- {
- BufferedReader br = new BufferedReader(new FileReader(mapFile));
- height=Integer.parseInt(br.readLine());
- width=Integer.parseInt(br.readLine());
- tileMap=new int[height][width];
- String line;
- for(int row=0;row<=height;row++)
- {
- line=br.readLine();
- String[] arLine=line.trim().split(" ");
- for(int col = 0; col<arLine.length; col++)
- {
- tileMap[row][col]=Integer.parseInt(arLine[col]);
- }
- }
- }
- catch(Exception e)
- {
- }
- }
- public void draw(Graphics g)
- {
- int ix;
- int iy=0;
- int col=0;
- for(int row=0;row<height;row++)
- {
- ix=0;
- for(col=0;col<width;col++)
- {
- if(tileMap[row][col]==0)
- {
- g.drawImage(FLOOR, ix, iy, null);
- ix=ix+48;
- }
- if(tileMap[row][col]==1)
- {
- g.drawImage(WALL, ix, iy, null);
- ix=ix+48;
- }
- if(tileMap[row][col]==2)
- {
- g.drawImage(FLOOR, ix, iy, null);
- ix=ix+48;
- }
- if(tileMap[row][col]==3)
- {
- g.drawImage(GOAL, ix, iy, null);
- ix=ix+48;
- }
- if(tileMap[row][col]==4)
- {
- g.drawImage(FLOOR, ix, iy, null);
- ix=ix+48;
- }
- if(tileMap[row][col]==5)
- {
- g.drawImage(FLOOR, ix, iy, null);
- ix=ix+48;
- }
- }
- if (col==width)
- {
- iy=iy+48;
- }
- }
- }
- public int findSpawny()
- {
- for(int i=0;i<height;i++)
- {
- for(int j=0;j<width;j++)
- {
- if(tileMap[i][j]==2)
- {
- return i;
- }
- }
- }
- return -1;
- }
- public int findSpawnx()
- {
- for(int i=0;i<height;i++)
- {
- for(int j=0;j<width;j++)
- {
- if(tileMap[i][j]==2)
- {
- return j;
- }
- }
- }
- return -1;
- }
- public int goalSpawny()
- {
- for(int i=0;i<height;i++)
- {
- for(int j=0;j<width;j++)
- {
- if(tileMap[i][j]==3)
- {
- return i;
- }
- }
- }
- return -1;
- }
- public int goalSpawnx()
- {
- for(int i=0;i<height;i++)
- {
- for(int j=0;j<width;j++)
- {
- if(tileMap[i][j]==3)
- {
- return j;
- }
- }
- }
- return -1;
- }
- public int enemySpawny()
- {
- for(int i=0;i<height;i++)
- {
- for(int j=0;j<width;j++)
- {
- if(tileMap[i][j]==4)
- {
- return i;
- }
- }
- }
- return -1;
- }
- public int enemySpawnx()
- {
- for(int i=0;i<height;i++)
- {
- for(int j=0;j<width;j++)
- {
- if(tileMap[i][j]==4)
- {
- return j;
- }
- }
- }
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement