Spawn additional balls at point of existing balls
This commit is contained in:
parent
d32cccebd6
commit
b1db9c7048
@ -177,4 +177,8 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
|
||||
return isStuck;
|
||||
}
|
||||
|
||||
public void setStuck(boolean isStuck) {
|
||||
this.isStuck = isStuck;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public abstract class Entity {
|
||||
}
|
||||
|
||||
public void setPos(Vector2 pos) {
|
||||
this.pos = pos;
|
||||
this.pos.set(pos);
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
|
@ -3,6 +3,7 @@ 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.badlogic.gdx.utils.Array;
|
||||
import com.me.brickbuster.entity.Ball;
|
||||
import com.me.brickbuster.entity.Paddle;
|
||||
import com.me.brickbuster.state.PlayState;
|
||||
@ -10,6 +11,7 @@ import com.me.brickbuster.state.PlayState;
|
||||
public class MultiBallPowerUp extends PowerUp {
|
||||
|
||||
private Vector2 pos;
|
||||
private static final Array<Ball> ballsToAdd = new Array<Ball>();
|
||||
|
||||
public MultiBallPowerUp(PlayState state, Vector2 brick, Color color) {
|
||||
super(state, brick, color);
|
||||
@ -18,10 +20,26 @@ public class MultiBallPowerUp extends PowerUp {
|
||||
|
||||
@Override
|
||||
public void activate() {
|
||||
for (int x = 0; x < 2; x++) {
|
||||
Ball ball = new Ball((PlayState) state);
|
||||
ball.launch();
|
||||
((PlayState) state).balls.add(ball);
|
||||
final Array<Ball> existing = ((PlayState) state).balls;
|
||||
if (existing.size >= 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Ball b : existing) {
|
||||
Vector2 velocity = b.getBody().getLinearVelocity();
|
||||
velocity.setAngleRad(velocity.angleRad() - MathUtils.PI/8);
|
||||
|
||||
for (int x = 0; x < 2; x++) {
|
||||
Ball ball = new Ball((PlayState) state);
|
||||
ball.setX(b.getX());
|
||||
ball.setY(b.getY());
|
||||
ball.setStuck(false);
|
||||
ball.getBody().setLinearVelocity(velocity);
|
||||
ballsToAdd.add(ball);
|
||||
velocity.setAngleRad(velocity.angleRad() + MathUtils.PI/4);
|
||||
}
|
||||
}
|
||||
existing.addAll(ballsToAdd);
|
||||
ballsToAdd.clear();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user