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
AnAreais a single room or outdoor scene in which the player can exist, containing its ownTiledMaptexture and set ofInteractableobjects.- Author:
- ENG1 Team 23 (Cohort 3)
-
-
Field Summary
Fields Modifier and Type Field Description private com.badlogic.gdx.math.Vector2initialCharacterPositionprivate java.util.List<Interactable>interactablesThe list ofInteractableobjects existing in theAreaprivate GameMapmapprivate com.badlogic.gdx.physics.box2d.WorldworldThe LibGDX world responsible for holdingBodyDef.BodyType.StaticBodyandBodyDef.BodyType.DynamicBodycollision zones, generally used forInteractableandTiledMapborder objects
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddInteractable(Interactable interactable)Adds anInteractableto the set of interactable tiles in the currentArea.com.badlogic.gdx.math.Vector2bound(com.badlogic.gdx.math.Vector2 candidate, float horizontalGutter, float verticalGutter)Bounds the given candidate vector along the given gutter boundaries andMapedgesvoiddispose()Releases all resources used by theAreaprivate voidgenerateBorders(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 theTiledMapcom.badlogic.gdx.math.Vector2getInitialCharacterPosition()(package private) com.badlogic.gdx.physics.box2d.BodyregisterCharacter(float width, float height)(package private) com.badlogic.gdx.physics.box2d.BodyregisterCollisionBody(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 theWorldcorresponding to theAreavoidrender(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)Registers the currentAreaonto the given game instanceSpriteBatch, including allInteractableobjectsvoidsetInitialCharacterPosition(com.badlogic.gdx.math.Vector2 position)voidstep()Steps theWorldassociated with theAreavoidtriggerInteractables(com.badlogic.gdx.math.Vector2 characterPosition)Given the current position of theCharacter, interact with any nearbyInteractableobjectsvoidupdateView(com.badlogic.gdx.graphics.OrthographicCamera gameCam)Instructs theGameMaprendering object to update its viewing position with respect to theOrthographicCameragame camera
-
-
-
Field Detail
-
interactables
private final java.util.List<Interactable> interactables
The list ofInteractableobjects existing in theArea- See Also:
Interactable
-
world
private final com.badlogic.gdx.physics.box2d.World world
The LibGDX world responsible for holdingBodyDef.BodyType.StaticBodyandBodyDef.BodyType.DynamicBodycollision zones, generally used forInteractableandTiledMapborder objects
-
initialCharacterPosition
private com.badlogic.gdx.math.Vector2 initialCharacterPosition
The initial position of the player-controlledCharacterupon being spawned into theArea. This positionVector2is 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 InvalidAreaExceptionConstructs a newAreawith aTiledMapwith a TMX file at the given path- Parameters:
mapPath- The path of theArea's background textureinitialCharacterPosition- The initial position of theCharacteron theAreamap, specified by in-game metre components- Throws:
InvalidAreaException- See Also:
Character
-
-
Method Detail
-
addInteractable
void addInteractable(Interactable interactable)
Adds anInteractableto the set of interactable tiles in the currentArea.- Parameters:
interactable- TheInteractableto add
-
triggerInteractables
public void triggerInteractables(com.badlogic.gdx.math.Vector2 characterPosition)
Given the current position of theCharacter, interact with any nearbyInteractableobjects- 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 andMapedges- 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 theGameMaprendering object to update its viewing position with respect to theOrthographicCameragame camera- Parameters:
gameCam- TheOrthographicCameragame camera against which theAreaviewport should be aligned
-
step
public void step()
Steps theWorldassociated 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 theWorldcorresponding to theArea- Parameters:
initialPosition- The initial position of the body, specified as in-game metre componentstype- The type of the body, according toBodyDef.BodyTypewidth- 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 ofRectangleMapObjects represented the border vector
-
dispose
public void dispose()
Releases all resources used by theArea- Specified by:
disposein interfacecom.badlogic.gdx.utils.Disposable
-
render
public void render(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
Registers the currentAreaonto the given game instanceSpriteBatch, including allInteractableobjects
-
-