Potion factory restructure and updated methods - UQdeco2800/2022-studio-2 GitHub Wiki

Potion factory restructure

The previous version of the potion factory create each type of potion separately and produced excess codes. In sprint 2, I wrote a createBasePotion function which creates a base potion with no special attribute. This can be used to create other potions by adding different PotionEffect components.

public static Entity createBasePotion() {
    Entity potion = new Entity()
            .addComponent(new PhysicsComponent())
            .addComponent(new ColliderComponent().setLayer(PhysicsLayer.PLAYER))
            .addComponent(new HitboxComponent().setLayer(PhysicsLayer.PLAYER))
            .addComponent(new ItemPickupComponent(PhysicsLayer.PLAYER));
    potion.setEntityType(EntityTypes.POTION);
    potion.getComponent(PhysicsComponent.class).setBodyType(BodyDef.BodyType.StaticBody);
    return potion;
}

Sprint 2 updated methods

PotionEffectComponent

Since type checking of potions were not implemented in sprint 1 and 2. I came up with the following overloaded methods to check if two potions have the same effect. Putting in Potion as parameter:

public boolean equalTo(Entity potion) {
    return this.effectType.equals(potion.getComponent(PotionEffectComponent.class).getPotionEffect());
}

Putting in effectType as parameter:

public boolean equalTo(String effectType) {
    return this.effectType.equals(effectType);
}

Back to Potions Page

Author

  • Li-Sung Ou
  • GitHub: @PeterOu8
  • Discord: Secret Agent Randy Beans#6754
  • Slack: Li-Sung Ou