Esempio n. 1
0
 /**
  * check if human collides with a ghost
  *
  * @param game
  * @return the ghost where the human collides with
  */
 public Ghost checkGhostCollision(Game game) {
   // ghost collision
   for (Ghost ghost : game.getGhosts()) {
     if (!ghost.getRip() && !ghost.getDead()) {
       if (checkHitboxCollision(this.getPosition(), 90, 90, ghost.getPosition(), 90, 90)) {
         return ghost;
       }
     }
   }
   return null;
 }
Esempio n. 2
0
 public void update(List<Point> ghostPositions) {
   for (int i = 0; i < ghosts.size(); ++i) {
     Ghost ghost = ghosts.get(i);
     Cell currentCell = getCell(ghost.getPosition());
     Cell newCell = getCell(ghostPositions.get(i));
     if (!currentCell.equals(newCell)) {
       grid.get(currentCell.row).get(currentCell.column).remove(ghost);
       grid.get(newCell.row).get(newCell.column).add(ghost);
     }
   }
 }
Esempio n. 3
0
  private void build(List<Ghost> ghosts) {
    grid = new ArrayList<List<List<Ghost>>>();
    for (int i = 0; i < nRows; ++i) {
      List<List<Ghost>> columns = new ArrayList<List<Ghost>>();
      for (int j = 0; j < nColumns; ++j) {
        columns.add(new LinkedList<Ghost>());
      }
      grid.add(columns);
    }

    for (Ghost ghost : ghosts) {
      Cell c = getCell(ghost.getPosition());
      grid.get(c.row).get(c.column).add(ghost);
    }
  }