Skip to content

Merge Powerups

atharvagupta2003 edited this page Oct 5, 2023 · 2 revisions

Overview

Merge Potions and Powerups to reduce Code duplication and accomodate it all in Laboratory

Usage

Initialisation:

  1. Merging Potion Component, Potion Types and Potion factory into powerups
  2. Merging Config Files
  3. deleting all unwanted potion files
 public class PowerupConfigs {
    public PowerupConfig healthPowerup = new PowerupConfig();
    public PowerupConfig speedPowerup = new PowerupConfig();
    public PowerupConfig extraLifePowerup = new PowerupConfig();
    public PowerupConfig doubleCrossPowerup = new PowerupConfig();
    public PowerupConfig tempImmunityPowerup = new PowerupConfig();
    public PowerupConfig doubleDamagePowerup = new PowerupConfig();
    public PowerupConfig snapPowerup = new PowerupConfig();
    public PowerupConfig death_potion = new PowerupConfig();
}

Example - Spawning Powerups

private void spawnPowerups() {
    GridPoint2 minPos = new GridPoint2(0, 0);
    GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2);
    GridPoint2 deathPosition = RandomUtils.random(minPos, maxPos);

    // Create a health and speed powerup
    Entity deathPotion = PowerupFactory.createDeathPotion();

    // Spawn the created powerups at the two random locations
    spawnEntityAt(deathPotion, deathPosition, true, false);
  }
Clone this wiki locally