-
Notifications
You must be signed in to change notification settings - Fork 2
Interaction System
Jantoom edited this page Sep 13, 2021
·
3 revisions
Entities will become Interactable if they hold a Component that extends the InteractionComponent
. This allows other entities to trigger collision and interaction events on them. Players specifically trigger interactions by pressing the E key.
-
PhysicsContactListener
: Receives all global Box2D collision events between fixtures. It will find the entities that own them, and trigger events "collision_start" and "collision_end" when collisions start and end.
-
PhysicsComponent
: Allows for thePhysicsContactListener
to fire events -
ColliderComponent
: Responsible for registering a fixture into the physics world. It serves as an easy-to-use interface between higher-level scripting and lower-level physics calculations. AHitboxComponent
is one that doesn't block movement of colliding entities. -
AnimationRenderComponent
: Switches between sprite animations for rendering. It is typical for most Interactable objects switching to a highlighted state while colliding with the player. -
InteractionComponent
: Serves as a base class for acting on collisions and interactions. It implements the interfaceInteractable
, which abstracts all methods relevant to inter-entity interaction. These arepreCollisionCheck
,onCollisionStart
,onCollisionEnd
andonInteraction
. By default, anInteractionComponent
:- listens for the events "collision_start", "collision_end" and "interaction"
- contains a reference to the entity's
HitboxComponent
for checking fixtures - contains a reference to the entity's
AnimationRenderComponent
for switching to highlighted textures
-
SurveyorComponent
: Responsible for triggering the "interaction" event. It works by surveying locations on the boundary of aHitboxComponent
for existing collisions, and chooses the closest entity collision for interaction. -
KeyboardPlayerInputComponent
: Pressing the E key will activate theSurveyorComponent
so that interactions may occur.
-
Player: Must have a
PhysicsComponent
,HitboxComponent
,KeyboardPlayerInputComponent
andSurveyorComponent
to use the Interaction system -
Interactable entities: Must have a
PhysicsComponent
,HitboxComponent
andInteractionComponent
to use the Interaction system- most interactable entities will have an
AnimationRenderComponent
to toggle textures when colliding, but this isn't compulsory - the player can also be an interactable entity
- most interactable entities will have an
-
onCollisionStart
andonCollisionEnd
should do a pre-collision check on the passed fixtures using the inheritedpreCollisionCheck
implementation. -
onCollisionStart
,onCollisionEnd
andonInteraction
should check for unique entity components using an "if, else if" statement to determine what functionality should be run.
@Override
public void onCollisionStart(Fixture me, Fixture other) {
Entity target = preCollisionCheck(me, other);
if (target == null) {
return;
} else if (target.getComponent(PlayerActions.class) != null) {
logger.info("BED ended collision with PLAYER, un-highlighting bed");
animator.startAnimation("bed");
}
}
- Rendered entities are usually highlighted when colliding, and un-highlighted otherwise
- (To be added) Informational overlays when colliding with important entities
Entity | onCollisionStart |
onCollisionEnd |
onInteraction |
---|---|---|---|
Player | Bed is highlighted | Bed is un-highlighted | Win condition is triggered |
Passive Bed Texture | Active Bed Texture |
---|---|
Entities and Components
Interaction System
Unit Testing
Input Handling
UI
Game Screens and Areas
Map Generation
Basic Interactable Objects Design