Compare commits
1 Commits
master
...
concurrent
Author | SHA1 | Date | |
---|---|---|---|
ffe74eb6aa |
@ -1,7 +0,0 @@
|
||||
# List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/
|
||||
tasks:
|
||||
- init: sh ./coauthors.sh
|
||||
vscode:
|
||||
extensions:
|
||||
- redhat.java
|
||||
- mhutchie.git-graph
|
BIN
Meteo_Engine.jar
BIN
Meteo_Engine.jar
Binary file not shown.
45
coauthors.sh
45
coauthors.sh
@ -1,45 +0,0 @@
|
||||
npm i -g git-mob
|
||||
cat <<-EOF > ~/.git-coauthors
|
||||
{
|
||||
"coauthors": {
|
||||
"sig": {
|
||||
"name": "sigonasr2",
|
||||
"email": "sigonasr2@gmail.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
git mob sig
|
||||
cat <<-EOF > .git/hooks/prepare-commit-msg
|
||||
#!/usr/bin/env node
|
||||
let exec = require('child_process').exec,
|
||||
fs = require('fs');
|
||||
|
||||
const commitMessage = process.argv[2];
|
||||
// expect .git/COMMIT_EDITMSG
|
||||
if(/COMMIT_EDITMSG/g.test(commitMessage)){
|
||||
let contents = "";
|
||||
exec("git mob-print",
|
||||
function (err, stdout) {
|
||||
if(err) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// opens .git/COMMIT_EDITMSG
|
||||
contents = fs.readFileSync(commitMessage);
|
||||
|
||||
if(contents.indexOf(stdout.trim()) !== -1) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const commentPos = contents.indexOf('# ');
|
||||
const gitMessage = contents.slice(0, commentPos);
|
||||
const gitComments = contents.slice(commentPos)
|
||||
|
||||
fs.writeFileSync(commitMessage, gitMessage + stdout + gitComments);
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
EOF
|
||||
chmod +x .git/hooks/prepare-commit-msg
|
||||
echo "Environment is setup!"
|
3
gitpod.yml
Normal file
3
gitpod.yml
Normal file
@ -0,0 +1,3 @@
|
||||
vscode:
|
||||
extensions:
|
||||
- redhat.java
|
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};
|
||||
}
|
||||
|
||||
addBlock(blockList.toArray(new Block[blockList.size()]));
|
||||
addBlock(null,blockList.toArray(new Block[blockList.size()]));
|
||||
this.x=x;
|
||||
this.y=y;
|
||||
this.yspd=startspd;
|
||||
@ -38,28 +38,43 @@ public class BlockClump {
|
||||
for (int i=0;i<collisionColumnRanges.length;i++) {
|
||||
collisionColumnRanges[i] = new int[]{-1,-1};
|
||||
}
|
||||
for (int i=0;i<blocks.size();i++) {
|
||||
Block b = blocks.get(i);
|
||||
updateBlockCollisionRangeWithBlock(b);
|
||||
}
|
||||
for (Block b : blocks) {updateBlockCollisionRangeWithBlock(b);}
|
||||
}
|
||||
public void addBlock(Block...blocks) {
|
||||
//Adds the block to the strucutre. Update collision column ranges to reflect the new bounds.
|
||||
for (Block b : blocks)
|
||||
{
|
||||
this.blocks.add(b);
|
||||
updateBlockCollisionRangeWithBlock(b);
|
||||
}
|
||||
}
|
||||
public void removeBlock(Block...blocks) {
|
||||
public void addBlock(List<BlockRequest> requestList,Block...blocks) {
|
||||
for (Block b : blocks) {
|
||||
this.blocks.remove(b);
|
||||
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 removeBlock(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.remove(b);
|
||||
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));
|
||||
}
|
||||
}
|
||||
updateBlockCollision();
|
||||
}
|
||||
public void drawBlocks(Graphics g, int originX, int originY, int block_width, int block_height, Block selectedBlock) {
|
||||
for (int i=0;i<blocks.size();i++) {
|
||||
Block b = blocks.get(i);
|
||||
for (Block b : blocks) {
|
||||
b.draw(g,originX+x,originY-y,block_width,block_height,launched,selectedBlock!=null&&selectedBlock.equals(b));
|
||||
if (Meteo.DEBUG_DRAWING==DebugMode.MODE2) {
|
||||
g.setColor(Color.BLACK);
|
||||
@ -72,8 +87,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]))),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));
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -109,12 +124,10 @@ public class BlockClump {
|
||||
return "BlockClump [blocks=" + blocks + ", x=" + x + ", y=" + y + ", yspd=" + yspd + "]";
|
||||
}
|
||||
public static void drawDebugBlockClumps(Graphics g, int originX, int originY, int block_width, int block_height, List<BlockClump> blockData) {
|
||||
for (int i=0;i<blockData.size();i++) {
|
||||
BlockClump bc = blockData.get(i);
|
||||
for (BlockClump bc : blockData) {
|
||||
bc.drawClumpOutlines(g,originX,originY,block_width,block_height);
|
||||
}
|
||||
for (int i=0;i<blockData.size();i++) {
|
||||
BlockClump bc = blockData.get(i);
|
||||
for (BlockClump bc : blockData) {
|
||||
bc.drawClumpDots(g,originX,originY,block_width,block_height);
|
||||
}
|
||||
}
|
||||
|
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;
|
||||
double vspeed;
|
||||
int attack_counter=0;
|
||||
boolean iterationLocked=false;
|
||||
|
||||
BlockClump clumpClickId;
|
||||
Block clickBlock;
|
||||
@ -36,6 +37,7 @@ public class Board {
|
||||
|
||||
List<BlockClump> blockClumpDeleteList = 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,
|
||||
double[] combo_power_bonus) {
|
||||
@ -58,50 +60,30 @@ public class Board {
|
||||
}
|
||||
|
||||
outerloop:
|
||||
for (int i=0;i<blockData.size();i++) {
|
||||
BlockClump blocks = blockData.get(i);
|
||||
for (BlockClump blocks : blockData) {
|
||||
DestroyOutsideBlocks(blocks);
|
||||
if (checkForMatches(blocks)) {continue;}
|
||||
double FUTURE_FALL_POSITION = blocks.y+blocks.yspd+gravity;
|
||||
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;
|
||||
for (int x=0;x<width;x++) {
|
||||
if (blocks.collisionColumnRanges[x][0]!=-1) {
|
||||
for (int j=0;j<blockData.size();j++) {
|
||||
BlockClump blocks2 = blockData.get(j);
|
||||
for (BlockClump blocks2 : blockData) {
|
||||
if (!blocks.equals(blocks2)&&blocks2.collisionColumnRanges[x][1]!=-1) {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -115,14 +97,27 @@ public class Board {
|
||||
//System.out.println(blocks.y);
|
||||
}
|
||||
MergeAllGroundedClumps();
|
||||
if (blockClumpDeleteList.size()>0) {
|
||||
blockData.removeAll(blockClumpDeleteList);
|
||||
blockClumpDeleteList.clear();
|
||||
}
|
||||
if (blockClumpAddList.size()>0) {
|
||||
blockData.addAll(blockClumpAddList);
|
||||
blockClumpAddList.clear();
|
||||
}
|
||||
if (!iterationLocked) {
|
||||
if (blockClumpDeleteList.size()>0) {
|
||||
blockData.removeAll(blockClumpDeleteList);
|
||||
blockClumpDeleteList.clear();
|
||||
}
|
||||
if (blockClumpAddList.size()>0) {
|
||||
blockData.addAll(blockClumpAddList);
|
||||
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) {
|
||||
if (blocks.yspd>0) {
|
||||
@ -135,7 +130,7 @@ public class Board {
|
||||
}
|
||||
}
|
||||
private void RemoveBlocks(BlockClump bc,Block...blocks) {
|
||||
bc.removeBlock(blocks);
|
||||
bc.removeBlock(blockRequestList,blocks);
|
||||
if (bc.getBlocks().size()==0) {
|
||||
blockClumpDeleteList.add(bc);
|
||||
}
|
||||
@ -144,9 +139,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 (int i=0;i<groundedClumps.size();i++) {
|
||||
BlockClump bc = groundedClumps.get(i);
|
||||
base.addBlock(bc.getBlocks().toArray(new Block[bc.getBlocks().size()]));
|
||||
for (BlockClump bc : groundedClumps) {
|
||||
base.addBlock(blockRequestList,bc.getBlocks().toArray(new Block[bc.getBlocks().size()]));
|
||||
}
|
||||
blockClumpDeleteList.addAll(groundedClumps);
|
||||
}
|
||||
@ -170,8 +164,7 @@ public class Board {
|
||||
int minY=Integer.MAX_VALUE;
|
||||
List<Block> newClumpBlocks = new ArrayList<Block>();
|
||||
newClumpBlocks.addAll(markedBlocks);
|
||||
for (int i=0;i<markedBlocks.size();i++) {
|
||||
Block b = markedBlocks.get(i);
|
||||
for (Block b : markedBlocks) {
|
||||
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()));
|
||||
@ -179,12 +172,11 @@ public class Board {
|
||||
}
|
||||
//For now just get rid of them.
|
||||
RemoveBlocks(blocks,newClumpBlocks.toArray(new Block[newClumpBlocks.size()]));
|
||||
for (int i=0;i<newClumpBlocks.size();i++) {
|
||||
Block b = newClumpBlocks.get(i);
|
||||
for (Block b : newClumpBlocks) {
|
||||
b.y-=minY;
|
||||
}
|
||||
blockClumpAddList.add(
|
||||
new BlockClump(newClumpBlocks, blocks.x, blocks.y+minY*block_height, launch_power, width, 120)
|
||||
new BlockClump(newClumpBlocks, blocks.x, blocks.y+minY*block_height+4, launch_power, width, 120)
|
||||
);
|
||||
}
|
||||
return markedBlocks.size()>0;
|
||||
@ -233,10 +225,9 @@ public class Board {
|
||||
return markedBlocks;
|
||||
}
|
||||
private void CombineAToB(BlockClump A, BlockClump B) {
|
||||
for (int i=0;i<A.getBlocks().size();i++) {
|
||||
Block b = A.getBlocks().get(i);
|
||||
for (Block b : A.getBlocks()) {
|
||||
b.y = B.collisionColumnRanges[b.x][1]+1;
|
||||
B.addBlock(b);
|
||||
B.addBlock(blockRequestList,b);
|
||||
}
|
||||
blockClumpDeleteList.add(A);
|
||||
}
|
||||
@ -250,8 +241,7 @@ public class Board {
|
||||
SplitBlockClump(blocks);
|
||||
}
|
||||
if (blocks.launched<=0) {
|
||||
for (int i=0;i<blocks.getBlocks().size();i++) {
|
||||
Block b = blocks.getBlocks().get(i);
|
||||
for (Block b : blocks.getBlocks()) {
|
||||
if (b.state==BlockState.IGNITED) {
|
||||
b.state=STARTINGSTATES[(int)(Meteo.r.nextInt(3))];
|
||||
}
|
||||
@ -276,71 +266,70 @@ 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 (int i=0;i<blockData.size();i++) {
|
||||
BlockClump bc = blockData.get(i);
|
||||
iterationLocked=true;
|
||||
for (BlockClump bc : blockData) {
|
||||
bc.drawBlocks(g,DRAW_STARTX,DRAW_STARTY,block_width,block_height,clickBlock);
|
||||
}
|
||||
g.setColor(Color.BLACK);
|
||||
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);
|
||||
iterationLocked=false;
|
||||
if (Meteo.DEBUG_DRAWING!=DebugMode.OFF) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawString(Integer.toString(blockData.size()),4,Meteo.SCREEN_HEIGHT-20);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
iterationLocked=true;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
iterationLocked=false;
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
//System.out.println("Released: "+e.getPoint());
|
||||
clickBlock=null;
|
||||
clumpClickId=null;
|
||||
}
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
//System.out.println("Entered: "+e.getPoint());
|
||||
}
|
||||
public void mouseExited(MouseEvent e) {
|
||||
//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;
|
||||
}
|
||||
break;
|
||||
case RELEASE:
|
||||
//System.out.println("Released: "+e.getPoint());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
iterationLocked=false;
|
||||
}
|
||||
}
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
//System.out.println("Moved: "+e.getPoint());
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
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) + "]";
|
||||
}
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
package sig;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
public class Meteo implements MouseListener,MouseMotionListener{
|
||||
public final static int SCREEN_WIDTH=640;
|
||||
@ -23,15 +21,8 @@ public class Meteo implements MouseListener,MouseMotionListener{
|
||||
public final static long TIMEPERTICK = 16666667l;
|
||||
public static DebugMode DEBUG_DRAWING = DebugMode.MODE2;
|
||||
|
||||
public static List<MouseQueue> MOUSE_QUEUE = new ArrayList<MouseQueue>();
|
||||
|
||||
public static void runGameLoop() {
|
||||
FRAMECOUNT++;
|
||||
for (int i=0;i<MOUSE_QUEUE.size();i++) {
|
||||
MouseQueue mq = MOUSE_QUEUE.get(i);
|
||||
b.handleMouse(mq);
|
||||
}
|
||||
MOUSE_QUEUE.clear();
|
||||
b.run(FRAMECOUNT);
|
||||
}
|
||||
|
||||
@ -84,36 +75,36 @@ public class Meteo implements MouseListener,MouseMotionListener{
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.CLICK,e));
|
||||
b.mouseClicked(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.PRESS,e));
|
||||
b.mousePressed(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.RELEASE,e));
|
||||
b.mouseReleased(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.ENTER,e));
|
||||
b.mouseEntered(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.EXIT,e));
|
||||
b.mouseExited(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.DRAG,e));
|
||||
b.mouseDragged(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.MOVE,e));
|
||||
b.mouseMoved(e);
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package sig;
|
||||
|
||||
public enum MouseEventType {
|
||||
CLICK,
|
||||
PRESS,
|
||||
RELEASE,
|
||||
ENTER,
|
||||
EXIT,
|
||||
DRAG,
|
||||
MOVE;
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package sig;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class MouseQueue {
|
||||
MouseEventType type;
|
||||
MouseEvent ev;
|
||||
MouseQueue(MouseEventType type,MouseEvent ev) {
|
||||
this.type=type;
|
||||
this.ev=ev;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user