Itembar System: itembar - UQdeco2800/2021-ext-studio-2 GitHub Wiki
Relevant Files:
- newItembar.java: the finalized java class of item bar
public newItembar() {
waters = new ArrayList<>();
foods = new ArrayList<>();
kits = new ArrayList<>();
for (int i = 0; i < 3; i++) {
waters.add("water");
foods.add("food");
kits.add("kit");
}
}
-
KeyboardPlayerInputComponent.java: Responsible for control the use of item.
press J to use health-kit
case Keys.J:
newItembar.usekit();
if(entity.getComponent(CombatStatsComponent.class).getHealth() < 100){
entity.getComponent(CombatStatsComponent.class).addHealth(10);
}
return true;
press L to use food
case Keys.L:
newItembar.usefood();
FoodDisplay.addOrRemoveImage(1);
return true;
press K to use water
case Keys.K:
newItembar.usewater();
WaterDisplay.addOrRemoveImage(1);
return true;
- ItemBarDisplay.java: Responsible for displays the itembar UI on the screen.
/* Listen to itembar events*/
entity.getEvents().addListener("updateitembar", this::updateItemBarUI);
/**
* Creates reusable ui styles and adds actors to the stage.
*/
@Override
public void create() {
super.create();
addActors();
entity.getEvents().addListener("updateitembar", this::updateItemBarUI);
}
public void updateItemBarUI() {
CharSequence text = bar.getcounts();
countlabel.setText(text);
}
@Override
public void dispose() {
super.dispose();
countlabel.remove();
counttable.remove();
}