Skip to content

Object Interaction

Pranay Premdas edited this page Sep 15, 2021 · 25 revisions

Entities that will have the ability to be interacted with by the player if they implement the InteractionComponent, allowing the player to trigger a specified event upon 'interacting' with it via the keyboard input 'E'. The component will also include optional functionality in order to allow it to trigger an event simply when the player is in contact with it, such as changing the sprite to display a yellow outline, or display an input prompt or tutorial (See examples below). The yellow outline indicates the user that the object is interactable.

Key Components

  • PhysicsContactListener: This listens for all collisions/contact that occur between fixtures and calls functions at the start, end, during and post contact.
  • PlayerObjectInteractions: This component is implemented by the Player entity and stores an ArrayList of entities that possess the InteractableComponent that the Player is currently in contact with.
  • InteractableComponent: Component which allows a entity to be interacted with.

Operation

Communication between Collisions and Player Entity

  • Game Physics notice Player Collisions: PhysicsContactListener listens for all physics collisions that occur, then retrieves the entities attached to Fixtures participating in the collision. At game initiation, a targetFixture belonging to the Player entity is parsed into the PhysicsContactListener. In all proceeding collisions, participating entities are compared to targetFixture to detect Player Collisions.
  • Collision is communicated to Player: On collision start, if the targetFixture is a participant, PhysicsContactListener retrieves the targetEntity component PlayerObjectInteractions and sends the non-player entity participating in the collision to this component.
  • Player knows what object entities it can interact with: The PlayerObjectInteractions component checks that the entity sent implements the InteractableComponent and then appends the entity to a list which describes what objects the Player entity is touching at that moment.
  • End of collision clean up: When the collision ends between the Player entity and the interactable object, PhysicsContactListener lets the Players PlayerObjectInteractions component know, so that the interactable object can be removed from the list of objects [that the Player entity is touching].

Keyboard Input Triggering Interaction Events

  • Keyboard Input and Interaction Checking: When 'E' is detected as keyboard input, a empty event is called within the player entity class. The interactable objects that are present in PlayerObjectInteraction detect this through implemented listeners.
  • Interaction Triggered: The triggered entities InteractableComponent is accessed and a interaction event is triggered via the EventHandler.
  • Interaction: The listener in the InteractableComponent The state of the entity, game state, or the Player entity is modified.

Each interactable component has a listener that triggers the entities trigger event. The action triggered by each trigger event is dependant on the object that the player interacts with.

Usage

  • Interactable Objects: For a object to be interactable it must implement the InteractableComponent
  • Interaction Entities: For a entity to interact with interactable objects, it must implement PlayerObjectInteractions

Door Interaction

Latent Door Texture Active Door Texture

Current progress: For the moment, only a bed entity is being spawned. The door entity will trigger a level change. However, as no new level was created in sprint 1, the door interaction was not implimented.

Bed Interaction

Latent Bed Texture Active Bed Texture

TV Interaction:

Latent TV Texture Switched off TV

Bubble Animation:

Clone this wiki locally