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. 40
      src/sig/Board.java
  5. 2
      src/sig/Meteo.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 yspd;
int[][] collisionColumnRanges;
boolean launched=false; //Blocks do not fall when landing (by gravity).
boolean re_sort=false; //Set to true when block clumps are divided into smaller columns for re-sorting.
int launched = -1; /*
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) {
this.blocks = new ArrayList<Block>();
this.blocks.addAll(blockList);
@ -25,7 +27,6 @@ public class BlockClump {
this.x=x;
this.y=y;
this.yspd=startspd;
System.out.println(Arrays.deepToString(collisionColumnRanges));
}
public void updateBlockCollision() {
//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 {
}

@ -58,47 +58,45 @@ public class Board {
if (frames%100==0) {
blockData.add(new BlockClump(Arrays.asList(new Block((int)(Math.random()*width),0)),0,590,0,width));
}
outerloop:
for (BlockClump blocks : blockData) {
double FUTURE_FALL_POSITION = blocks.y+blocks.yspd+gravity;
boolean landed=false;
outerloop:
for (int x=0;x<width;x++) {
if (blocks.collisionColumnRanges[x][0]!=-1) {
for (BlockClump blocks2 : blockData) {
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) {
blocks.yspd=0;
blocks.y=blocks2.y+(blocks2.collisionColumnRanges[x][0]+1)*block_height;
landed=true;
break outerloop;
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) {
blocks.yspd=0;
blocks.y=blocks2.y+(blocks2.collisionColumnRanges[x][1]+1)*block_height;
landed=true;
break outerloop;
HandleBlockLand(blocks, x, blocks2.y+(blocks2.collisionColumnRanges[x][1]+1)*block_height);
continue outerloop;
}
}
}
}
}
}
if (!landed) {
if (FUTURE_FALL_POSITION>0) {
blocks.yspd=Math.max(blocks.yspd+gravity,max_fall_spd);
blocks.y+=blocks.yspd;
} else {
//We have hit the bottom.
blocks.yspd=0;
blocks.y=0;
}
}
if (FUTURE_FALL_POSITION>0) {
blocks.yspd=Math.max(blocks.yspd+gravity,max_fall_spd);
blocks.y+=blocks.yspd;
} else {
//We have hit the bottom.
blocks.yspd=0;
blocks.y=0;
}
//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) {
final int DRAW_STARTX = (int)(x - block_width*((double)width/2));
final int DRAW_STARTY = (int)(y + block_height*((double)height/2));

@ -18,7 +18,7 @@ public class Meteo {
b.run(FRAMECOUNT);
}
public static void main(String[] args) {
public static void main(String[] args) {
double[] val = {0,0,};
b = new Board(SCREEN_WIDTH/2,SCREEN_HEIGHT/2,24,24,8,14,-0.065,1,4,-2,val);

Loading…
Cancel
Save