Refactored block landing functions

concurrentModificationException1
Joshua Sigona 3 years ago
parent b2d2701c9a
commit af8c5ce854
  1. BIN
      Meteo_Engine.jar
  2. 7
      src/sig/BlockClump.java
  3. 5
      src/sig/BlockClumpState.java
  4. 38
      src/sig/Board.java

Binary file not shown.

@ -10,8 +10,10 @@ public class BlockClump {
double x,y; //the lower-left origin of this block clump. Every block positions relative to this. double x,y; //the lower-left origin of this block clump. Every block positions relative to this.
double yspd; double yspd;
int[][] collisionColumnRanges; int[][] collisionColumnRanges;
boolean launched=false; //Blocks do not fall when landing (by gravity). int launched = -1; /*
boolean re_sort=false; //Set to true when block clumps are divided into smaller columns for re-sorting. Negative is for when block clumps are divided into smaller columns for re-sorting.
Positive is used for how much landing launch time before being split and falling.*/
public BlockClump(List<Block> blockList, double x, double y, double startspd, int width) { public BlockClump(List<Block> blockList, double x, double y, double startspd, int width) {
this.blocks = new ArrayList<Block>(); this.blocks = new ArrayList<Block>();
this.blocks.addAll(blockList); this.blocks.addAll(blockList);
@ -25,7 +27,6 @@ public class BlockClump {
this.x=x; this.x=x;
this.y=y; this.y=y;
this.yspd=startspd; this.yspd=startspd;
System.out.println(Arrays.deepToString(collisionColumnRanges));
} }
public void updateBlockCollision() { public void updateBlockCollision() {
//Call this whenever the block structure changes. This will define what the top and bottom positions //Call this whenever the block structure changes. This will define what the top and bottom positions

@ -0,0 +1,5 @@
package sig;
public enum BlockClumpState {
}

@ -59,46 +59,44 @@ public class Board {
blockData.add(new BlockClump(Arrays.asList(new Block((int)(Math.random()*width),0)),0,590,0,width)); blockData.add(new BlockClump(Arrays.asList(new Block((int)(Math.random()*width),0)),0,590,0,width));
} }
outerloop:
for (BlockClump blocks : blockData) { for (BlockClump blocks : blockData) {
double FUTURE_FALL_POSITION = blocks.y+blocks.yspd+gravity; double FUTURE_FALL_POSITION = blocks.y+blocks.yspd+gravity;
boolean landed=false;
outerloop:
for (int x=0;x<width;x++) { for (int x=0;x<width;x++) {
if (blocks.collisionColumnRanges[x][0]!=-1) { if (blocks.collisionColumnRanges[x][0]!=-1) {
for (BlockClump blocks2 : blockData) { for (BlockClump blocks2 : blockData) {
if (!blocks.equals(blocks2)&&blocks2.collisionColumnRanges[x][1]!=-1) { if (!blocks.equals(blocks2)&&blocks2.collisionColumnRanges[x][1]!=-1) {
if (FUTURE_FALL_POSITION<blocks2.y) { 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) { if (FUTURE_FALL_POSITION+blocks.collisionColumnRanges[x][1]*block_height>blocks2.y+(blocks2.collisionColumnRanges[x][0]+1)*block_height) {
blocks.yspd=0; HandleBlockLand(blocks, x, blocks2.y+(blocks2.collisionColumnRanges[x][0]+1)*block_height);
blocks.y=blocks2.y+(blocks2.collisionColumnRanges[x][0]+1)*block_height; continue outerloop;
landed=true;
break outerloop;
} }
} else { } else {
if (FUTURE_FALL_POSITION+blocks.collisionColumnRanges[x][0]*block_height<blocks2.y+(blocks2.collisionColumnRanges[x][1]+1)*block_height) { if (FUTURE_FALL_POSITION+blocks.collisionColumnRanges[x][0]*block_height<blocks2.y+(blocks2.collisionColumnRanges[x][1]+1)*block_height) {
blocks.yspd=0; HandleBlockLand(blocks, x, blocks2.y+(blocks2.collisionColumnRanges[x][1]+1)*block_height);
blocks.y=blocks2.y+(blocks2.collisionColumnRanges[x][1]+1)*block_height; continue outerloop;
landed=true;
break outerloop;
} }
} }
} }
} }
} }
} }
if (!landed) { if (FUTURE_FALL_POSITION>0) {
if (FUTURE_FALL_POSITION>0) { blocks.yspd=Math.max(blocks.yspd+gravity,max_fall_spd);
blocks.yspd=Math.max(blocks.yspd+gravity,max_fall_spd); blocks.y+=blocks.yspd;
blocks.y+=blocks.yspd; } else {
} else { //We have hit the bottom.
//We have hit the bottom. blocks.yspd=0;
blocks.yspd=0; blocks.y=0;
blocks.y=0; }
}
}
//System.out.println(blocks.y); //System.out.println(blocks.y);
} }
} }
private void HandleBlockLand(BlockClump blocks, int x, double yset) {
blocks.yspd=0;
blocks.y=yset;
}
public void drawBoard(Graphics g) { public void drawBoard(Graphics g) {
final int DRAW_STARTX = (int)(x - block_width*((double)width/2)); final int DRAW_STARTX = (int)(x - block_width*((double)width/2));
final int DRAW_STARTY = (int)(y + block_height*((double)height/2)); final int DRAW_STARTY = (int)(y + block_height*((double)height/2));

Loading…
Cancel
Save