Class EnemyBubbleModel


public class EnemyBubbleModel extends EmptyBubbleModel
Represents an enemy bubble created by the player.

This class extends the EmptyBubbleModel and provides specific behavior for enemy bubbles. Enemy bubbles contain an enemy model and have additional logic for handling the enemy's state and interactions.

  • Constructor Details

    • EnemyBubbleModel

      public EnemyBubbleModel(EnemyModel enemyModel, float x, float y, Constants.Direction direction)
      Constructs a new EnemyBubbleModel.
      Parameters:
      enemyModel - the enemy model of the captured enemy
      x - the starting x coordinate
      y - the starting y coordinate
      direction - the starting direction
  • Method Details

    • respawnEnemy

      public void respawnEnemy()
      Respawns the enemy if the bubble was not popped by the player.

      If the bubble was not popped by the player, this method resets the enemy's state, repositions the enemy to the bubble's current coordinates, and sets the enemy to an active state.

    • updateDeadAction

      protected void updateDeadAction()
      Updates the bubble's movement after it has been popped by the player.

      This method handles the bubble's movement based on its current state and direction.

      If the bubble is moving upwards, it updates the y-coordinate and checks for perimeter wall collisions to change direction if necessary.

      If the bubble is moving downwards, it updates the y-coordinate and checks for collisions with solid objects to stop the bubble and spawn a reward.

      Overrides:
      updateDeadAction in class EmptyBubbleModel
    • pop

      public void pop()
      Pops the bubble and updates its state.

      If the bubble's current state is not POP\_NORMAL or POP\_RED, this method changes the state to the appropriate pop state based on the previous state.

      Additionally, it sets the enemy's alive status to false.

      Overrides:
      pop in class EmptyBubbleModel
    • playerPop

      public void playerPop(PlayerModel playerModel, int EnemyBubblePopCounter, ChainReactionManager chainReactionManager)
      Handles the player popping the bubble, this method is only used by the ChainReactionManager.

      If the bubble has not been popped yet, this method increases the enemy bubble pop counter, updates the consecutive pops counter, and adds a chain reaction reward.

      Then, it calls the playerPop(PlayerModel) method to handle the actual popping logic.

      Overrides:
      playerPop in class EmptyBubbleModel
      Parameters:
      playerModel - the player model
      EnemyBubblePopCounter - the number of enemy bubbles popped
      chainReactionManager - the chain explosion manager
    • playerPop

      public void playerPop(PlayerModel playerModel)
      Handles the player popping the enemy bubble.

      This method calculates the speed and direction of the bubble after it has been popped by the player.

      It sets the bubble's state to DEAD, marks it as popped, and updates the enemy's alive status to false.

      Parameters:
      playerModel - the player model
    • getEnemyModel

      public EnemyModel getEnemyModel()
    • isPlayerPopped

      public boolean isPlayerPopped()