Class EnvironmentalCollision

java.lang.Object
com.deco2800.game.areas.terrain.EnvironmentalCollision

public class EnvironmentalCollision extends Object
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 Details

    • EnvironmentalCollision

      public EnvironmentalCollision(TerrainComponent terrain)
      Constructor method for the Environmental Collision.
      Parameters:
      terrain - Requires the terrain for convering x,y into world positions
  • Method Details

    • getEntities

      public Collection<Entity> getEntities()
      Returns:
      Collection of entities stored on the map
    • addEntity

      public void addEntity(Entity newEntity)
      Adds a new entity to hashtable
      Parameters:
      newEntity - new entity to be added to the environment
    • wouldCollide

      public Boolean wouldCollide(Entity potentialEntity, int xPotential, int yPotential)
      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 map
      xPotential - the proposed x cell position of the entity
      yPotential - 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 cord
      y - the tile's y cord
      Returns:
      true if near water else false