Added mouse event detection.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
concurrentModificationException1
Nic0Nic0Nii 3 years ago
parent 06f5a93e6c
commit 845d7fedf8
  1. BIN
      Meteo_Engine.jar
  2. 16
      src/sig/Block.java
  3. 4
      src/sig/BlockClump.java
  4. 21
      src/sig/Board.java
  5. 2
      src/sig/Meteo.java

Binary file not shown.

@ -6,6 +6,7 @@ import java.awt.Color;
public class Block{
BlockState state;
int x,y; //Relative to its block clump
int draw_x,draw_y;
final static BlockState[] STARTINGSTATES = {BlockState.BLUE,
BlockState.GREEN,
BlockState.ORANGE,
@ -22,12 +23,23 @@ public class Block{
public String toString() {
return "Block [state=" + state + ", x=" + x + ", y=" + y + "]";
}
public void draw(Graphics g, double x, double y, int block_width, int block_height,int launched) {
public void draw(Graphics g, double x, double y, int block_width, int block_height, int launched, boolean selected) {
if (Meteo.DEBUG_DRAWING==DebugMode.MODE0&&launched<=-1) {
g.setColor(Color.BLACK);
} else {
g.setColor(state.getCol());
}
g.fill3DRect((int)x+this.x*block_width,(int)y-this.y*block_height, block_width, block_height, true);
draw_x=(int)x+this.x*block_width;
draw_y=(int)y-this.y*block_height;
g.fill3DRect(draw_x, draw_y, block_width, block_height, true);
if (selected) {
g.setColor(Color.RED);
for (int i=0;i<2;i++) {
g.drawRect(draw_x+i-1,draw_y+i-1,block_width-1,block_height-1);
}
}
}
}

@ -54,9 +54,9 @@ public class BlockClump {
}
updateBlockCollision();
}
public void drawBlocks(Graphics g, int originX, int originY, int block_width, int block_height) {
public void drawBlocks(Graphics g, int originX, int originY, int block_width, int block_height, Block selectedBlock) {
for (Block b : blocks) {
b.draw(g,originX+x,originY-y,block_width,block_height,launched);
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);
g.drawString(Integer.toString(maxBlockHeight),(int)x+b.x*block_width+originX+4,(int)-y-b.y*block_height+originY+16);

@ -24,7 +24,7 @@ public class Board {
int attack_counter=0;
BlockClump clumpClickId;
Block clickBlockX;
Block clickBlock;
final static BlockState[] STARTINGSTATES = {BlockState.BLUE,
BlockState.GREEN,
@ -252,7 +252,7 @@ public class Board {
final int DRAW_ENDX = (int)(x + block_width*((double)width/2));
for (BlockClump bc : blockData) {
bc.drawBlocks(g,DRAW_STARTX,DRAW_STARTY,block_width,block_height);
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);
@ -268,15 +268,16 @@ public class Board {
public void mousePressed(MouseEvent e) {
//System.out.println("Pressed: "+e.getPoint());
//Adjust Y coordinate based on where the board is positioned.
int MOUSEX = e.getX();
int MOUSEY = y-e.getY();
clickBlock=null;
clumpClickId=null;
outer:
for (BlockClump bc : blockData) {
Rectangle bounds = new Rectangle((int)(bc.x+x),(int)(bc.y+y),width*block_width,bc.maxBlockHeight*block_height);
if (bounds.contains(MOUSEX,MOUSEY)) {
System.out.println("Clicked inside clump "+bc);
break;
} else {
System.out.println("Off by "+(bc.x+x-MOUSEX)+","+(bc.y+y-MOUSEY));
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;
}
}
}
}

@ -59,7 +59,7 @@ public class Meteo implements MouseListener{
}
}.start();
f.addMouseListener(this);
f.getContentPane().addMouseListener(this);
f.add(p);
f.setSize(SCREEN_WIDTH,SCREEN_HEIGHT);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Loading…
Cancel
Save