Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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 136 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
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (46 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (64 views)
2014-09-21 02:42:18

BurntPizza (36 views)
2014-09-21 01:30:30

moogie (42 views)
2014-09-21 00:26:15

UprightPath (51 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!