|
|
|
@ -58,30 +58,50 @@ public class Board { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
outerloop: |
|
|
|
|
for (BlockClump blocks : blockData) { |
|
|
|
|
for (int i=0;i<blockData.size();i++) { |
|
|
|
|
BlockClump blocks = blockData.get(i); |
|
|
|
|
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 (BlockClump blocks2 : blockData) { |
|
|
|
|
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) { |
|
|
|
|
CombineAToBFromBelow(blocks,blocks2); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -124,7 +144,8 @@ public class Board { |
|
|
|
|
List<BlockClump> groundedClumps = blockData.stream().filter((cl)->cl.y==0).collect(Collectors.toList()); |
|
|
|
|
if (groundedClumps.size()>1) { |
|
|
|
|
BlockClump base = groundedClumps.remove(0); |
|
|
|
|
for (BlockClump bc : groundedClumps) { |
|
|
|
|
for (int i=0;i<groundedClumps.size();i++) { |
|
|
|
|
BlockClump bc = groundedClumps.get(i); |
|
|
|
|
base.addBlock(bc.getBlocks().toArray(new Block[bc.getBlocks().size()])); |
|
|
|
|
} |
|
|
|
|
blockClumpDeleteList.addAll(groundedClumps); |
|
|
|
@ -149,7 +170,8 @@ public class Board { |
|
|
|
|
int minY=Integer.MAX_VALUE; |
|
|
|
|
List<Block> newClumpBlocks = new ArrayList<Block>(); |
|
|
|
|
newClumpBlocks.addAll(markedBlocks); |
|
|
|
|
for (Block b : markedBlocks) { |
|
|
|
|
for (int i=0;i<markedBlocks.size();i++) { |
|
|
|
|
Block b = markedBlocks.get(i); |
|
|
|
|
b.state = BlockState.IGNITED; |
|
|
|
|
//All blocks above marked blocks now join the clump.
|
|
|
|
|
newClumpBlocks.addAll(blocks.getSortedBlocksOnCol(b.x).stream().filter((block)->!newClumpBlocks.contains(block)&&block.y>b.y).collect(Collectors.toList())); |
|
|
|
@ -157,11 +179,12 @@ public class Board { |
|
|
|
|
} |
|
|
|
|
//For now just get rid of them.
|
|
|
|
|
RemoveBlocks(blocks,newClumpBlocks.toArray(new Block[newClumpBlocks.size()])); |
|
|
|
|
for (Block b : newClumpBlocks) { |
|
|
|
|
for (int i=0;i<newClumpBlocks.size();i++) { |
|
|
|
|
Block b = newClumpBlocks.get(i); |
|
|
|
|
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; |
|
|
|
@ -210,7 +233,8 @@ public class Board { |
|
|
|
|
return markedBlocks; |
|
|
|
|
} |
|
|
|
|
private void CombineAToB(BlockClump A, BlockClump B) { |
|
|
|
|
for (Block b : A.getBlocks()) { |
|
|
|
|
for (int i=0;i<A.getBlocks().size();i++) { |
|
|
|
|
Block b = A.getBlocks().get(i); |
|
|
|
|
b.y = B.collisionColumnRanges[b.x][1]+1; |
|
|
|
|
B.addBlock(b); |
|
|
|
|
} |
|
|
|
@ -226,7 +250,8 @@ public class Board { |
|
|
|
|
SplitBlockClump(blocks); |
|
|
|
|
} |
|
|
|
|
if (blocks.launched<=0) { |
|
|
|
|
for (Block b : blocks.getBlocks()) { |
|
|
|
|
for (int i=0;i<blocks.getBlocks().size();i++) { |
|
|
|
|
Block b = blocks.getBlocks().get(i); |
|
|
|
|
if (b.state==BlockState.IGNITED) { |
|
|
|
|
b.state=STARTINGSTATES[(int)(Meteo.r.nextInt(3))]; |
|
|
|
|
} |
|
|
|
@ -251,7 +276,8 @@ public class Board { |
|
|
|
|
final int DRAW_STARTY = (int)(y + block_height*((double)height/2)); |
|
|
|
|
final int DRAW_ENDX = (int)(x + block_width*((double)width/2)); |
|
|
|
|
|
|
|
|
|
for (BlockClump bc : blockData) { |
|
|
|
|
for (int i=0;i<blockData.size();i++) { |
|
|
|
|
BlockClump bc = blockData.get(i); |
|
|
|
|
bc.drawBlocks(g,DRAW_STARTX,DRAW_STARTY,block_width,block_height,clickBlock); |
|
|
|
|
} |
|
|
|
|
g.setColor(Color.BLACK); |
|
|
|
@ -262,32 +288,59 @@ public class Board { |
|
|
|
|
g.drawString(Integer.toString(blockData.size()),4,Meteo.SCREEN_HEIGHT-20); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public void mouseClicked(MouseEvent e) { |
|
|
|
|
//System.out.println("Clicked: "+e.getPoint());
|
|
|
|
|
} |
|
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
|
//System.out.println("Pressed: "+e.getPoint());
|
|
|
|
|
//Adjust Y coordinate based on where the board is positioned.
|
|
|
|
|
clickBlock=null; |
|
|
|
|
clumpClickId=null; |
|
|
|
|
outer: |
|
|
|
|
for (BlockClump bc : blockData) { |
|
|
|
|
for (Block b : bc.getBlocks()) { |
|
|
|
|
if (new Rectangle(b.draw_x,b.draw_y,block_width,block_height).contains(e.getPoint())) { |
|
|
|
|
clickBlock=b; |
|
|
|
|
clumpClickId=bc; |
|
|
|
|
break outer; |
|
|
|
|
public void handleMouse(MouseQueue mq) { |
|
|
|
|
MouseEvent e = mq.ev; |
|
|
|
|
switch (mq.type) { |
|
|
|
|
case CLICK: |
|
|
|
|
//System.out.println("Clicked: "+e.getPoint());
|
|
|
|
|
break; |
|
|
|
|
case DRAG: |
|
|
|
|
//System.out.println("Dragged: "+e.getPoint());
|
|
|
|
|
if (clumpClickId!=null&&clickBlock!=null) { |
|
|
|
|
List<Block> adjacentBlocks = clumpClickId.getBlocks().stream().filter((block)->Math.abs(clickBlock.y-block.y)==1&&clickBlock.x==block.x).collect(Collectors.toList()); |
|
|
|
|
for (Block b : adjacentBlocks) { |
|
|
|
|
if (new Rectangle(0,b.draw_y,Meteo.SCREEN_WIDTH,block_height).contains(e.getPoint())) { |
|
|
|
|
int newY = b.y; |
|
|
|
|
b.y=clickBlock.y; |
|
|
|
|
clickBlock.y = newY; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case ENTER: |
|
|
|
|
//System.out.println("Entered: "+e.getPoint());
|
|
|
|
|
break; |
|
|
|
|
case EXIT: |
|
|
|
|
//System.out.println("Exited: "+e.getPoint());
|
|
|
|
|
break; |
|
|
|
|
case MOVE: |
|
|
|
|
//System.out.println("Moved: "+e.getPoint());
|
|
|
|
|
break; |
|
|
|
|
case PRESS: |
|
|
|
|
//System.out.println("Pressed: "+e.getPoint());
|
|
|
|
|
//Adjust Y coordinate based on where the board is positioned.
|
|
|
|
|
clickBlock=null; |
|
|
|
|
clumpClickId=null; |
|
|
|
|
outer: |
|
|
|
|
for (int i=0;i<blockData.size();i++) { |
|
|
|
|
BlockClump bc = blockData.get(i); |
|
|
|
|
for (int j=0;j<bc.getBlocks().size();j++) { |
|
|
|
|
Block b = bc.getBlocks().get(j); |
|
|
|
|
if (new Rectangle(b.draw_x,b.draw_y,block_width,block_height).contains(e.getPoint())) { |
|
|
|
|
clickBlock=b; |
|
|
|
|
clumpClickId=bc; |
|
|
|
|
break outer; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case RELEASE: |
|
|
|
|
//System.out.println("Released: "+e.getPoint());
|
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
|
//System.out.println("Released: "+e.getPoint());
|
|
|
|
|
} |
|
|
|
|
public void mouseEntered(MouseEvent e) { |
|
|
|
|
//System.out.println("Entered: "+e.getPoint());
|
|
|
|
|
} |
|
|
|
|
public void mouseExited(MouseEvent e) { |
|
|
|
|
//System.out.println("Exited: "+e.getPoint());
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|