Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (690)
Games in Android Showcase (201)
games submitted by our members
Games in WIP (764)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: Gibbo3771 (posted 2014-03-05 15:13:19, viewed 239 times)

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   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99   100   101   102   103   104   105   106   107   108   109   110   111   112   113   114   115   116   117   118   119   120   121   122   123   124   125   126   127   128   129   130   131   132   133   134   135   136   137   138   139   140   141   142   143   144   145  
private void initDoors() throws LevelLoaderException {
      /** Tile adjacent on the X axis */
      int adjacentX = 0;
      /** Tile adjacent the Y axis */
      int adjacentY = 0;
      /** Temporary door variable */
      Door door = null;
      /** Tile type for comparing against array */
      TileType type = null;

      

      /*
       * Iterate through array of tiles and get the doors and assign proper
       * hinges
       */
      for (Tile doors : Level.tiles) {
         switch (doors.getType()) {
         case DOOR:
            door = (Door) doors;
            adjacentX = (int) door.getPosition().x;
            adjacentY = (int) door.getPosition().y;
            /* Check left and right side of door for anchorable walls */
            for (int x = adjacentX - 1; x < adjacentX + 2; x += 2) {
               type = TileType.getType(cells[x][adjacentY]);
               switch (type) {
               case WALL:
                  for (int wall = 0; wall < Level.tiles.size; wall++) {
                     Tile tile = Level.tiles.get(wall);
                     if (tile.getType() == TileType.WALL) {
                        Vector2 anchorPos = tile.getBody()
                              .getPosition();
                        if ((!door.isHinged()) && anchorPos.x == x
                              && anchorPos.y == adjacentY) {
                           int xx = x < adjacentX ? -1 : 1;
                           door.connectedHinges(tile.getBody(),
                                 new Vector2(xx, 0)).setHinged(true);
                        }

                     }
                  }
               default:
                  break;
               }
            }
            /* Check bottom and top of door for anchorable walls */
            for (int y = adjacentY - 1; y < adjacentY + 2; y += 2) {
               type = TileType.getType(cells[adjacentX][y]);
               switch (type) {
               case WALL:
                  for (int wall = 0; wall < Level.tiles.size; wall++) {
                     Tile tile = Level.tiles.get(wall);
                     if (tile.getType() == TileType.WALL) {
                        Vector2 anchorPos = tile.getBody()
                              .getPosition();
                        if ((!door.isHinged()) && anchorPos.y == y
                              && anchorPos.x == adjacentX) {
                           int yy = y < adjacentY ? -1 : 1;
                           door.connectedHinges(tile.getBody(),
                                 new Vector2(0, yy)).setHinged(true);
                        }

                     }
                  }
               default:
                  break;
               }
            }
         default:
            break;
         }
      }
      /**
       * Group doors next to each other to have the same ID, used for
       * unlocking and the such
       */
      for (Tile doors : Level.tiles) {
         switch (doors.getType()) {
         case DOOR:
            door = (Door) doors;
            adjacentX = (int) door.getPosition().x;
            adjacentY = (int) door.getPosition().y;
            for (int x = adjacentX - 1; x < adjacentX + 2; x += 2) {
               type = TileType.getType(cells[x][adjacentY]);
               switch (type) {
               case DOOR:
                  for (int wall = 0; wall < Level.tiles.size; wall++) {
                     Tile tile = Level.tiles.get(wall);
                     if (tile.getType() == TileType.DOOR) {
                        Door doorAdjacent = (Door) tile;
                        Vector2 adjacentPos = doorAdjacent.getBody()
                              .getPosition();
                        /*
                         * Check if the adjacent tile coordinates match
                         * our door coordinates
                         */
                        if (adjacentPos.x == x
                              && adjacentPos.y == adjacentY) {
                           door.setDoorID(doorAdjacent.getDoorID());
                           Level.doors.put(door.getDoorID(), door);
                           Level.doors.put(doorAdjacent.getDoorID(),
                                 doorAdjacent);

                        }

                     }
                  }
                  break;

               default:
                  break;
               }

            }
            for (int y = adjacentY - 1; y < adjacentY + 2; y += 2) {
               type = TileType.getType(cells[adjacentX][y]);
               switch (type) {
               case DOOR:
                  for (int wall = 0; wall < Level.tiles.size; wall++) {
                     Tile tile = Level.tiles.get(wall);
                     if (tile.getType() == TileType.DOOR) {
                        Door doorAdjacent = (Door) tile;
                        Vector2 adjacentPos = doorAdjacent.getBody()
                              .getPosition();
                        if (adjacentPos.y == y
                              && adjacentPos.x == adjacentX) {
                           door.setDoorID(doorAdjacent.getDoorID());
                           Level.doors.put(door.getDoorID(), door);
                           Level.doors.put(doorAdjacent.getDoorID(),
                                 doorAdjacent);
                        }

                     }
                  }
               default:
                  break;
               }
            }
         default:
            break;

         }

      }
   }





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 
xTheGamerPlayz (218 views)
2016-09-26 21:26:27

Wave Propagation (417 views)
2016-09-20 13:29:55

steveyg90 (525 views)
2016-09-15 20:41:23

steveyg90 (520 views)
2016-09-15 20:13:52

steveyg90 (563 views)
2016-09-14 14:44:42

steveyg90 (586 views)
2016-09-14 14:42:13

theagentd (539 views)
2016-09-12 16:57:14

theagentd (466 views)
2016-09-12 14:18:31

theagentd (317 views)
2016-09-12 14:14:46

Nihilhis (750 views)
2016-09-01 13:36:54
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!