Class Grid


public class Grid extends World
Grid Class - Used for rectangular-tiled games A 2D array of GridTiles which can be marked Subclass of World that can show all Images & Sprites
  • Constructor Details

    • Grid

      public Grid(processing.core.PApplet p)
      Grid Constructor #1: Default constructor that creates a 3x3 Grid
      Parameters:
      p - Processing applet
    • Grid

      public Grid(processing.core.PApplet p, int rows, int cols)
      Grid Construtor #2: Only accepts the number of rows & columns (Default for 2023)
      Parameters:
      p - Processing applet
      rows -
      cols -
    • Grid

      public Grid(processing.core.PApplet p, String screenName, processing.core.PImage bgImg, int rows, int cols)
      Grid constructor #3: Sets background image + rows & cols
      Parameters:
      p - Processing applet
      screenName - String to track Screens
      bgImg - stationary background image
      rows -
      cols -
    • Grid

      public Grid(processing.core.PApplet p, String screenName, processing.core.PImage bgImg, String[][] tileMarks, int rows, int cols)
      Grid constructor #4: Takeas in 2D String array parameter to set tile marks
      Parameters:
      p - Processing applet
      screenName - String to track Screens
      bgImg - stationary background image
      tileMarks -
      rows -
      cols -
  • Method Details

    • setMark

      public void setMark(String mark, GridLocation loc)
      Assigns a String mark to a location in the Grid. This mark is not necessarily visible, but can help in tracking what you want recorded at each GridLocation.
      Parameters:
      mark -
      loc - GridLocation for a specific GridTile
    • getMark

      public String getMark(GridLocation loc)
      Gets the mark value at a location
      Parameters:
      loc - GridLocation for a specific GridTile
      Returns:
      String
    • removeMark

      public boolean removeMark(GridLocation loc)
      Gets the mark value at a location
      Parameters:
      loc - GridLocation for a specific GridTile
      Returns:
      boolean
    • hasMark

      public boolean hasMark(GridLocation loc)
      Checks if a location has a mark
      Parameters:
      loc - GridLocation for a specific GridTile
      Returns:
      boolean
    • setNewMark

      public boolean setNewMark(String mark, GridLocation loc)
      Assigns a String mark to a location in the Grid. This mark is not necessarily visible, but can help in tracking what you want recorded at each GridLocation.
      Parameters:
      mark -
      loc -
      Returns:
      boolean true if mark is correctly set (no previous mark), false otherwise
    • printGrid

      public void printGrid()
      Prints out the marks in the Grid to the console
    • startPrintingGridMarks

      public void startPrintingGridMarks()
      If Grid mark system is used, shows all marks in the Grid in the console
    • stopPrintingGridMarks

      public void stopPrintingGridMarks()
      Turns off Grid mark system from printing all marks in the Grid in the console
    • setAllMarks

      public void setAllMarks(String[][] tileMarks)
      Sets the marks for an entire grid from a 2D String array tileMarks MUST match the same number of rows & columns as the grid
      Parameters:
      tileMarks -
    • getGridLocation

      public GridLocation getGridLocation()
      Returns:
      GridLocation where the mouse is currently hovering over
    • getX

      public int getX(GridLocation loc)
      Provides the x-pixel value given a GridLocation loc
      Parameters:
      loc - GridLocation to check
      Returns:
      int x-pixel value
    • getX

      public int getX(int row, int col)
      Parameters:
      row - row of a specific GridTile
      col - column of a specific GridTile
      Returns:
      int x-value of left edge of a GridTile
    • getCenterX

      public int getCenterX(GridLocation loc)
      Parameters:
      loc - GridLocation for a specific GridTile
      Returns:
      int x-value of center pixel of the GridLocation
    • getY

      public int getY(GridLocation loc)
      Parameters:
      loc - GridLocation for a specific GridTile
      Returns:
      int y-value of top pixel of a GridLocation
    • getY

      public int getY(int row, int col)
      Parameters:
      row - row of a specific GridTile
      col - column of a specific GridTile
      Returns:
      int y-value of left edge of a GridTile
    • getCenterY

      public int getCenterY(GridLocation loc)
      Parameters:
      loc - GridLocation for a specific GridTile
      Returns:
      int y-value of center pixel of the GridLocation
    • getNumRows

      public int getNumRows()
      Accessor method
      Returns:
      int number of rows in the Grid
    • getNumCols

      public int getNumCols()
      Accessor method
      Returns:
      int number of cols in the Grid
    • getTileWidth

      public int getTileWidth()
      Accessor method
      Returns:
      int width of 1 Tile in the Grid
    • getTileHeight

      public int getTileHeight()
      Accessor method
      Returns:
      int height of 1 Tile in the Grid
    • getTile

      public GridTile getTile(GridLocation loc)
      Returns the GridTile object stored at a specified GridLocation
      Parameters:
      loc - GridLocation for a specific GridTile
      Returns:
      GridTile
    • getTile

      public GridTile getTile(int row, int col)
      Parameters:
      row - row of a specific GridTile
      col - column of a specific GridTile
      Returns:
      GridTile GridTile object stored at a specified row and column
    • setTileImage

      public void setTileImage(GridLocation loc, processing.core.PImage img)
      Sets the image at a particular tile in the grid & displays it
      Parameters:
      loc - GridLocation for a specific GridTile
      img -
    • getTileImage

      public processing.core.PImage getTileImage(GridLocation loc)
      Returns the PImage associated with a particular GridTile
      Parameters:
      loc - GridLocation for a specific GridTile
      Returns:
      PImage
    • hasTileImage

      public boolean hasTileImage(GridLocation loc)
      Parameters:
      loc - GridLocation for a specifc GridTile
      Returns:
      boolean true if the GridTile has a PImage, false otherwise
    • clearTileImage

      public void clearTileImage(GridLocation loc)
      Clears the tile image
      Parameters:
      loc - GridLocation for a specific GridTile
    • showTileImage

      public void showTileImage(GridLocation loc)
      Displays the PImage at a specific location
      Parameters:
      loc - GridLocation for a specific GridTile
    • showGridImages

      public void showGridImages()
      Displays the PImages stored in ALL the GridTiles
    • showImages

      @Deprecated public void showImages()
      Deprecated.
    • show

      public void show()
      Displays all World + Screen + Grid visuals
      Overrides:
      show in class World
    • setTileSprite

      public void setTileSprite(GridLocation loc, Sprite sprite)
      Sets the Sprite at a particular tile in the grid & displays it
      Parameters:
      loc - GridLocation to change
      sprite - new Sprite to add to tile
    • getTileSprite

      public Sprite getTileSprite(GridLocation loc)
      Gets the Sprite from a specific GridTile
      Parameters:
      loc - GridLocation for a specific GridTile
      Returns:
      Sprite Sprite associated with a particular Tile
    • hasTileSprite

      public boolean hasTileSprite(GridLocation loc)
      Checks if a Tile has a PImage
      Parameters:
      loc - GridLocation for a specific GridTile
      Returns:
      boolean true if the GridTile has a stored image, false otherwise
    • clearTileSprite

      public void clearTileSprite(GridLocation loc)
      Clears the image from a particular tile
      Parameters:
      loc - GridLocation for a specific GridTile
    • animateTileSprite

      public void animateTileSprite(GridLocation loc)
      Checks for an AnimatedSprite and animates it
      Parameters:
      loc - GridLocation for a specific GridTile
    • showTileSprite

      public void showTileSprite(GridLocation loc)
      Displays the Sprite on a single GridTile
      Parameters:
      loc - GridLocation for a specific GridTile
    • showGridSprites

      public void showGridSprites()
      Displays ALL the Sprites stored in the Grid
    • clearGrid

      public void clearGrid()
      Clears the screen from all Images & Sprites