Package com.hobbitsadventure.model

Examples of com.hobbitsadventure.model.RealmMap


    paintTiles(g);
    paintThingsAndCharacters(g);
  }
 
  private void paintTiles(Graphics g) {
    RealmMap realmMap = gameState.getRealmMap();
    int numRows = realmMap.getNumRows();
    int numCols = realmMap.getNumCols();
    int playerRow = gameState.getPlayerRow();
    int playerCol = gameState.getPlayerCol();
   
    int minI = playerRow - SIGHT_RADIUS;
    int maxI = playerRow + SIGHT_RADIUS;
    int minJ = playerCol - SIGHT_RADIUS;
    int maxJ = playerCol + SIGHT_RADIUS;
   
    for (int i = minI; i <= maxI; i++) {
      int rowIndex = (numRows + i) % numRows;
      int baseY = (i - minI) * TILE_HEIGHT;
      for (int j = minJ; j <= maxJ; j++) {
        int colIndex = (numCols + j) % numCols;
       
        // Paint tile
        Tile tile = realmMap.getTile(rowIndex, colIndex);
        int x = (j - minJ) * TILE_WIDTH;
        tile.paint(g, x, baseY);
       
        // Paint thing if it's occluded by subsequent tile roles
        Thing thing = realmMap.getThing(rowIndex, colIndex);
        if (thing != null && thing.isOccludedByTerrain()) {
          int y = baseY - 65 + tile.getHeight();
          g.drawImage(thing.getSprite(), x, y, null);
        }
      }
View Full Code Here


      }
    }
  }
 
  private void paintThingsAndCharacters(Graphics g) {
    RealmMap realmMap = gameState.getRealmMap();
    int numRows = realmMap.getNumRows();
    int numCols = realmMap.getNumCols();
    int playerRow = gameState.getPlayerRow();
    int playerCol = gameState.getPlayerCol();
   
    int minI = playerRow - SIGHT_RADIUS;
    int maxI = playerRow + SIGHT_RADIUS;
    int minJ = playerCol - SIGHT_RADIUS;
    int maxJ = playerCol + SIGHT_RADIUS;
   
    for (int i = minI; i <= maxI; i++) {
      int rowIndex = (numRows + i) % numRows;
      int baseY = (i - minI) * TILE_HEIGHT;
      for (int j = minJ; j <= maxJ; j++) {
        int colIndex = (numCols + j) % numCols;
        Tile tile = realmMap.getTile(rowIndex, colIndex);
        int x = (j - minJ) * TILE_WIDTH;
        int y = baseY - 65 + tile.getHeight();
       
        // Paint thing (if we haven't already)
        Thing thing = realmMap.getThing(rowIndex, colIndex);
        if (thing != null && !thing.isOccludedByTerrain()) {
          g.drawImage(thing.getSprite(), x, y, null);
         
        }
       
        // Paint character
        GameCharacter character = realmMap.getCharacter(rowIndex, colIndex);
        if (character != null) {
          if (thing != null) { y += thing.getYOffset(); }
          g.drawImage(character.getSprite(), x, y, null);
        }
      }
View Full Code Here

      rowList.add(row);
    }
   
    int numRows = rowList.size();
    int numCols = rowList.get(0).length;
    RealmMap realmMap = new RealmMap(numRows, numCols);
    for (int i = 0; i < numRows; i++) {
      for (int j = 0; j < numCols; j++) {
        RealmCell cell = rowList.get(i)[j];
        realmMap.setCell(i, j, cell);
       
        // Add a little more interest to the height map. This is just temporary.
//        double distance = Math.sqrt(((30 - i) * (30 - i)) + ((30 - j) * (30 - j)));
//        int offset = (int) Math.min(distance - 20.0, 0) * 5;
//        Tile tile = cell.getTile();
//        tile.setHeight(tile.getHeight() + offset);
      }
    }
   
   
    // FIXME Not sure we should re-read all the NPCs when reloading the map. Maybe they should have an existence
    // outside the map. Also the NPCs need to maintain their own positions as well (for movement), and updates need
    // to be synchronized with the object map. Maybe there is a better way to do it but that's what I have in mind
    // for now.
    realmMap.setCharacter(30, 25, new NonPlayerCharacter(NpcClasses.BUG));
    realmMap.setCharacter(28, 22, new NonPlayerCharacter(NpcClasses.PRINCESS));
    realmMap.setCharacter(10, 10, new NonPlayerCharacter(NpcClasses.CAT_GIRL));
    realmMap.setCharacter(20, 20, new NonPlayerCharacter(NpcClasses.HORN_GIRL));
    realmMap.setCharacter(40, 40, new NonPlayerCharacter(NpcClasses.PINK_GIRL));
   
    return realmMap;
  }
View Full Code Here

TOP

Related Classes of com.hobbitsadventure.model.RealmMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.