-
Notifications
You must be signed in to change notification settings - Fork 1
Potion factory restructure and updated methods
PeterOu8 edited this page Sep 20, 2022
·
2 revisions
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;
}
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);
}
- Li-Sung Ou
- GitHub: @PeterOu8
- Discord: Secret Agent Randy Beans#6754
- Slack: Li-Sung Ou