Disposal of Plunger Projectile after Certain Duration - UQdeco2800/2022-studio-2 GitHub Wiki

Summary

This wiki page will explain the how the plunger projectiles (spawned after an attack instance is called on ranged weapon) is disposed after a certain duration to preserve memory.

This is an extension/improvement on the already existing implementation of the Ranged Weapon Implementation in the game.

WeaponArrowProjectileComponent

Located in: source/core/src/main/com/deco2800/game/components/combatitemscomponents/WeaponArrowProjectileComponent.java

This is a component that is tied to the projectile entities. A new variable called arrowExpireTime is created and it stores the current time of the game incremented by 2000ms. This is the time when the projectile spawned should be disposed.

long arrowExpireTime = System.currentTimeMillis() + 2000;

Under the update() method, the disposeExpiredArrow() is called to check if the arrow should be disposed or not.

In the disposeExpiredArrow() method, if the current time of the game is greater than the arrowExpireTime, the projectile entity is disposed, along with its animation.

    private void disposeExpiredArrow() {
        if (System.currentTimeMillis() > arrowExpireTime) {
            entity.dispose();
            entity.getComponent(AnimationRenderComponent.class).stopAnimation();
        }
    }

Justification of Integration

From the Testing Plan for Libgdx Components it was found that the plunger bow projectiles travels for an infinite distance and never gets disposed until the game area is changed/reset. This implementation will ensure that the plunger bow projectile will be disposed after a specified time (2 seconds) so that the memory usage of the game is kept low. This also ensures that the game experience is improved as prior to this, the projectiles spawned can travel forever to the top of the map where the boss is, which means that the boss can be killed even when the player is only freshly spawned into the map.

Back to Combat Items Contents Page

Author

  • Eugene Chong
  • GitHub: @eugene2341
  • Discord: gene#0005
  • Slack: Eugene Chong