Package com.pointcliki.grid

Examples of com.pointcliki.grid.GridCoordinate


    calculateTile();
    gridManager().addObject(fTile, this);
  }
 
  protected void calculateTile() {
    fTile = new GridCoordinate((int) Math.floor((fPosition.x - 16f) / 32f), (int) Math.floor((fPosition.y - 16f) / 32f));
  }
View Full Code Here


      addChild(new TileLayer(this, i).position(fOffset), i * 100);
    }
  }
 
  public GridCoordinate tileAtPoint(Vector2f v) {
    return new GridCoordinate((int) Math.floor((v.x - fOffset.x) / 32), (int) Math.floor((v.y - fOffset.y) / 32));
  }
View Full Code Here

  }
 
  @Override
  public MapEntity resize(Vector2f span) {
    super.resize(span);
    fGridSpan = new GridCoordinate(((int) Math.ceil(span.x / 32f)) + 1, ((int) Math.ceil(span.y / 32f)) + 1);
    return this;
  }
View Full Code Here

    Collections.reverse(path);
   
    // Perform diagonal optimization
    for (int i = 0; i < path.size() - 1; i++) {
      // Can only optimize straight paths so ignore diagonal ones
      GridCoordinate lineDir = path.get(i + 1).subtract(path.get(i));
      if (lineDir.isDiagonal()) continue;
      // Look ahead for the last diagonal in the next run of diagonals
      boolean inRun = false;
      boolean found = false;
      int j = i + 1;
      GridCoordinate diagDir = null;
      while (j < path.size() - 1) {
        GridCoordinate jDir = path.get(j + 1).subtract(path.get(j));
        // Start following a diagonal run
        if (jDir.isDiagonal() && !inRun) {
          inRun = true;
          found = true;
          diagDir = jDir;
          // Ensure we can go diagonally from i
          if (!diagMove(path.get(i), diagDir)) {
            found = false;
            break;
          }
        // Stop following a diagonal run
        } else if (inRun && !jDir.equals(diagDir)) {
          break;
        // Only go in straight lines
        } else if ((jDir.isDiagonal() && !jDir.equals(diagDir)) || (!jDir.isDiagonal() && !jDir.equals(lineDir))) {
          found = false;
          break;
        }
        j++;
      }
      // If a possible optimization has been found
      if (found) {
        // Get distance
        GridCoordinate dist = path.get(j).subtract(path.get(i));
        // Get perpendicular and parallel distance
        int u;  // Perpendicular
        int v;  // Parallel
        if (Math.abs(lineDir.x()) == 1) {
          u = Math.abs(dist.y());
          v = Math.abs(dist.x());
        } else {
          u = Math.abs(dist.x());
          v = Math.abs(dist.y());
        }
        ArrayList<GridCoordinate> segment = new ArrayList<GridCoordinate>();
        // Found
        boolean segFound = true;
        // Iterate over columns to find an optimal path segment
        for (int m = u; m > 0; m--) {
          GridCoordinate tile = path.get(i).add(diagDir);
          // Try to draw a better path
          segment.clear();
          segFound = true;
          // Iterate over rows
          for (int n = 1; n < v + m - u; n++) {
            if (!fMap.isValid(tile) || !passable(tile)) {
              segFound = false;
              break;
            }
            segment.add(tile);
            if (n < m) {
              // Ensure that we can move diagonally
              if (!diagMove(tile, diagDir)) {
                segFound = false;
                break;
              }
              tile = tile.add(diagDir);
            }
            else tile = tile.add(lineDir);
          }
          if (segFound) break;
          // Reduce j, the possible end point
          j--;
        }
View Full Code Here

    if (g != null && g.state() != GruntState.MOVING) return false;
    return true;
  }
 
  protected boolean diagMove(GridCoordinate tile, GridCoordinate diagDir) {
    GridCoordinate a = tile.add(new GridCoordinate(diagDir.x(), 0));
    GridCoordinate b = tile.add(new GridCoordinate(0, diagDir.y()));
    return !fMap.traits(a).contains("solid") && !fMap.traits(b).contains("solid");
  }
View Full Code Here

       */
      private static final long serialVersionUID = -339957012805410993L;

      @Override
      public void run(RollingBall ball, long currentFrame) {
        GridCoordinate xy = ball.getTile();
       
        squashGrunt(gridManager().getFirstEntityOfTypeAt(xy, Grunt.class),xy);
       
        for (String s: GridCoordinate.COMPASS)
          squashGrunt(gridManager().getFirstEntityOfTypeAt(xy.add(GridCoordinate.fromString(s)), Grunt.class), xy);
       
        for (String s: GridCoordinate.DIAGONAL_COMPASS)
          squashGrunt(gridManager().getFirstEntityOfTypeAt(xy.add(GridCoordinate.fromString(s)), Grunt.class), xy);
      }
     
      public void squashGrunt(Grunt g, GridCoordinate xy) {
        if (g == null) return;
        Rectangle r = new Rectangle(Grunt.COLLISION_RECT.getX() - (fPosition.x - g.position().x), Grunt.COLLISION_RECT.getY() - (fPosition.y - g.position().y), Grunt.COLLISION_RECT.getWidth(), Grunt.COLLISION_RECT.getHeight());
View Full Code Here

   
    fMapViewer.dispatcher().addMinion("mouse.down", new Minion<IEvent>() {
      @Override
      public long run(Dispatcher<IEvent> dispatcher, String type, IEvent event) {
        if (event instanceof MouseEvent && fSideContainer instanceof TilesSideBar) {
          GridCoordinate g = fMapViewer.tileAtPoint(new Vector2f(((MouseEvent)event).x(), ((MouseEvent)event).y() - 28));
          TilesSideBar side = (TilesSideBar) fSideContainer;
          fMapViewer.map().tile(side.tileset(), g.x(), g.y(), side.selected());
        }
        if (fAniCursor != null) {
          if (((MouseEvent) event).button() == 1) setEditingLogic(null);
          else ((ObjectSideBar) fSideContainer).placeLogic(new Vector2f(((MouseEvent) event).x() - fMapViewer.offset().x, ((MouseEvent) event).y() - fMapViewer.offset().y - 28));
        }
        return Minion.CONTINUE;
      }
    });
   
    fMapViewer.dispatcher().addMinion("mouse.drag", new Minion<IEvent>() {
      @Override
      public long run(Dispatcher<IEvent> dispatcher, String type, IEvent event) {
        if (event instanceof MouseEvent && fSideContainer instanceof TilesSideBar) {
          GridCoordinate g = fMapViewer.tileAtPoint(new Vector2f(((MouseEvent)event).x(), ((MouseEvent)event).y() - 28));
          TilesSideBar side = (TilesSideBar) fSideContainer;
          fMapViewer.map().tile(side.tileset(), g.x(), g.y(), side.selected());
          fCursor.position(fMapViewer.positionOfTile(g).add(new Vector2f(0, 28)));
        }
        return Minion.CONTINUE;
      }
    });
View Full Code Here

  protected boolean fSelected;
  protected boolean fSnapToGrid = false;
 
  @Override
  protected void calculateTile() {
    fTile = new GridCoordinate((int) Math.floor((fPosition.x + 1) / 32f), (int) Math.floor((fPosition.y + 1) / 32f));
  }
View Full Code Here

  @Override
  public void handleUIMouseEvent(String type, Vector2f local, MouseEvent event) {
    super.handleUIMouseEvent(type, local, event);
    // Move
    if (type.equals("mouse.down") && !fMapEntity.map().editing()) {
      scene(LevelScene.class).human().click(new GridCoordinate((int) (local.x / 32f), (int) (local.y / 32f)), event.button());
    }
    if (fMapEntity.map().editing() && type.equals("mouse.down") && event.button() == 1) for (Logic l: fMapEntity.map().selectedLogics()) fMapEntity.map().deselectLogic(l);
  }
View Full Code Here

    }
    return true;
  }

  protected void followPath() {
    GridCoordinate xy = fPath.get(fPathIndex);
    fPathIndex++;
   
    xy = xy.subtract(fGrunt.getTile());
    fGrunt.animate("WALK", "WALK", xy);
    fGrunt.movement().move(xy);
    fGrunt.state(GruntState.MOVING);
  }
View Full Code Here

TOP

Related Classes of com.pointcliki.grid.GridCoordinate

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.