Skip to content

Commit

Permalink
feat: delegate player death behaviour to the game instance
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceh121 committed Sep 7, 2024
1 parent daf1240 commit 2d1d755
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
7 changes: 7 additions & 0 deletions core/src/me/vinceh121/wanderer/StoryWanderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Align;

import me.vinceh121.wanderer.character.CharacterDeadEvent;
import me.vinceh121.wanderer.event.Event;
import me.vinceh121.wanderer.input.Input;
import me.vinceh121.wanderer.input.InputListenerAdapter;
Expand Down Expand Up @@ -42,6 +43,7 @@ public boolean inputDown(final Input in) {
StoryWanderer.this.objectivesView.setVisible(true);
return true;
}

return false;
}

Expand All @@ -51,10 +53,15 @@ public boolean inputUp(final Input in) {
StoryWanderer.this.objectivesView.setVisible(false);
return true;
}

return false;
}
});

this.eventDispatcher.addEventListener(CharacterDeadEvent.TYPE, e -> {
// TODO display lose screen
});

// BY CALLER

this.startStory("singleplayer", 0, 0);
Expand Down
8 changes: 8 additions & 0 deletions core/src/me/vinceh121/wanderer/Wanderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import me.vinceh121.wanderer.entity.ILivingEntity;
import me.vinceh121.wanderer.entity.NavigationWaypoint;
import me.vinceh121.wanderer.entity.Prop;
import me.vinceh121.wanderer.event.Event;
import me.vinceh121.wanderer.event.EventDispatcher;
import me.vinceh121.wanderer.i18n.I18N;
import me.vinceh121.wanderer.input.Input;
import me.vinceh121.wanderer.input.InputListenerAdapter;
Expand All @@ -70,6 +72,8 @@ public class Wanderer extends ApplicationDelegate {
private final ScriptManager scriptManager = new ScriptManager();
private final ModManager modManager = new ModManager();

protected final EventDispatcher eventDispatcher = new EventDispatcher();

private ConsoleHandler consoleHandler;

private Array<AbstractEntity> entities;
Expand Down Expand Up @@ -910,6 +914,10 @@ public void dispose() {
}
}

public void dispatchEvent(final Event e) {
this.eventDispatcher.dispatchEvent(e);
}

public ConsoleHandler getConsoleHandler() {
return this.consoleHandler;
}
Expand Down
18 changes: 18 additions & 0 deletions core/src/me/vinceh121/wanderer/character/CharacterDeadEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.vinceh121.wanderer.character;

import me.vinceh121.wanderer.event.Event;

public class CharacterDeadEvent extends Event {
public static final String TYPE = "characterDead";
private final CharacterW character;

public CharacterDeadEvent(final CharacterW character) {
super(TYPE);

this.character = character;
}

public CharacterW getCharacter() {
return character;
}
}
2 changes: 1 addition & 1 deletion core/src/me/vinceh121/wanderer/character/CharacterW.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private void moveCamera() {

@Override
public void onDeath() {
// TODO
this.game.dispatchEvent(new CharacterDeadEvent(this));
}

public void processInput() {
Expand Down

0 comments on commit 2d1d755

Please sign in to comment.