Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: AnsonKindred/poomonkeys-common
base: 90b0206b5c
...
head fork: AnsonKindred/poomonkeys-common
compare: 1145ba88d7
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Sep 28, 2012
= Got some shit working 1145ba8
Showing with 78 additions and 39 deletions.
  1. +78 −39 src/poomonkeys/common/ExplosionController.java
View
117 src/poomonkeys/common/ExplosionController.java
@@ -2,7 +2,8 @@
import java.util.ArrayList;
-public class ExplosionController extends Thread {
+public class ExplosionController extends Thread
+{
ArrayList<ArrayList<Dirt>> explosions = new ArrayList<ArrayList<Dirt>>();
Terrain t;
@@ -10,19 +11,23 @@
static ExplosionController instance = null;
- public static ExplosionController getInstance() {
- if (instance == null) {
+ public static ExplosionController getInstance()
+ {
+ if (instance == null)
+ {
instance = new ExplosionController();
}
return instance;
}
- public void init(Terrain t) {
+ public void init(Terrain t)
+ {
this.t = t;
}
// x and y are relative to the bottom left of the terrain
- public void explode(float x, float y, float r) {
+ public void explode(float x, float y, float r)
+ {
// Helpful square at click point
Dirt test = new Dirt();
test.x = x;
@@ -35,17 +40,22 @@ public void explode(float x, float y, float r) {
int min_index = (int) ((x - r) / t.segmentWidth) + 1;
int max_index = (int) ((x + r) / t.segmentWidth);
- if (max_index > t.NUM_POINTS - 1) {
+ if (max_index > t.NUM_POINTS - 1)
+ {
max_index = t.NUM_POINTS - 1;
}
- if (min_index < 0) {
+ if (min_index < 0)
+ {
min_index = 0;
}
// The actual x value at the min and max indexes
float minX = min_index * t.segmentWidth;
float maxX = max_index * t.segmentWidth;
-
+ System.out.println("min_index "+min_index);
+ System.out.println("max_index "+max_index);
+ System.out.println("minX "+minX);
+ System.out.println("maxX "+maxX);
ArrayList<Dirt> dirt;
float totalDirtVolume = 0;
@@ -54,7 +64,8 @@ public void explode(float x, float y, float r) {
// Assign a portion of the removed dirt volume to each dirt point
float individualDirtVolume = totalDirtVolume / dirt.size();
- for (int d = 0; d < dirt.size(); d++) {
+ for (int d = 0; d < dirt.size(); d++)
+ {
dirt.get(d).volume = individualDirtVolume;
}
@@ -62,7 +73,8 @@ public void explode(float x, float y, float r) {
explosions.add(dirt);
// Start the animation process if it isn't running
- if (!this.isAlive()) {
+ if (!this.isAlive())
+ {
this.start();
}
}
@@ -70,11 +82,12 @@ public void explode(float x, float y, float r) {
/*
* Sets terrain heights to the bottom of the explosion circle
*/
- private float _collapseTerrain(int min_index, int max_index, float x,
- float y, float r) {
+ private float _collapseTerrain(int min_index, int max_index, float x, float y, float r)
+ {
float dirtVolume = 0;
- for (int i = min_index; i <= max_index; i++) {
+ for (int i = min_index; i <= max_index; i++)
+ {
float xFromI = i * t.segmentWidth;
float offset = (float) Math.sqrt(r * r - Math.pow(xFromI - x, 2));
float tCircleY = (float) (offset + y);
@@ -83,8 +96,10 @@ private float _collapseTerrain(int min_index, int max_index, float x,
// checks if the land is above the bottom of the circle, otherwise
// don't mess with it.
- if (t.points[i] > bCircleY) {
- if (t.points[i] > tCircleY) {
+ if (t.points[i] > bCircleY)
+ {
+ if (t.points[i] > tCircleY)
+ {
dirtVolume += t.points[i] - tCircleY;
}
@@ -97,26 +112,42 @@ private float _collapseTerrain(int min_index, int max_index, float x,
return dirtVolume;
}
- private ArrayList<Dirt> _generateDirtpoints(float minX, float maxX,
- float x, float y, float r) {
+ private ArrayList<Dirt> _generateDirtpoints(float minX, float maxX, float x, float y, float r)
+ {
ArrayList<Dirt> dirt = new ArrayList<Dirt>();
float explosion_width = Math.abs(maxX - minX);
+ System.out.println("Explosion width " + explosion_width);
int num_dirt_columns = (int) ((explosion_width + t.segmentWidth) / (2 * DIRT_SIZE));
+ System.out.println("Dirt columns " + num_dirt_columns);
float gapTotal = (explosion_width + t.segmentWidth) % (2 * DIRT_SIZE);
+ System.out.println("gap total " + gapTotal);
float gap = gapTotal / num_dirt_columns;
- for (float col_x = minX - t.segmentWidth / 2; col_x <= maxX + t.segmentWidth / 2 + gap / 2; col_x += DIRT_SIZE
- * 2 + gap) {
-
+ System.out.println("gap " + gap);
+ System.out.println();
+ float col_x = minX - t.segmentWidth/2 + gap/2 + DIRT_SIZE;
+ float end_x = maxX + t.segmentWidth/2 - gap/2 - DIRT_SIZE;
+ float EPSILON = .0001f;
+ for (; col_x <= end_x + EPSILON; col_x += DIRT_SIZE * 2 + gap)
+ {
_generateDirtColumn(col_x, x, y, r, gap, dirt);
}
return dirt;
}
- private float _generateDirtColumn(float col_x, float x, float y, float r,
- float gap, ArrayList<Dirt> dirt) {
- float offset = (float) Math.sqrt(r * r - Math.pow(col_x - x, 2));
+ private float _generateDirtColumn(float col_x, float x, float y, float r, float gap, ArrayList<Dirt> dirt)
+ {
+ float thing = (float) (r * r - Math.pow(col_x - x, 2));
+ float offset = 0;
+ if(thing > 0)
+ {
+ offset = (float) Math.sqrt(thing);
+ }
+ else
+ {
+ offset = 0;
+ }
float tCircleY = (float) (offset + y);
int iFromX = (int) (col_x / t.segmentWidth);
@@ -125,9 +156,11 @@ private float _generateDirtColumn(float col_x, float x, float y, float r,
float p1y = t.points[iFromX];
float p2y = t.points[iFromX + 1];
float top = p1y + (p2y - p1y) * xPercent;
- if (top > tCircleY) {
+ if (top > tCircleY)
+ {
float d = 0;
- while (tCircleY + d <= top) {
+ while (tCircleY + d <= top)
+ {
Dirt dirtPoint = new Dirt();
dirtPoint.x = col_x;
dirtPoint.y = tCircleY + d;
@@ -145,26 +178,30 @@ private float _generateDirtColumn(float col_x, float x, float y, float r,
/**
* Animates the dirt points and handles adding them back to the terrain
*/
- public void run() {
- while (!explosions.isEmpty()) {
- for (int e = 0; e < explosions.size(); e++) {
+ public void run()
+ {
+ while (!explosions.isEmpty())
+ {
+ for (int e = 0; e < explosions.size(); e++)
+ {
ArrayList<Dirt> dirt = explosions.get(e);
- for (int i = 0; i < dirt.size(); i++) {
+ for (int i = 0; i < dirt.size(); i++)
+ {
Dirt d = dirt.get(i);
d.vy += -.01;
d.x += d.vx;
d.y += d.vy;
int iFromX = (int) (d.x / t.segmentWidth);
- double percent = 1 - (d.x % t.segmentWidth)
- / t.segmentWidth;
- double landYatX = t.points[iFromX]
- + (t.points[iFromX + 1] - t.points[iFromX])
- * percent;
- if (d.y < landYatX) {
- if (t.points[iFromX + 1] < t.points[iFromX]) {
+ double percent = 1 - (d.x % t.segmentWidth) / t.segmentWidth;
+ double landYatX = t.points[iFromX] + (t.points[iFromX + 1] - t.points[iFromX]) * percent;
+ if (d.y < landYatX)
+ {
+ if (t.points[iFromX + 1] < t.points[iFromX])
+ {
t.points[iFromX + 1] += d.volume;
- } else {
+ } else
+ {
t.points[iFromX] += d.volume;
}
t.unregisterDrawable(d);
@@ -177,9 +214,11 @@ public void run() {
t.buildGeometry(t.width, t.height);
t.finalizeGeometry();
- try {
+ try
+ {
Thread.currentThread().sleep(159999);
- } catch (InterruptedException e) {
+ } catch (InterruptedException e)
+ {
e.printStackTrace();
}
}

No commit comments for this range

Something went wrong with that request. Please try again.