diff --git a/core/src/com/me/brickbuster/BrickBuster.java b/core/src/com/me/brickbuster/BrickBuster.java index e2d1410..b50d3a5 100644 --- a/core/src/com/me/brickbuster/BrickBuster.java +++ b/core/src/com/me/brickbuster/BrickBuster.java @@ -10,6 +10,7 @@ import com.badlogic.gdx.math.Vector2; import com.me.brickbuster.entity.*; import com.me.brickbuster.entity.powerup.GluePowerUp; import com.me.brickbuster.entity.powerup.LongerPaddlePowerUp; +import com.me.brickbuster.entity.powerup.MultiBallPowerUp; import com.me.brickbuster.entity.powerup.PowerUp; import java.util.ArrayList; @@ -53,6 +54,9 @@ public class BrickBuster extends ApplicationAdapter { else if (MathUtils.randomBoolean(0.08f)) { powerUpType = LongerPaddlePowerUp.class; } + else if (MathUtils.randomBoolean(0.04f)) { + powerUpType = MultiBallPowerUp.class; + } bricks.add(new Brick(this, powerUpType, x, HEIGHT - y)); } } diff --git a/core/src/com/me/brickbuster/entity/Ball.java b/core/src/com/me/brickbuster/entity/Ball.java index 9ea847c..5bb4b40 100644 --- a/core/src/com/me/brickbuster/entity/Ball.java +++ b/core/src/com/me/brickbuster/entity/Ball.java @@ -135,4 +135,12 @@ public class Ball extends Entity { public boolean isDead() { return isDead; } + + public void setDirection(Vector2 direction) { + this.direction = direction; + } + + public void setStuck(boolean stuck) { + isStuck = stuck; + } } diff --git a/core/src/com/me/brickbuster/entity/powerup/MultiBallPowerUp.java b/core/src/com/me/brickbuster/entity/powerup/MultiBallPowerUp.java new file mode 100644 index 0000000..4a91caa --- /dev/null +++ b/core/src/com/me/brickbuster/entity/powerup/MultiBallPowerUp.java @@ -0,0 +1,30 @@ +package com.me.brickbuster.entity.powerup; + +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.math.MathUtils; +import com.badlogic.gdx.math.Vector2; +import com.me.brickbuster.BrickBuster; +import com.me.brickbuster.entity.Ball; +import com.me.brickbuster.entity.Brick; + +public class MultiBallPowerUp extends PowerUp { + + private Vector2 pos; + + public MultiBallPowerUp(BrickBuster brickBuster, Brick brick) { + super(brickBuster, brick, Color.ROYAL); + this.pos = getPos().cpy(); + } + + @Override + public void activate() { + for (int x = 0; x < 2; x++) { + Ball ball = new Ball(getBrickBuster()); + ball.setPos(pos.cpy()); + float angle = MathUtils.random(MathUtils.PI*2); + ball.setDirection(new Vector2(MathUtils.cos(angle), MathUtils.sin(angle))); + ball.setStuck(false); + getBrickBuster().getBalls().add(ball); + } + } +}