Class Grid
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 Summary
ConstructorsConstructorDescriptionGrid(processing.core.PApplet p) Grid Constructor #1: Default constructor that creates a 3x3 GridGrid(processing.core.PApplet p, int rows, int cols) Grid Construtor #2: Only accepts the number of rows & columns (Default for 2023)Grid(processing.core.PApplet p, String screenName, processing.core.PImage bgImg, int rows, int cols) Grid constructor #3: Sets background image + rows & colsGrid(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 -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks for an AnimatedSprite and animates itvoidClears the screen from all Images & SpritesvoidClears the tile imagevoidClears the image from a particular tileintgetCenterX(GridLocation loc) intgetCenterY(GridLocation loc) getMark(GridLocation loc) Gets the mark value at a locationintAccessor methodintAccessor methodgetTile(int row, int col) getTile(GridLocation loc) Returns the GridTile object stored at a specified GridLocationintAccessor methodprocessing.core.PImagegetTileImage(GridLocation loc) Returns the PImage associated with a particular GridTileGets the Sprite from a specific GridTileintAccessor methodintgetX(int row, int col) intgetX(GridLocation loc) Provides the x-pixel value given a GridLocation locintgetY(int row, int col) intgetY(GridLocation loc) booleanhasMark(GridLocation loc) Checks if a location has a markbooleanhasTileImage(GridLocation loc) booleanChecks if a Tile has a PImagevoidPrints out the marks in the Grid to the consolebooleanremoveMark(GridLocation loc) Gets the mark value at a locationvoidsetAllMarks(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 gridvoidsetMark(String mark, GridLocation loc) Assigns a String mark to a location in the Grid.booleansetNewMark(String mark, GridLocation loc) Assigns a String mark to a location in the Grid.voidsetTileImage(GridLocation loc, processing.core.PImage img) Sets the image at a particular tile in the grid & displays itvoidsetTileSprite(GridLocation loc, Sprite sprite) Sets the Sprite at a particular tile in the grid & displays itvoidshow()Displays all World + Screen + Grid visualsvoidDisplays the PImages stored in ALL the GridTilesvoidDisplays ALL the Sprites stored in the GridvoidDeprecated.voidDisplays the PImage at a specific locationvoidDisplays the Sprite on a single GridTilevoidIf Grid mark system is used, shows all marks in the Grid in the consolevoidTurns off Grid mark system from printing all marks in the Grid in the consoleMethods inherited from class World
addSprite, addSpriteCopy, addSpriteCopyTo, addSpriteCopyTo, clearAllSprites, getColliders, getNumSprites, getSprite, getSprites, printSprites, printWorldSprites, removeSprite, removeSprite, showSprites, showWorldSprites, updateMethods inherited from class Screen
distToRightEdge, getBgImage, getIsMoveable, getLeftX, getName, getScreenTime, getScreenTimeSeconds, getTimeSince, getTopY, getTotalTime, moveBgXY, pause, resetTime, setBg, setLeftX, setName, setTopY, showBg, toString
-
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 appletrows-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 appletscreenName- String to track ScreensbgImg- stationary background imagerows-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 appletscreenName- String to track ScreensbgImg- stationary background imagetileMarks-rows-cols-
-
-
Method Details
-
setMark
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
Gets the mark value at a location- Parameters:
loc- GridLocation for a specific GridTile- Returns:
- String
-
removeMark
Gets the mark value at a location- Parameters:
loc- GridLocation for a specific GridTile- Returns:
- boolean
-
hasMark
Checks if a location has a mark- Parameters:
loc- GridLocation for a specific GridTile- Returns:
- boolean
-
setNewMark
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
trueif mark is correctly set (no previous mark),falseotherwise
-
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
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
- Returns:
- GridLocation where the mouse is currently hovering over
-
getX
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 GridTilecol- column of a specific GridTile- Returns:
- int x-value of left edge of a GridTile
-
getCenterX
- Parameters:
loc- GridLocation for a specific GridTile- Returns:
- int x-value of center pixel of the GridLocation
-
getY
- 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 GridTilecol- column of a specific GridTile- Returns:
- int y-value of left edge of a GridTile
-
getCenterY
- 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
Returns the GridTile object stored at a specified GridLocation- Parameters:
loc- GridLocation for a specific GridTile- Returns:
- GridTile
-
getTile
- Parameters:
row- row of a specific GridTilecol- column of a specific GridTile- Returns:
- GridTile GridTile object stored at a specified row and column
-
setTileImage
Sets the image at a particular tile in the grid & displays it- Parameters:
loc- GridLocation for a specific GridTileimg-
-
getTileImage
Returns the PImage associated with a particular GridTile- Parameters:
loc- GridLocation for a specific GridTile- Returns:
- PImage
-
hasTileImage
- Parameters:
loc- GridLocation for a specifc GridTile- Returns:
- boolean
trueif the GridTile has a PImage,falseotherwise
-
clearTileImage
Clears the tile image- Parameters:
loc- GridLocation for a specific GridTile
-
showTileImage
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. -
show
public void show()Displays all World + Screen + Grid visuals -
setTileSprite
Sets the Sprite at a particular tile in the grid & displays it- Parameters:
loc- GridLocation to changesprite- new Sprite to add to tile
-
getTileSprite
Gets the Sprite from a specific GridTile- Parameters:
loc- GridLocation for a specific GridTile- Returns:
- Sprite Sprite associated with a particular Tile
-
hasTileSprite
Checks if a Tile has a PImage- Parameters:
loc- GridLocation for a specific GridTile- Returns:
- boolean
trueif the GridTile has a stored image,falseotherwise
-
clearTileSprite
Clears the image from a particular tile- Parameters:
loc- GridLocation for a specific GridTile
-
animateTileSprite
Checks for an AnimatedSprite and animates it- Parameters:
loc- GridLocation for a specific GridTile
-
showTileSprite
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
-