Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. public class GamePane extends GridPane{
  2.  
  3. Scene scene = Game.scene;
  4. private int rowAmount;
  5. private int columnAmount;
  6. char[][] charArray = new char[11][11];
  7. Input input = new Input(scene);
  8.  
  9.  
  10.  
  11. public GamePane(int rowAmount, int columnAmount, Input input){
  12.  
  13. charArray = MapReader.parsedChars();
  14. this.columnAmount = columnAmount;
  15. this.rowAmount = rowAmount;
  16. this.input = input;
  17.  
  18.  
  19. ColumnConstraints columnn;
  20. RowConstraints row;
  21.  
  22. GridPane gameGrid = new GridPane();
  23.  
  24.  
  25. for (int i = 0; i < columnAmount; i++) {
  26. columnn = new ColumnConstraints(45);
  27. gameGrid.getColumnConstraints().add(columnn);
  28. gameGrid.setStyle("-fx-background-color: white; -fx-grid-lines-visible:true");
  29.  
  30. }
  31.  
  32. for (int i = 0; i < rowAmount; i++) {
  33.  
  34. row = new RowConstraints(45);
  35. gameGrid.getRowConstraints().add(row);
  36. }
  37.  
  38.  
  39. for (int countCols = 0; countCols < rowAmount; countCols++) {
  40. for (int countRows = 0; countRows < columnAmount; countRows++) {
  41. Pane cellPane = new Pane();
  42. ;
  43. cellPane.setMaxSize(50,50);
  44. cellPane.setMinSize(50, 50);
  45. cellPane.setStyle("fx-grid-lines-visible:true");
  46.  
  47. this.add(cellPane, countCols, countRows);
  48.  
  49.  
  50.  
  51. if (charArray[countCols][countRows] == '#') {
  52.  
  53. ;
  54.  
  55.  
  56. Image wallImage = new Image(getClass().getResource("Wall.png").toExternalForm());
  57. //input.addListeners();
  58.  
  59.  
  60. this.add(new Wall(cellPane, wallImage, 0, 0, 0, 0, input), countCols, countRows);
  61. this.add(Game.walls, countRows, countRows);
  62. }
  63.  
  64.  
  65. public static boolean checkWallCollisions(){
  66.  
  67. boolean wallCollision = false;
  68.  
  69.  
  70. for(Player player: players){
  71. for(Wall wall: walls){
  72. if(player.collidesWith(wall) && Player.canMove == true){
  73. //System.out.println("Player collided with wall");
  74.  
  75. player.setDy(-player.getDy());
  76. player.setDx(-player.getDx());
  77. //Player.canMove = false;
  78.  
  79. player.move();
  80.  
  81. //Wall.collision = true;
  82.  
  83. }
  84.  
  85. }
  86.  
  87. }
  88. return wallCollision;
  89.  
  90. }
  91.  
  92.  
  93.  
  94.  
  95. }
  96. }
  97. }
  98.  
  99. public void addListeners(Scene scene) {
  100.  
  101. scene.addEventFilter(KeyEvent.KEY_PRESSED, keyPressedEventHandler);
  102. scene.addEventFilter(KeyEvent.KEY_RELEASED, keyReleasedEventHandler);
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement