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 TypeMethodDescriptionvoid
Checks for an AnimatedSprite and animates itvoid
Clears the screen from all Images & Spritesvoid
Clears the tile imagevoid
Clears the image from a particular tileint
getCenterX
(GridLocation loc) int
getCenterY
(GridLocation loc) getMark
(GridLocation loc) Gets the mark value at a locationint
Accessor methodint
Accessor methodgetTile
(int row, int col) getTile
(GridLocation loc) Returns the GridTile object stored at a specified GridLocationint
Accessor methodprocessing.core.PImage
getTileImage
(GridLocation loc) Returns the PImage associated with a particular GridTileGets the Sprite from a specific GridTileint
Accessor methodint
getX
(int row, int col) int
getX
(GridLocation loc) Provides the x-pixel value given a GridLocation locint
getY
(int row, int col) int
getY
(GridLocation loc) boolean
hasMark
(GridLocation loc) Checks if a location has a markboolean
hasTileImage
(GridLocation loc) boolean
Checks if a Tile has a PImagevoid
Prints out the marks in the Grid to the consoleboolean
removeMark
(GridLocation loc) Gets the mark value at a locationvoid
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 gridvoid
setMark
(String mark, GridLocation loc) Assigns a String mark to a location in the Grid.boolean
setNewMark
(String mark, GridLocation loc) Assigns a String mark to a location in the Grid.void
setTileImage
(GridLocation loc, processing.core.PImage img) Sets the image at a particular tile in the grid & displays itvoid
setTileSprite
(GridLocation loc, Sprite sprite) Sets the Sprite at a particular tile in the grid & displays itvoid
show()
Displays all World + Screen + Grid visualsvoid
Displays the PImages stored in ALL the GridTilesvoid
Displays ALL the Sprites stored in the Gridvoid
Deprecated.void
Displays the PImage at a specific locationvoid
Displays the Sprite on a single GridTilevoid
If Grid mark system is used, shows all marks in the Grid in the consolevoid
Turns 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, update
Methods 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
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
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
true
if the GridTile has a PImage,false
otherwise
-
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
true
if the GridTile has a stored image,false
otherwise
-
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
-