Class BubbleModel
- Direct Known Subclasses:
PlayerBubbleModel,SpecialBubbleModel
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 Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected intprotected Constants.Bubble.BubbleTypeprotected Constants.Directionprotected Ellipse2D.Floatprotected Rectangle2D.Floatprotected final LevelManagerModelprotected intprotected booleanprotected intprotected Constants.Directionprotected intprotected intprotected booleanprotected intprotected intprotected final PlayingTimerprotected floatprotected float -
Constructor Summary
ConstructorsConstructorDescriptionBubbleModel(float x, float y, Constants.Direction direction) Constructs a new BubbleModel. -
Method Summary
Modifier and TypeMethodDescriptionvoidMakes the bubble bounce down when the player jumps on it.protected voidMakes the bubble shake in place when the wind direction is NONE.protected voidChanges the direction of the bubble, to the opposite of the current direction.abstract voidcheckCollisionWithPlayer(PlayerModel playerModel) Checks for collision with the player invalid input: '&' contains the logic to handle the collisions.Gets the center point of the bubble's hitbox.intgetState()protected voidhandlePlayerPush(PlayerModel playerModel) Handles the player's push interaction with the bubble.protected voidbooleanisActive()Returns the active status of the entity.protected booleanisPlayerJumpingOnBubble(PlayerModel playerModel) Checks if the player is jumping on the bubble.protected booleanisPlayerPoppingBubble(PlayerModel playerModel) Checks if the player is popping the bubble.protected booleanisPlayerTouchingBubble(PlayerModel playerModel) Checks if the player is touching the bubble.booleanisPopped()protected voidApplies the Pac-Man effect to the bubble, allowing it to wrap around the screen vertically.voidsetActive(boolean active) Sets the active status of the entity.abstract voidupdate()Updates the bubble model.protected voidUpdates the hitbox of the collision boxes to align them with bubble position.protected voidUpdates the direction of the bubble based on the current wind direction data from the level manager.protected voidUpdates the position of the bubble based on its current state and direction.protected voidUpdates the timers.Methods inherited from class model.entities.EntityModel
conpenetrationSafeUpdateXPos, deactivate, getHitbox, getTileX, getTileY, initHitbox, initLevelManager, isImmune, updateXPos
-
Field Details
-
levelManagerModel
-
timer
-
internalCollisionBox
-
externalCollisionBox
-
active
protected boolean active -
popped
protected boolean popped -
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
-
previousDirection
-
-
Constructor Details
-
BubbleModel
Constructs a new BubbleModel.- Parameters:
x- the starting x coordinatey- the starting y coordinatedirection- the starting direction
-
-
Method Details
-
update
public abstract void update()Updates the bubble model. -
checkCollisionWithPlayer
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
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
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
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
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
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:EntityModelSets the active status of the entity.- Overrides:
setActivein classEntityModel- Parameters:
active- the new active status to set
-
isActive
public boolean isActive()Description copied from class:EntityModelReturns the active status of the entity.- Overrides:
isActivein classEntityModel- Returns:
- true if the entity is active, false otherwise
-
getState
public int getState() -
getDirection
-
isPopped
public boolean isPopped() -
getBubbleType
-