GSoC Week 5: Keeping Score
Posted on June 21st, 2018
After trials and tribulations this week, I've gotten the score system working! I had started some of the base code for the score system last week, but didn't realize how much more time it would take to puzzle the whole thing out. I changes up the base rasterizer and prefabs so that each of the base blocks have a team faction attached to them. I also added a component to them that allows them to be activated, and so that when they are activated they trigger a check to see if the activator (player) has the enemy flag--if so, it adds a point to the player's team.
// Checking to see if the player is activating their base and have the enemy flag
if (baseTeamComponent.team.equals(baseTeamComponent.BLACK) && heldItem.getComponent(BlockItemComponent.class).blockFamily.getURI().toString()
.equalsIgnoreCase("LightAndShadowResources:RedFlag")) {
blackScore++;
}
ScoreSystem.java handles the bulk of the lifting going on. It handles the onActivate code previously mentioned, as well as the bindings for the UI. The UI has UILabels for each team's score, and binds the redScore and the blackScore values to integers in ScoreSystem.java.
// An example of score binding to a particular section of the UI
scoreScreen = nuiManager.getHUD().getHUDElement("LightAndShadow:ScoreHud");
blackScoreArea = scoreScreen.find("blackScoreArea", UILabel.class);
blackScoreArea.bindText(new ReadOnlyBinding() {
@Override
public String get() {
return String.valueOf(blackScore);
}
});
So in short--the new score system keeps track of two integers, redScore and blackScore, binds those values to the HUD UI, and then adds to the current score when the player activates a block at their base and holds the enemy flag.
Black team scores!
The one big thing missing from the main gameplay loop is the resetting of the level when a player scores.
I was hoping to start on some of the weapons and raycasting code this week, but unfortunately wasn't able to yet. I'm hoping to talk more about the best way to implement some of this at the meeting tomorrow (already heard that the Gookeeper code was one place to look for this) and make any revisions to the current PR as needed. I've been thinking maybe an item similar to the current magic wand is the way to go for the item (magic staff, maybe?) to allow the players to target one another.
Work up to this date are in the same PR as last week, https://github.com/Terasology/LightAndShadow/pull/67