Package model.bubbles

Class BubbleModel

java.lang.Object
model.entities.EntityModel
model.bubbles.BubbleModel
Direct Known Subclasses:
PlayerBubbleModel, SpecialBubbleModel

public abstract class BubbleModel extends EntityModel
Represents a bubble created by the player.

This abstract class provides the basic structure and behavior for bubbles created by the player. It includes methods for updating the bubble's state, handling collisions with the player, and managing timers.

  • Field Details

    • levelManagerModel

      protected final LevelManagerModel levelManagerModel
    • timer

      protected final PlayingTimer timer
    • internalCollisionBox

      protected Rectangle2D.Float internalCollisionBox
    • externalCollisionBox

      protected Ellipse2D.Float externalCollisionBox
    • active

      protected boolean active
    • popped

      protected boolean popped
    • bubbleType

      protected Constants.Bubble.BubbleType bubbleType
    • state

      protected int state
    • previousState

      protected int previousState
    • normalTimer

      protected int normalTimer
    • redTimer

      protected int redTimer
    • blinkingTimer

      protected int blinkingTimer
    • popTimer

      protected int popTimer
    • shakeTimer

      protected int shakeTimer
    • shake

      protected boolean shake
    • xSpeed

      protected float xSpeed
    • ySpeed

      protected float ySpeed
    • direction

      protected Constants.Direction direction
    • previousDirection

      protected Constants.Direction previousDirection
  • Constructor Details

    • BubbleModel

      public BubbleModel(float x, float y, Constants.Direction direction)
      Constructs a new BubbleModel.
      Parameters:
      x - the starting x coordinate
      y - the starting y coordinate
      direction - the starting direction
  • Method Details

    • update

      public abstract void update()
      Updates the bubble model.
    • checkCollisionWithPlayer

      public abstract void checkCollisionWithPlayer(PlayerModel playerModel)
      Checks for collision with the player invalid input: '&' contains the logic to handle the collisions.
      Parameters:
      playerModel - the player model
    • initCollisionBoxes

      protected void initCollisionBoxes()
    • updateTimers

      protected void updateTimers()
      Updates the timers.
    • updateCollisionBoxes

      protected void updateCollisionBoxes()
      Updates the hitbox of the collision boxes to align them with bubble position.
    • updateDirection

      protected void updateDirection()
      Updates the direction of the bubble based on the current wind direction data from the level manager.

      If the bubble is outside the map, the direction is not updated.

      If the current direction is not NONE, the previous direction is updated to the current direction.

      The new direction is then set based on the wind direction data at the bubble's current tile position.

    • updatePosition

      protected void updatePosition()
      Updates the position of the bubble based on its current state and direction.

      If the bubble is not popped it calculates the x and y speeds based oni the wind direction and updates the bubble's position accordingly.

      If the direction is NONE, the bubble will shake in place.

    • pacManEffect

      protected void pacManEffect()
      Applies the Pac-Man effect to the bubble, allowing it to wrap around the screen vertically.

      If the bubble moves beyond the bottom of the screen, it reappears at the top.

      If the bubble moves beyond the top of the screen, it reappears at the bottom.

    • bounceDown

      public void bounceDown()
      Makes the bubble bounce down when the player jumps on it.

      This method is called when the player jumps on the bubble, causing the bubble to move downwards by a small amount.

    • bubbleShaking

      protected void bubbleShaking()
      Makes the bubble shake in place when the wind direction is NONE.

      The shaking direction is determined by the previous direction of the bubble.

      If the previous direction was UP or DOWN, the bubble will shake vertically.

      If the previous direction was LEFT or RIGHT, the bubble will shake horizontally.

      The shaking speed alternates based on the shake state.

    • isPlayerPoppingBubble

      protected boolean isPlayerPoppingBubble(PlayerModel playerModel)
      Checks if the player is popping the bubble.

      If the player is colliding with the internal collision box of the bubble, the bubble is considered popped.

      Parameters:
      playerModel - the player model
      Returns:
      true if the player is colliding with the internal collision box of the bubble, false otherwise
    • isPlayerJumpingOnBubble

      protected boolean isPlayerJumpingOnBubble(PlayerModel playerModel)
      Checks if the player is jumping on the bubble.

      This method determines if the player is currently jumping on the bubble by comparing the y-coordinate of the bubble's hitbox with the player's hitbox and checking if the player's jump is active.

      Parameters:
      playerModel - the player model
      Returns:
      true if the player is jumping on the bubble, false otherwise
    • isPlayerTouchingBubble

      protected boolean isPlayerTouchingBubble(PlayerModel playerModel)
      Checks if the player is touching the bubble.

      This method determines if the player is currently touching the bubble by checking if the player's hitbox intersects with the bubble's external collision box.

      Parameters:
      playerModel - the player model
      Returns:
      true if the player's hitbox intersects with the bubble's external collision box, false otherwise
    • handlePlayerPush

      protected void handlePlayerPush(PlayerModel playerModel)
      Handles the player's push interaction with the bubble.

      This method adjusts the bubble's position based on the player's push direction.

      If the player is pushing from the left, the bubble moves to the left.

      If the player is pushing from the right, the bubble moves to the right.

      Parameters:
      playerModel - the player model
    • getCenter

      public Point getCenter()
      Gets the center point of the bubble's hitbox.

      This method calculates the center coordinates of the bubble's hitbox and returns them as a Point object.

      Returns:
      the center point of the bubble's hitbox
    • changeDirection

      protected void changeDirection()
      Changes the direction of the bubble, to the opposite of the current direction.
    • setActive

      public void setActive(boolean active)
      Description copied from class: EntityModel
      Sets the active status of the entity.
      Overrides:
      setActive in class EntityModel
      Parameters:
      active - the new active status to set
    • isActive

      public boolean isActive()
      Description copied from class: EntityModel
      Returns the active status of the entity.
      Overrides:
      isActive in class EntityModel
      Returns:
      true if the entity is active, false otherwise
    • getState

      public int getState()
    • getDirection

      public Constants.Direction getDirection()
    • isPopped

      public boolean isPopped()
    • getBubbleType

      public Constants.Bubble.BubbleType getBubbleType()