Package de.tum.cit.fop.maze.Parser
Class GameField
java.lang.Object
de.tum.cit.fop.maze.Parser.GameField
Represents the game field grid containing tiles and game objects.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddGameObject(GameObject obj) Adds a game object to the field.Gets all game objects in the field.intGets the field height.<T extends GameObject>
List<T>getObjectsByType(Class<T> type) Gets all game objects of a specific type.com.badlogic.gdx.math.Vector2Gets the player's starting position.intGets the number of keys required to open the exit.getTile(int x, int y) Gets the tile type at specified coordinates.com.badlogic.gdx.math.Vector2getTileTypeCoords(GameField newMap, TileType TYPE) intgetWidth()Gets the field width.booleanisInsideWall(float x, float y, com.badlogic.gdx.math.Vector2 size) Checks if a position overlaps with any solid tile.voidsetPlayerStartPos(com.badlogic.gdx.math.Vector2 pos) Sets the player's starting position.voidSets a tile at specified coordinates.
-
Constructor Details
-
GameField
public GameField(int width, int height)
-
-
Method Details
-
getTile
Gets the tile type at specified coordinates.- Parameters:
x- X coordinatey- Y coordinate- Returns:
- The tile type, or WALL if out of bounds
-
getGameObjects
Gets all game objects in the field.- Returns:
- List of game objects
-
getPlayerStartPos
public com.badlogic.gdx.math.Vector2 getPlayerStartPos()Gets the player's starting position.- Returns:
- Player start position vector
-
setPlayerStartPos
public void setPlayerStartPos(com.badlogic.gdx.math.Vector2 pos) Sets the player's starting position.- Parameters:
pos- New start position
-
getWidth
public int getWidth()Gets the field width.- Returns:
- Width in tiles
-
getRequiredKeys
public int getRequiredKeys()Gets the number of keys required to open the exit.- Returns:
- Number of keys in the field
-
getHeight
public int getHeight()Gets the field height.- Returns:
- Height in tiles
-
getObjectsByType
Gets all game objects of a specific type.- Type Parameters:
T- Type parameter extending GameObject- Parameters:
type- The class type to filter by- Returns:
- List of objects matching the type
-
getTileTypeCoords
-
setTile
Sets a tile at specified coordinates.- Parameters:
x- X coordinatey- Y coordinatetile- Tile type to set
-
addGameObject
Adds a game object to the field.- Parameters:
obj- The game object to add
-
isInsideWall
public boolean isInsideWall(float x, float y, com.badlogic.gdx.math.Vector2 size) Checks if a position overlaps with any solid tile.- Parameters:
x- X positiony- Y positionsize- Object size for collision checking- Returns:
- True if inside a wall or solid tile
-