Compare commits
1 Commits
master
...
concurrent
Author | SHA1 | Date | |
---|---|---|---|
ffe74eb6aa |
BIN
Meteo_Engine.jar
BIN
Meteo_Engine.jar
Binary file not shown.
7
src/sig/BlockAddRequest.java
Normal file
7
src/sig/BlockAddRequest.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package sig;
|
||||||
|
|
||||||
|
public class BlockAddRequest extends BlockRequest{
|
||||||
|
BlockAddRequest(BlockClump bc, Block b) {
|
||||||
|
super(bc,b);
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,7 @@ public class BlockClump {
|
|||||||
collisionColumnRanges[i] = new int[]{-1,-1};
|
collisionColumnRanges[i] = new int[]{-1,-1};
|
||||||
}
|
}
|
||||||
|
|
||||||
addBlock(blockList.toArray(new Block[blockList.size()]));
|
addBlock(null,blockList.toArray(new Block[blockList.size()]));
|
||||||
this.x=x;
|
this.x=x;
|
||||||
this.y=y;
|
this.y=y;
|
||||||
this.yspd=startspd;
|
this.yspd=startspd;
|
||||||
@ -40,19 +40,38 @@ public class BlockClump {
|
|||||||
}
|
}
|
||||||
for (Block b : blocks) {updateBlockCollisionRangeWithBlock(b);}
|
for (Block b : blocks) {updateBlockCollisionRangeWithBlock(b);}
|
||||||
}
|
}
|
||||||
public void addBlock(Block...blocks) {
|
public void addBlock(List<BlockRequest> requestList,Block...blocks) {
|
||||||
|
for (Block b : blocks) {
|
||||||
|
if (requestList==null) {
|
||||||
//Adds the block to the strucutre. Update collision column ranges to reflect the new bounds.
|
//Adds the block to the strucutre. Update collision column ranges to reflect the new bounds.
|
||||||
for (Block b : blocks)
|
|
||||||
{
|
|
||||||
this.blocks.add(b);
|
this.blocks.add(b);
|
||||||
updateBlockCollisionRangeWithBlock(b);
|
updateBlockCollisionRangeWithBlock(b);
|
||||||
|
} else {
|
||||||
|
requestList.add(new BlockAddRequest(this,b));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void removeBlock(Block...blocks) {
|
}
|
||||||
|
public void removeBlock(List<BlockRequest> requestList,Block...blocks) {
|
||||||
for (Block b : blocks) {
|
for (Block b : blocks) {
|
||||||
|
if (requestList==null) {
|
||||||
|
//Adds the block to the strucutre. Update collision column ranges to reflect the new bounds.
|
||||||
this.blocks.remove(b);
|
this.blocks.remove(b);
|
||||||
}
|
|
||||||
updateBlockCollision();
|
updateBlockCollision();
|
||||||
|
} else {
|
||||||
|
requestList.add(new BlockDeleteRequest(this,b));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Block(List<BlockRequest> requestList,Block...blocks) {
|
||||||
|
for (Block b : blocks) {
|
||||||
|
if (requestList==null) {
|
||||||
|
//Adds the block to the strucutre. Update collision column ranges to reflect the new bounds.
|
||||||
|
this.blocks.add(b);
|
||||||
|
updateBlockCollisionRangeWithBlock(b);
|
||||||
|
} else {
|
||||||
|
requestList.add(new BlockAddRequest(this,b));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void drawBlocks(Graphics g, int originX, int originY, int block_width, int block_height, Block selectedBlock) {
|
public void drawBlocks(Graphics g, int originX, int originY, int block_width, int block_height, Block selectedBlock) {
|
||||||
for (Block b : blocks) {
|
for (Block b : blocks) {
|
||||||
|
7
src/sig/BlockDeleteRequest.java
Normal file
7
src/sig/BlockDeleteRequest.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package sig;
|
||||||
|
|
||||||
|
public class BlockDeleteRequest extends BlockRequest{
|
||||||
|
BlockDeleteRequest(BlockClump bc, Block b) {
|
||||||
|
super(bc,b);
|
||||||
|
}
|
||||||
|
}
|
10
src/sig/BlockRequest.java
Normal file
10
src/sig/BlockRequest.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package sig;
|
||||||
|
|
||||||
|
public class BlockRequest {
|
||||||
|
BlockClump bc;
|
||||||
|
Block b;
|
||||||
|
BlockRequest(BlockClump bc,Block b) {
|
||||||
|
this.bc=bc;
|
||||||
|
this.b=b;
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,7 @@ public class Board {
|
|||||||
int block_width,block_height;
|
int block_width,block_height;
|
||||||
double vspeed;
|
double vspeed;
|
||||||
int attack_counter=0;
|
int attack_counter=0;
|
||||||
|
boolean iterationLocked=false;
|
||||||
|
|
||||||
BlockClump clumpClickId;
|
BlockClump clumpClickId;
|
||||||
Block clickBlock;
|
Block clickBlock;
|
||||||
@ -36,6 +37,7 @@ public class Board {
|
|||||||
|
|
||||||
List<BlockClump> blockClumpDeleteList = new ArrayList<BlockClump>();
|
List<BlockClump> blockClumpDeleteList = new ArrayList<BlockClump>();
|
||||||
List<BlockClump> blockClumpAddList = new ArrayList<BlockClump>();
|
List<BlockClump> blockClumpAddList = new ArrayList<BlockClump>();
|
||||||
|
List<BlockRequest> blockRequestList = new ArrayList<BlockRequest>();
|
||||||
|
|
||||||
public Board(int centerX,int centerY,int block_width,int block_height,int boardWidth, int boardHeight, double gravity, double launch_power, double max_rise_spd, double max_fall_spd,
|
public Board(int centerX,int centerY,int block_width,int block_height,int boardWidth, int boardHeight, double gravity, double launch_power, double max_rise_spd, double max_fall_spd,
|
||||||
double[] combo_power_bonus) {
|
double[] combo_power_bonus) {
|
||||||
@ -95,6 +97,7 @@ public class Board {
|
|||||||
//System.out.println(blocks.y);
|
//System.out.println(blocks.y);
|
||||||
}
|
}
|
||||||
MergeAllGroundedClumps();
|
MergeAllGroundedClumps();
|
||||||
|
if (!iterationLocked) {
|
||||||
if (blockClumpDeleteList.size()>0) {
|
if (blockClumpDeleteList.size()>0) {
|
||||||
blockData.removeAll(blockClumpDeleteList);
|
blockData.removeAll(blockClumpDeleteList);
|
||||||
blockClumpDeleteList.clear();
|
blockClumpDeleteList.clear();
|
||||||
@ -103,6 +106,18 @@ public class Board {
|
|||||||
blockData.addAll(blockClumpAddList);
|
blockData.addAll(blockClumpAddList);
|
||||||
blockClumpAddList.clear();
|
blockClumpAddList.clear();
|
||||||
}
|
}
|
||||||
|
if (blockRequestList.size()>0) {
|
||||||
|
for (BlockRequest addReq:blockRequestList.stream().filter((request)->request instanceof BlockAddRequest).collect(Collectors.toList())) {
|
||||||
|
addReq.bc.addBlock(null,addReq.b);
|
||||||
|
}
|
||||||
|
for (BlockRequest removeReq:blockRequestList.stream().filter((request)->request instanceof BlockDeleteRequest).collect(Collectors.toList())) {
|
||||||
|
removeReq.bc.removeBlock(null,removeReq.b);
|
||||||
|
}
|
||||||
|
blockRequestList.clear();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("Lock was requested so update could not be performed.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void DestroyOutsideBlocks(BlockClump blocks) {
|
private void DestroyOutsideBlocks(BlockClump blocks) {
|
||||||
if (blocks.yspd>0) {
|
if (blocks.yspd>0) {
|
||||||
@ -115,7 +130,7 @@ public class Board {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void RemoveBlocks(BlockClump bc,Block...blocks) {
|
private void RemoveBlocks(BlockClump bc,Block...blocks) {
|
||||||
bc.removeBlock(blocks);
|
bc.removeBlock(blockRequestList,blocks);
|
||||||
if (bc.getBlocks().size()==0) {
|
if (bc.getBlocks().size()==0) {
|
||||||
blockClumpDeleteList.add(bc);
|
blockClumpDeleteList.add(bc);
|
||||||
}
|
}
|
||||||
@ -125,7 +140,7 @@ public class Board {
|
|||||||
if (groundedClumps.size()>1) {
|
if (groundedClumps.size()>1) {
|
||||||
BlockClump base = groundedClumps.remove(0);
|
BlockClump base = groundedClumps.remove(0);
|
||||||
for (BlockClump bc : groundedClumps) {
|
for (BlockClump bc : groundedClumps) {
|
||||||
base.addBlock(bc.getBlocks().toArray(new Block[bc.getBlocks().size()]));
|
base.addBlock(blockRequestList,bc.getBlocks().toArray(new Block[bc.getBlocks().size()]));
|
||||||
}
|
}
|
||||||
blockClumpDeleteList.addAll(groundedClumps);
|
blockClumpDeleteList.addAll(groundedClumps);
|
||||||
}
|
}
|
||||||
@ -212,7 +227,7 @@ public class Board {
|
|||||||
private void CombineAToB(BlockClump A, BlockClump B) {
|
private void CombineAToB(BlockClump A, BlockClump B) {
|
||||||
for (Block b : A.getBlocks()) {
|
for (Block b : A.getBlocks()) {
|
||||||
b.y = B.collisionColumnRanges[b.x][1]+1;
|
b.y = B.collisionColumnRanges[b.x][1]+1;
|
||||||
B.addBlock(b);
|
B.addBlock(blockRequestList,b);
|
||||||
}
|
}
|
||||||
blockClumpDeleteList.add(A);
|
blockClumpDeleteList.add(A);
|
||||||
}
|
}
|
||||||
@ -251,12 +266,14 @@ public class Board {
|
|||||||
final int DRAW_STARTY = (int)(y + block_height*((double)height/2));
|
final int DRAW_STARTY = (int)(y + block_height*((double)height/2));
|
||||||
final int DRAW_ENDX = (int)(x + block_width*((double)width/2));
|
final int DRAW_ENDX = (int)(x + block_width*((double)width/2));
|
||||||
|
|
||||||
|
iterationLocked=true;
|
||||||
for (BlockClump bc : blockData) {
|
for (BlockClump bc : blockData) {
|
||||||
bc.drawBlocks(g,DRAW_STARTX,DRAW_STARTY,block_width,block_height,clickBlock);
|
bc.drawBlocks(g,DRAW_STARTX,DRAW_STARTY,block_width,block_height,clickBlock);
|
||||||
}
|
}
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.fillRoundRect(DRAW_STARTX, DRAW_STARTY+block_height, DRAW_ENDX-DRAW_STARTX, 3, 3, 1);
|
g.fillRoundRect(DRAW_STARTX, DRAW_STARTY+block_height, DRAW_ENDX-DRAW_STARTX, 3, 3, 1);
|
||||||
BlockClump.drawDebugBlockClumps(g,DRAW_STARTX,DRAW_STARTY,block_width,block_height,blockData);
|
BlockClump.drawDebugBlockClumps(g,DRAW_STARTX,DRAW_STARTY,block_width,block_height,blockData);
|
||||||
|
iterationLocked=false;
|
||||||
if (Meteo.DEBUG_DRAWING!=DebugMode.OFF) {
|
if (Meteo.DEBUG_DRAWING!=DebugMode.OFF) {
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.drawString(Integer.toString(blockData.size()),4,Meteo.SCREEN_HEIGHT-20);
|
g.drawString(Integer.toString(blockData.size()),4,Meteo.SCREEN_HEIGHT-20);
|
||||||
@ -270,6 +287,7 @@ public class Board {
|
|||||||
//Adjust Y coordinate based on where the board is positioned.
|
//Adjust Y coordinate based on where the board is positioned.
|
||||||
clickBlock=null;
|
clickBlock=null;
|
||||||
clumpClickId=null;
|
clumpClickId=null;
|
||||||
|
iterationLocked=true;
|
||||||
outer:
|
outer:
|
||||||
for (BlockClump bc : blockData) {
|
for (BlockClump bc : blockData) {
|
||||||
for (Block b : bc.getBlocks()) {
|
for (Block b : bc.getBlocks()) {
|
||||||
@ -280,14 +298,38 @@ public class Board {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
iterationLocked=false;
|
||||||
}
|
}
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
//System.out.println("Released: "+e.getPoint());
|
//System.out.println("Released: "+e.getPoint());
|
||||||
|
clickBlock=null;
|
||||||
|
clumpClickId=null;
|
||||||
}
|
}
|
||||||
public void mouseEntered(MouseEvent e) {
|
public void mouseEntered(MouseEvent e) {
|
||||||
//System.out.println("Entered: "+e.getPoint());
|
//System.out.println("Entered: "+e.getPoint());
|
||||||
}
|
}
|
||||||
public void mouseExited(MouseEvent e) {
|
public void mouseExited(MouseEvent e) {
|
||||||
//System.out.println("Exited: "+e.getPoint());
|
//System.out.println("Exited: "+e.getPoint());
|
||||||
|
clickBlock=null;
|
||||||
|
clumpClickId=null;
|
||||||
|
}
|
||||||
|
public void mouseDragged(MouseEvent e) {
|
||||||
|
//System.out.println("Dragged: "+e.getPoint());
|
||||||
|
if (clickBlock!=null&&clumpClickId!=null) {
|
||||||
|
iterationLocked=true;
|
||||||
|
for (Block b : clumpClickId.getBlocks()) {
|
||||||
|
if (Math.abs(b.y-clickBlock.y)==1&&new Rectangle(b.draw_x,b.draw_y,block_width,block_height).contains(e.getPoint())) {
|
||||||
|
//Swap the positions of these two blocks.
|
||||||
|
int oldY = clickBlock.y;
|
||||||
|
clickBlock.y=b.y;
|
||||||
|
b.y=oldY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iterationLocked=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
//System.out.println("Moved: "+e.getPoint());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,9 @@ import javax.swing.JFrame;
|
|||||||
|
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
|
import java.awt.event.MouseMotionListener;
|
||||||
|
|
||||||
public class Meteo implements MouseListener{
|
public class Meteo implements MouseListener,MouseMotionListener{
|
||||||
public final static int SCREEN_WIDTH=640;
|
public final static int SCREEN_WIDTH=640;
|
||||||
public final static int SCREEN_HEIGHT=640;
|
public final static int SCREEN_HEIGHT=640;
|
||||||
public static long FRAMECOUNT=0;
|
public static long FRAMECOUNT=0;
|
||||||
@ -60,6 +61,7 @@ public class Meteo implements MouseListener{
|
|||||||
}.start();
|
}.start();
|
||||||
|
|
||||||
f.getContentPane().addMouseListener(this);
|
f.getContentPane().addMouseListener(this);
|
||||||
|
f.getContentPane().addMouseMotionListener(this);
|
||||||
f.add(p);
|
f.add(p);
|
||||||
f.setSize(SCREEN_WIDTH,SCREEN_HEIGHT);
|
f.setSize(SCREEN_WIDTH,SCREEN_HEIGHT);
|
||||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
@ -95,4 +97,14 @@ public class Meteo implements MouseListener{
|
|||||||
public void mouseExited(MouseEvent e) {
|
public void mouseExited(MouseEvent e) {
|
||||||
b.mouseExited(e);
|
b.mouseExited(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent e) {
|
||||||
|
b.mouseDragged(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
b.mouseMoved(e);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user