From e2900e3173a89ac5e02ca46e6507211f87f603c4 Mon Sep 17 00:00:00 2001 From: Ashwath V A Date: Wed, 2 Mar 2022 22:33:39 +0530 Subject: [PATCH 1/2] fix #617(iii, iv): Asteroids break into smaller pieces and then into tiny rocks. The smaller pieces also drop loot when destroyed. --- .../rubble/systems/RubbleCreationSystem.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/engine/src/main/java/org/destinationsol/rubble/systems/RubbleCreationSystem.java b/engine/src/main/java/org/destinationsol/rubble/systems/RubbleCreationSystem.java index b4fa242f0..638df0a25 100644 --- a/engine/src/main/java/org/destinationsol/rubble/systems/RubbleCreationSystem.java +++ b/engine/src/main/java/org/destinationsol/rubble/systems/RubbleCreationSystem.java @@ -32,6 +32,7 @@ import org.destinationsol.location.components.Angle; import org.destinationsol.location.components.Position; import org.destinationsol.location.components.Velocity; +import org.destinationsol.moneyDropping.components.DropsMoneyOnDestruction; import org.destinationsol.removal.events.DeletionEvent; import org.destinationsol.removal.systems.DestructionSystem; import org.destinationsol.rendering.RenderableElement; @@ -51,9 +52,9 @@ */ public class RubbleCreationSystem implements EventReceiver { - public static final float SIZE_TO_RUBBLE_COUNT = 13f; - public static final float MIN_SCALE = .07f; - public static final float MAX_SCALE = .12f; + public static final float SIZE_TO_RUBBLE_COUNT = 8f; + public static final float MIN_SCALE = .1f; + public static final float MAX_SCALE = .3f; private static final float MAX_SPD = 40f; @In @@ -115,7 +116,7 @@ private void buildRubblePieces(Position pos, Velocity vel, Angle angle, Size siz element.graphicsOffset = new Vector2(); float scale = SolRandom.randomFloat(MIN_SCALE, MAX_SCALE); - element.setSize(scale); + element.setSize(scale * size.size); element.relativePosition = new Vector2(); element.tint = Color.WHITE; @@ -136,7 +137,7 @@ private void buildRubblePieces(Position pos, Velocity vel, Angle angle, Size siz //Create size component Size sizeComponent = new Size(); - sizeComponent.size = scale; + sizeComponent.size = scale * size.size; //Create velocity component Velocity velocityComponent = new Velocity(); @@ -147,6 +148,11 @@ private void buildRubblePieces(Position pos, Velocity vel, Angle angle, Size siz EntityRef entityRef = entitySystemManager.getEntityManager().createEntity(graphicsComponent, positionComponent, sizeComponent, angle, velocityComponent, new RubbleMesh(), health); + if (sizeComponent.size > 0.1) { + entityRef.setComponent(new CreatesRubbleOnDestruction()); + entityRef.setComponent(new DropsMoneyOnDestruction()); + } + SolMath.free(velocity); entityRef.setComponent(new BodyLinked()); } From 58cbfde3f32855379bba9a85ad42873e8bb8a379 Mon Sep 17 00:00:00 2001 From: Ashwath V A Date: Thu, 3 Mar 2022 06:09:31 +0530 Subject: [PATCH 2/2] Code fixes --- .../rubble/systems/RubbleCreationSystem.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/engine/src/main/java/org/destinationsol/rubble/systems/RubbleCreationSystem.java b/engine/src/main/java/org/destinationsol/rubble/systems/RubbleCreationSystem.java index 638df0a25..f1e53fff4 100644 --- a/engine/src/main/java/org/destinationsol/rubble/systems/RubbleCreationSystem.java +++ b/engine/src/main/java/org/destinationsol/rubble/systems/RubbleCreationSystem.java @@ -53,6 +53,7 @@ public class RubbleCreationSystem implements EventReceiver { public static final float SIZE_TO_RUBBLE_COUNT = 8f; + public static final float MIN_DIVISIBLE_SIZE = .1f; public static final float MIN_SCALE = .1f; public static final float MAX_SCALE = .3f; private static final float MAX_SPD = 40f; @@ -116,7 +117,8 @@ private void buildRubblePieces(Position pos, Velocity vel, Angle angle, Size siz element.graphicsOffset = new Vector2(); float scale = SolRandom.randomFloat(MIN_SCALE, MAX_SCALE); - element.setSize(scale * size.size); + float scaledSize = scale * size.size; + element.setSize(scaledSize); element.relativePosition = new Vector2(); element.tint = Color.WHITE; @@ -126,7 +128,7 @@ private void buildRubblePieces(Position pos, Velocity vel, Angle angle, Size siz //Create position component float velocityAngle = SolRandom.randomFloat(180); Vector2 position = new Vector2(); - SolMath.fromAl(position, velocityAngle, SolRandom.randomFloat(size.size)); + SolMath.fromAl(position, velocityAngle, SolRandom.randomFloat(scaledSize)); position.add(basePos); Position positionComponent = new Position(); positionComponent.position = position; @@ -137,7 +139,7 @@ private void buildRubblePieces(Position pos, Velocity vel, Angle angle, Size siz //Create size component Size sizeComponent = new Size(); - sizeComponent.size = scale * size.size; + sizeComponent.size = scaledSize; //Create velocity component Velocity velocityComponent = new Velocity(); @@ -148,7 +150,7 @@ private void buildRubblePieces(Position pos, Velocity vel, Angle angle, Size siz EntityRef entityRef = entitySystemManager.getEntityManager().createEntity(graphicsComponent, positionComponent, sizeComponent, angle, velocityComponent, new RubbleMesh(), health); - if (sizeComponent.size > 0.1) { + if (scaledSize > MIN_DIVISIBLE_SIZE) { entityRef.setComponent(new CreatesRubbleOnDestruction()); entityRef.setComponent(new DropsMoneyOnDestruction()); }