package jbrickbreaker.model.bonuses;
import java.awt.Color;
import java.awt.geom.Point2D;
import java.util.*;
import jbrickbreaker.model.Ball;
import jbrickbreaker.model.Game;
/**
* This class represents a bonus that brings up several ball
* in the game.
*
* @author Maxime Reymond
*
*/
public class MultipleBallBonus extends Bonus {
public MultipleBallBonus(int x, int y) {
super(x, y, Color.MAGENTA);
}
@Override
public void execute(Game g) {
double[][] bla = new double[Ball.NB_MAX_BALLS][2];
double alpha = 2*Math.PI/Ball.NB_MAX_BALLS;
for (int i = 0; i < bla.length; i++) {
bla[i][0] = Math.sin(i*alpha);
bla[i][1] = Math.cos(i*alpha);
}
List<Ball> aB = g.getBalls();
int nb = Ball.NB_MAX_BALLS - aB.size();
double bX = aB.get(0).getCenterX();
double bY = aB.get(0).getCenterY();
for (int i = 0; i < nb; i++) {
Ball b = new Ball(bX, bY);
Point2D sB = b.getSpeed();
Point2D speed = new Point2D.Double(bla[i][0]*sB.getY(),bla[i][1]*sB.getX());
b.setSpeed(speed);
g.addBall(b);
}
g.getPlayer().removeStuckBonus();
g.unstuckBalls();
}
@Override
public String getName() {
return "Mu"; //$NON-NLS-1$
}
}