-
Notifications
You must be signed in to change notification settings - Fork 1
Triggering the dialog by pressing the F key
wsxmr1234 edited this page Oct 19, 2022
·
1 revision
public class TriggerDialogComponent extends Component {
@Override
public void create() {
entity.getEvents().addListener("collisionStart", this::onCollisionStart);
entity.getEvents().addListener("collisionEnd", this::onCollisionEnd);
}
private void onCollisionEnd(Fixture me, Fixture other) {
if (!PhysicsLayer.contains(targetLayer, other.getFilterData().categoryBits)) {
// Doesn't match our target layer, ignore
return;
}
npcInteractionDisplay.hideInteractionPrompt();
Stage stage = ServiceLocator.getRenderService().getStage();
if (listener != null) {
stage.removeListener(listener);
}
}
private void onCollisionStart(Fixture me, Fixture other) {
if (!PhysicsLayer.contains(targetLayer, other.getFilterData().categoryBits)) {
// Doesn't match our target layer, ignore
return;
}
npcInteractionDisplay.showInteractionPrompt();
Stage stage = ServiceLocator.getRenderService().getStage();
listener = new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {
if (keycode == Input.Keys.F) {
// TODO add trigger dialog
switch (name) {
case Zoe -> {
try {
npcInteractionDisplay.interactWithZoe();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
case Metis -> {
try {
npcInteractionDisplay.interactWithMetis();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
case Doris -> {
npcInteractionDisplay.interactWithDoris();
}
}
}
return false;
}
};
stage.addListener(listener);
}
}
In order to achieve the function of triggering the dialog by pressing the f key close to the user, i do it by using the collision event. I added two events onCollisionStart and onCollisionEnd. When the player collides with the NPC, the onCollisionStart event will be triggered, and a key listener will be created to monitor whether the player presses the F key. And when the player is far away from the NPC, the key listener will be removed.
- Uniform Pixel Grid Resolution
- Storyline
- Instruction
- NPC info
- NPC Communication Script
- Inventory-System-and-Consumables
- Storyline User Test
- Traitor Clues
- Game Characters
- Player Profile User Test
- Player Eviction Menu Sprint1: User survey (Team 7)
- Player Eviction Menu Sprint2: User survey (Team 7)
- Sprint3 - Win/lose Condition: User survey (Team 7)
- Sprint4 - Polishing-tasks: User survey (Team 7)
- Transition Animation/Special Effects/Sound Effects: Feature Overviews
- Transition Animation and Effects: Design Process & Guideline
- Sprint 4 User Testing
- Transition Animation & Effect: Code Guideline-Sprint4
- Sound effect when players complete npc tasks and hover over npc cards
- Fixing the clue bug
- Music Test
- Player Eviction Menu: Design Process & Guideline
- Player Eviction Menu (Feature Overviews)
- Player Eviction Menu: Code Guideline - Sprint1
- Sprint 1 User Testing
- Detailed Eviction Card: Design Process & Guideline
- Detailed Eviction Card: Feature Overviews
- Sprint 2 User Testing
- Player Eviction Menu: Code Guideline - Sprint2
- Sprint 2 Inventory System and Consumables Items User Testing
- Sprint 2 Inventory System and Consumables Items Functionality
- NPC interaction testing plan sprint3
- NPC interaction testing results sprint3
- NPC Dialogue Scripts
- Code Guideline
- Win/lose Condition: Design Process & Guideline
- Win/lose Condition: Feature Overviews
- Sprint 3 User Testing
- Win/lose condition: Code Guideline - Sprint3
- Enemy List
- User Testing 1: Enemy Image Filter
- User Testing 2: Enemy Animation and AI
- User Testing 3: Basic Attack