|
@@ -27,7 +27,6 @@ public class HolonCanvas extends JPanel {
|
|
|
|
|
|
|
|
|
private ArrayList<HolonBody> bodies = new ArrayList<>();
|
|
|
- private HolonBody currentBall;
|
|
|
private int subCount;
|
|
|
|
|
|
|
|
@@ -64,8 +63,14 @@ public class HolonCanvas extends JPanel {
|
|
|
if (!controller.getSimManager().getSubNets().equals(subnets)) {
|
|
|
subnets = controller.getSimManager().getSubNets();
|
|
|
subCount = subnets.size();
|
|
|
- bodies = new ArrayList<>();
|
|
|
- createBodies(subCount);
|
|
|
+
|
|
|
+
|
|
|
+ calcCenter();
|
|
|
+ if (bodies.isEmpty()) {
|
|
|
+ createBodies(subCount);
|
|
|
+ } else {
|
|
|
+ addNewBodies(subCount);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
currentTime = System.currentTimeMillis();
|
|
@@ -93,12 +98,37 @@ public class HolonCanvas extends JPanel {
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private void createBodies(int subCount) {
|
|
|
- calcCenter();
|
|
|
+
|
|
|
+ private void addNewBodies(int subCount) {
|
|
|
|
|
|
- for(int i = 0; i<subCount; i++){
|
|
|
- HolonBody temp = new HolonBody(center.width+i, center.height+i, subnets.get(i).getObjects().size()*5+10, subnets.get(i).getObjects().size()*5+10, model.getSubNetColors().get(i));
|
|
|
+ ArrayList<HolonBody> newBodies = new ArrayList<>();
|
|
|
+ for (int i = 0; i < bodies.size(); i++) {
|
|
|
+ for (int j = 0; j < subCount; j++) {
|
|
|
+ if (model.getSubNetColors().get(j) == bodies.get(i).getColor()) {
|
|
|
+ bodies.get(i).setRadius(subnets.get(j).getObjects().size() * 5 + 10);
|
|
|
+ bodies.get(i).setMass(subnets.get(j).getObjects().size() * 5 + 10);
|
|
|
+ newBodies.add(bodies.get(i));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ bodies = newBodies;
|
|
|
+ for (int i = bodies.size(); i < subCount; i++) {
|
|
|
+ HolonBody temp = new HolonBody((center.width + 1) + (-1 * i), (center.height + 1) + (-1 * i),
|
|
|
+ subnets.get(i).getObjects().size() * 5 + 10, subnets.get(i).getObjects().size() * 5 + 10,
|
|
|
+ model.getSubNetColors().get(i));
|
|
|
+ bodies.add(temp);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void createBodies(int subCount) {
|
|
|
+ for (int i = 0; i < subCount; i++) {
|
|
|
+ HolonBody temp = new HolonBody((center.width + 1) + (-1 * i), (center.height + 1) + (-1 * i),
|
|
|
+ subnets.get(i).getObjects().size() * 5 + 10, subnets.get(i).getObjects().size() * 5 + 10,
|
|
|
+ model.getSubNetColors().get(i));
|
|
|
bodies.add(temp);
|
|
|
}
|
|
|
}
|
|
@@ -118,13 +148,9 @@ public class HolonCanvas extends JPanel {
|
|
|
|
|
|
|
|
|
for (int i = 0; i < subCount; i++) {
|
|
|
- bodies.get(i).draw(this.g2);
|
|
|
+ bodies.get(i).setRadius((subnets.get(i).getObjects().size() * 5 + 10)*controller.getHolonBodyScale()/100);
|
|
|
+ bodies.get(i).draw(this.g2, controller.getHolonBodyScale());
|
|
|
}
|
|
|
-
|
|
|
- HolonBody tempBall = currentBall;
|
|
|
- if (tempBall != null)
|
|
|
- tempBall.draw(this.g2);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public void updateGame(float elapsedSeconds) {
|
|
@@ -133,10 +159,12 @@ public class HolonCanvas extends JPanel {
|
|
|
|
|
|
calcCenter();
|
|
|
for (int i = 0; i < subCount; i++) {
|
|
|
- bodies.get(i).position.setX((float) (bodies.get(i).position.getX() + (bodies.get(i).velocity.getX() * (elapsedSeconds))
|
|
|
- - ((bodies.get(i).position.getX() - center.getWidth()) / 50)));
|
|
|
- bodies.get(i).position.setY((float) (bodies.get(i).position.getY() + (bodies.get(i).velocity.getY() * (elapsedSeconds))
|
|
|
- - ((bodies.get(i).position.getY() - center.getHeight()) / 50)));
|
|
|
+ bodies.get(i).position
|
|
|
+ .setX((float) (bodies.get(i).position.getX() + (bodies.get(i).velocity.getX() * (elapsedSeconds))
|
|
|
+ - ((bodies.get(i).position.getX() - center.getWidth()) / 100)));
|
|
|
+ bodies.get(i).position
|
|
|
+ .setY((float) (bodies.get(i).position.getY() + (bodies.get(i).velocity.getY() * (elapsedSeconds))
|
|
|
+ - ((bodies.get(i).position.getY() - center.getHeight()) / 100)));
|
|
|
|
|
|
if (Math.abs(bodies.get(i).velocity.getX()) < Constants.epsilon)
|
|
|
bodies.get(i).velocity.setX(0);
|
|
@@ -165,7 +193,7 @@ public class HolonCanvas extends JPanel {
|
|
|
public void checkCollisions() {
|
|
|
insertionSort(bodies);
|
|
|
|
|
|
- for (int i = 0; i < subCount; i++) {
|
|
|
+ for (int i = 0; i < subCount; i++) {
|
|
|
|
|
|
for (int j = i + 1; j < subCount; j++) {
|
|
|
if ((bodies.get(i).position.getX() + bodies.get(i).getRadius()) < (bodies.get(j).position.getX()
|