Package com.deco2800.game.areas.terrain
Class EnvironmentalCollision
java.lang.Object
com.deco2800.game.areas.terrain.EnvironmentalCollision
Helper Class that stores entities on the map and checks collisions when given
a new entity
Used for placing environmental objects such as trees, rocks and buildings
plus additional
utility like finding closet entity to a point or retrieving a list of all
environmental entities
-
Constructor Summary
ConstructorsConstructorDescriptionEnvironmentalCollision
(TerrainComponent terrain) Constructor method for the Environmental Collision. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new entity to hashtableboolean
isNearWater
(int x, int y) Checks the current tile and all tiles around it for a water tile.wouldCollide
(Entity potentialEntity, int xPotential, int yPotential) Calculates if the given entity will collide with already existing entities Still in testing phase.
-
Constructor Details
-
EnvironmentalCollision
Constructor method for the Environmental Collision.- Parameters:
terrain
- Requires the terrain for convering x,y into world positions
-
-
Method Details
-
getEntities
- Returns:
- Collection of entities stored on the map
-
addEntity
Adds a new entity to hashtable- Parameters:
newEntity
- new entity to be added to the environment
-
wouldCollide
Calculates if the given entity will collide with already existing entities Still in testing phase. Uses the scale x and scale y of the entity to determine collision/hitbox size Due to isometric view world positions must be used thus the conversion from cell coordinates- Parameters:
potentialEntity
- The new entity to be added to the mapxPotential
- the proposed x cell position of the entityyPotential
- the proposed y cell position of the entity- Returns:
- true if a collision would occur else false
-
isNearWater
public boolean isNearWater(int x, int y) Checks the current tile and all tiles around it for a water tile. Returns true if near water. This is necessary as world pos doesnt perfectly allign to cell positions therefore a buffer must be introduced- Parameters:
x
- the tile's x cordy
- the tile's y cord- Returns:
- true if near water else false
-