Resolved bottoming out edge cases with collisions. No more empty block bugs.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
Nic0Nic0Nii 3 years ago
parent c542d07708
commit c68177f5f5
  1. BIN
      Meteo_Engine.jar
  2. 4
      src/sig/BlockClump.java
  3. 51
      src/sig/Board.java
  4. 16
      src/sig/CollisionRangeIdentifier.java

Binary file not shown.

@ -72,8 +72,8 @@ public class BlockClump {
g.setColor(new Color(0,255,0,128));
for (int i=0;i<collisionColumnRanges.length;i++) {
if (collisionColumnRanges[i][0]!=-1) {
g.drawRect((int)(x+i*block_width)+originX,(int)(originY-y-(block_height*(collisionColumnRanges[i][1]-collisionColumnRanges[i][0]))),block_width,block_height*(collisionColumnRanges[i][1]-collisionColumnRanges[i][0]+1));
g.drawRect((int)(x+i*block_width)+originX+1,(int)(originY+1-y-(block_height*(collisionColumnRanges[i][1]-collisionColumnRanges[i][0]))),block_width,block_height*(collisionColumnRanges[i][1]-collisionColumnRanges[i][0]+1));
g.drawRect((int)(x+i*block_width)+originX,(int)(originY-y-(block_height*(collisionColumnRanges[i][1]))),block_width,block_height*(collisionColumnRanges[i][1]-collisionColumnRanges[i][0]+1));
g.drawRect((int)(x+i*block_width)+originX+1,(int)(originY+1-y-(block_height*(collisionColumnRanges[i][1]))),block_width,block_height*(collisionColumnRanges[i][1]-collisionColumnRanges[i][0]+1));
}
}
}

@ -63,27 +63,44 @@ public class Board {
DestroyOutsideBlocks(blocks);
if (checkForMatches(blocks)) {continue;}
double FUTURE_FALL_POSITION = blocks.y+blocks.yspd+gravity;
for (int x=0;x<width;x++) {
List<CollisionRangeIdentifier> ranges = new ArrayList<CollisionRangeIdentifier>();
for (int k=0;k<blocks.collisionColumnRanges.length;k++) {
int[] range = blocks.collisionColumnRanges[k];
ranges.add(new CollisionRangeIdentifier(k, range));
}
ranges = ranges.stream().sorted((a,b)->a.range[0]-b.range[0]).collect(Collectors.toList());
//System.out.println(ranges);
for (int l=0;l<ranges.size();l++) {
int x=ranges.get(l).index;
if (blocks.collisionColumnRanges[x][0]!=-1) {
for (int j=0;j<blockData.size();j++) {
BlockClump blocks2 = blockData.get(j);
if (!blocks.equals(blocks2)&&blocks2.collisionColumnRanges[x][1]!=-1) {
if (FUTURE_FALL_POSITION<blocks2.y) {
if (FUTURE_FALL_POSITION+blocks.collisionColumnRanges[x][1]*block_height>blocks2.y+(blocks2.collisionColumnRanges[x][0]+1)*block_height) {
HandleBlockLand(blocks, x, blocks2.y+(blocks2.collisionColumnRanges[x][0]+1)*block_height);
continue outerloop;
}
} else {
if (FUTURE_FALL_POSITION+blocks.collisionColumnRanges[x][0]*block_height<blocks2.y+(blocks2.collisionColumnRanges[x][1]+1)*block_height) {
HandleBlockLand(blocks, x, blocks2.y+(blocks2.collisionColumnRanges[x][1]+1)*block_height);
if (blocks.launched==-1) {
CombineAToB(blocks,blocks2);
blocks.launched=-2;
if (blocks.yspd>0) {
if (blocks2.y+(blocks2.collisionColumnRanges[x][0])*block_height>FUTURE_FALL_POSITION+(blocks.collisionColumnRanges[x][1])*block_height) {
if (FUTURE_FALL_POSITION+(blocks.collisionColumnRanges[x][1])*block_height>blocks2.y+(blocks2.collisionColumnRanges[x][0])*block_height) {
HandleBlockLand(blocks, x, blocks2.y+(blocks2.collisionColumnRanges[x][0])*block_height-blocks.maxBlockHeight*block_height);
continue outerloop;
}
}
} else {
if (FUTURE_FALL_POSITION+(blocks.collisionColumnRanges[x][0])*block_height<=0) { //Handle reaching the ground.
HandleBlockLand(blocks, x, 0);
continue outerloop;
} else
if (blocks2.y<FUTURE_FALL_POSITION+(blocks.collisionColumnRanges[x][0])*block_height) {
if (FUTURE_FALL_POSITION+(blocks.collisionColumnRanges[x][0])*block_height<blocks2.y+(blocks2.collisionColumnRanges[x][1]+1)*block_height) {
HandleBlockLand(blocks, x, blocks2.y+(blocks2.collisionColumnRanges[x][1]+1)*block_height);
System.out.println(ranges);
if (blocks.launched==-1) {
CombineAToB(blocks,blocks2);
blocks.launched=-2;
}
continue outerloop;
}
continue outerloop;
}
}
}
}
}
}
}
}
}
@ -166,7 +183,7 @@ public class Board {
b.y-=minY;
}
blockClumpAddList.add(
new BlockClump(newClumpBlocks, blocks.x, blocks.y+minY*block_height+4, launch_power, width, 120)
new BlockClump(newClumpBlocks, blocks.x, blocks.y+minY*block_height, launch_power, width, 120)
);
}
return markedBlocks.size()>0;

@ -0,0 +1,16 @@
package sig;
import java.util.Arrays;
public class CollisionRangeIdentifier {
int index;
int[] range;
CollisionRangeIdentifier(int index,int[] range) {
this.index=index;
this.range=range;
}
@Override
public String toString() {
return "CollisionRangeIdentifier [index=" + index + ", range=" + Arrays.toString(range) + "]";
}
}
Loading…
Cancel
Save