Class Area
- java.lang.Object
-
- bytemusketeers.heslingtonhustle.scene.Area
-
- All Implemented Interfaces:
Drawable
,com.badlogic.gdx.utils.Disposable
public class Area extends java.lang.Object implements Drawable
AnArea
is a single room or outdoor scene in which the player can exist, containing its ownTiledMap
texture and set ofInteractable
objects.- Author:
- ENG1 Team 23 (Cohort 3)
-
-
Field Summary
Fields Modifier and Type Field Description private com.badlogic.gdx.math.Vector2
initialCharacterPosition
private java.util.List<Interactable>
interactables
The list ofInteractable
objects existing in theArea
private GameMap
map
private com.badlogic.gdx.physics.box2d.World
world
The LibGDX world responsible for holdingBodyDef.BodyType.StaticBody
andBodyDef.BodyType.DynamicBody
collision zones, generally used forInteractable
andTiledMap
border objects
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addInteractable(Interactable interactable)
Adds anInteractable
to the set of interactable tiles in the currentArea
.com.badlogic.gdx.math.Vector2
bound(com.badlogic.gdx.math.Vector2 candidate, float horizontalGutter, float verticalGutter)
Bounds the given candidate vector along the given gutter boundaries andMap
edgesvoid
dispose()
Releases all resources used by theArea
private void
generateBorders(com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.objects.RectangleMapObject> borderObjects)
Generate the static collision bodies for all given border objects, as defined by theTiledMap
com.badlogic.gdx.math.Vector2
getInitialCharacterPosition()
(package private) com.badlogic.gdx.physics.box2d.Body
registerCharacter(float width, float height)
(package private) com.badlogic.gdx.physics.box2d.Body
registerCollisionBody(com.badlogic.gdx.math.Vector2 initialPosition, com.badlogic.gdx.physics.box2d.BodyDef.BodyType type, float width, float height)
Registers a new body with a standard collision box in theWorld
corresponding to theArea
void
render(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
Registers the currentArea
onto the given game instanceSpriteBatch
, including allInteractable
objectsvoid
setInitialCharacterPosition(com.badlogic.gdx.math.Vector2 position)
void
step()
Steps theWorld
associated with theArea
void
triggerInteractables(com.badlogic.gdx.math.Vector2 characterPosition)
Given the current position of theCharacter
, interact with any nearbyInteractable
objectsvoid
updateView(com.badlogic.gdx.graphics.OrthographicCamera gameCam)
Instructs theGameMap
rendering object to update its viewing position with respect to theOrthographicCamera
game camera
-
-
-
Field Detail
-
interactables
private final java.util.List<Interactable> interactables
The list ofInteractable
objects existing in theArea
- See Also:
Interactable
-
world
private final com.badlogic.gdx.physics.box2d.World world
The LibGDX world responsible for holdingBodyDef.BodyType.StaticBody
andBodyDef.BodyType.DynamicBody
collision zones, generally used forInteractable
andTiledMap
border objects
-
initialCharacterPosition
private com.badlogic.gdx.math.Vector2 initialCharacterPosition
The initial position of the player-controlledCharacter
upon being spawned into theArea
. This positionVector2
is specified in in-game metres.- See Also:
getInitialCharacterPosition()
-
map
private final GameMap map
- See Also:
GameMap
,GameMap.render(SpriteBatch)
-
-
Constructor Detail
-
Area
Area(java.lang.String mapPath, com.badlogic.gdx.math.Vector2 initialCharacterPosition) throws InvalidAreaException
Constructs a newArea
with aTiledMap
with a TMX file at the given path- Parameters:
mapPath
- The path of theArea
's background textureinitialCharacterPosition
- The initial position of theCharacter
on theArea
map, specified by in-game metre components- Throws:
InvalidAreaException
- See Also:
Character
-
-
Method Detail
-
addInteractable
void addInteractable(Interactable interactable)
Adds anInteractable
to the set of interactable tiles in the currentArea
.- Parameters:
interactable
- TheInteractable
to add
-
triggerInteractables
public void triggerInteractables(com.badlogic.gdx.math.Vector2 characterPosition)
Given the current position of theCharacter
, interact with any nearbyInteractable
objects- Parameters:
characterPosition
- The position of the player-controlledCharacter
- See Also:
Interactable.interact()
-
bound
public com.badlogic.gdx.math.Vector2 bound(com.badlogic.gdx.math.Vector2 candidate, float horizontalGutter, float verticalGutter)
Bounds the given candidate vector along the given gutter boundaries andMap
edges- Parameters:
candidate
- The vector to be boundedhorizontalGutter
- The gutter, specified as in-game metres, on the horizontal axisverticalGutter
- The gutter, specified as in-game metres, on the vertical axis- Returns:
- The bounded vector
- See Also:
GameMap.bound(Vector2, float, float)
-
updateView
public void updateView(com.badlogic.gdx.graphics.OrthographicCamera gameCam)
Instructs theGameMap
rendering object to update its viewing position with respect to theOrthographicCamera
game camera- Parameters:
gameCam
- TheOrthographicCamera
game camera against which theArea
viewport should be aligned
-
step
public void step()
Steps theWorld
associated with theArea
- See Also:
World.step(float, int, int)
-
registerCollisionBody
com.badlogic.gdx.physics.box2d.Body registerCollisionBody(com.badlogic.gdx.math.Vector2 initialPosition, com.badlogic.gdx.physics.box2d.BodyDef.BodyType type, float width, float height)
Registers a new body with a standard collision box in theWorld
corresponding to theArea
- Parameters:
initialPosition
- The initial position of the body, specified as in-game metre componentstype
- The type of the body, according toBodyDef.BodyType
width
- The fixed width of the body, in in-game metresheight
- The fixed height of the body, in in-game metres- Returns:
- The newly registered body
-
registerCharacter
com.badlogic.gdx.physics.box2d.Body registerCharacter(float width, float height)
- Parameters:
width
- The width of the characterheight
- The height of the character- Returns:
- The newly registered character body
- See Also:
registerCollisionBody(Vector2, BodyDef.BodyType, float, float)
,Character
-
getInitialCharacterPosition
public com.badlogic.gdx.math.Vector2 getInitialCharacterPosition()
- Returns:
- The requested position vector
- See Also:
Character
-
setInitialCharacterPosition
public void setInitialCharacterPosition(com.badlogic.gdx.math.Vector2 position)
- Parameters:
position
- The new position- See Also:
Character
-
generateBorders
private void generateBorders(com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.objects.RectangleMapObject> borderObjects)
Generate the static collision bodies for all given border objects, as defined by theTiledMap
- Parameters:
borderObjects
- The array ofRectangleMapObject
s represented the border vector
-
dispose
public void dispose()
Releases all resources used by theArea
- Specified by:
dispose
in interfacecom.badlogic.gdx.utils.Disposable
-
render
public void render(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
Registers the currentArea
onto the given game instanceSpriteBatch
, including allInteractable
objects
-
-