Added multi ball powerup

This commit is contained in:
BlueNutterfly 2018-11-12 19:15:24 +04:00
parent 4a7c9215dd
commit 4694947a08
3 changed files with 42 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import com.badlogic.gdx.math.Vector2;
import com.me.brickbuster.entity.*; import com.me.brickbuster.entity.*;
import com.me.brickbuster.entity.powerup.GluePowerUp; import com.me.brickbuster.entity.powerup.GluePowerUp;
import com.me.brickbuster.entity.powerup.LongerPaddlePowerUp; import com.me.brickbuster.entity.powerup.LongerPaddlePowerUp;
import com.me.brickbuster.entity.powerup.MultiBallPowerUp;
import com.me.brickbuster.entity.powerup.PowerUp; import com.me.brickbuster.entity.powerup.PowerUp;
import java.util.ArrayList; import java.util.ArrayList;
@ -53,6 +54,9 @@ public class BrickBuster extends ApplicationAdapter {
else if (MathUtils.randomBoolean(0.08f)) { else if (MathUtils.randomBoolean(0.08f)) {
powerUpType = LongerPaddlePowerUp.class; powerUpType = LongerPaddlePowerUp.class;
} }
else if (MathUtils.randomBoolean(0.04f)) {
powerUpType = MultiBallPowerUp.class;
}
bricks.add(new Brick(this, powerUpType, x, HEIGHT - y)); bricks.add(new Brick(this, powerUpType, x, HEIGHT - y));
} }
} }

View File

@ -135,4 +135,12 @@ public class Ball extends Entity {
public boolean isDead() { public boolean isDead() {
return isDead; return isDead;
} }
public void setDirection(Vector2 direction) {
this.direction = direction;
}
public void setStuck(boolean stuck) {
isStuck = stuck;
}
} }

View File

@ -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);
}
}
}