1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| import java.util.*; import java.awt.*;
public class MapDirector{ Maps M = new Maps(); Prey prey; ArrayList<Floor> floor = new ArrayList<Floor>(); ArrayList<Wall> wall = new ArrayList<Wall>(); ArrayList<Wall> wallT = new ArrayList<Wall>(); ArrayList<Exit> exit = new ArrayList<Exit>(); private short Maze1[][] = M.RandomMaze; private Random r = new Random(); public static boolean WIN = false; public MapDirector(){ M.GenerateMaze(r.nextInt(70) + 30); prey = new Prey(50,50,500,270); for(int y = 0;y < Maze1.length;y++){ for(int x = 0;x < Maze1[y].length;x++){ if(Maze1[y][x] == 0){floor.add(new Floor(x*50,y*46));} if(Maze1[y][x] == 1){wall.add(new Wall(x*50,y*46,1));wall.add(new Wall(x*50,y*46-4,1)); wall.add(new Wall(x*50,y*46-8,1));wallT.add(new Wall(x*50,y*46-12,1));} if(Maze1[y][x] == 2){floor.add(new Floor(x*50,y*46));} } } } public void WallCollision(Wall w){ Rectangle wall = new Rectangle(w.x,w.y,50,50); Rectangle U = new Rectangle(Prey.x + 20,Prey.y + 10,13,5); Rectangle D = new Rectangle(Prey.x + 20,Prey.y + 20,13,5); Rectangle L = new Rectangle(Prey.x + 17,Prey.y + 20,5,5); Rectangle R = new Rectangle(Prey.x + 30,Prey.y + 20,5,5); if(U.intersects(wall)){Prey.y += 2;Prey.gy -= 2;} else if(D.intersects(wall)){Prey.y -= 2;Prey.gy += 2;} else if(L.intersects(wall)){Prey.x += 2;Prey.gx -= 2;} else if(R.intersects(wall)){Prey.x -= 2;Prey.gx += 2;} } public void Exit(Exit e){ Rectangle exit = new Rectangle(e.x,e.y,50,50); Rectangle PREY = new Rectangle(Prey.x,Prey.y,50,50); if(PREY.intersects(exit)){WIN = true;} } public void paint(Graphics g,Graphics2D g2d){ g2d = (Graphics2D) g; g2d.translate(Prey.gx,Prey.gy); for(Floor f : floor){g2d.drawImage(Floor.floor,f.x,f.y,50,50,null);} for(Wall w : wall){g2d.drawImage(Wall.wall,w.x,w.y,50,50,null);} prey.paint(g,g2d); for(Wall w : wallT){g2d.drawImage(Wall.wall,w.x,w.y,50,50,null);} } } |