diff --git a/Meteo_Engine.jar b/Meteo_Engine.jar index 3b221ca..0954251 100644 Binary files a/Meteo_Engine.jar and b/Meteo_Engine.jar differ diff --git a/src/sig/Block.java b/src/sig/Block.java index 8e5ea08..bad29b3 100644 --- a/src/sig/Block.java +++ b/src/sig/Block.java @@ -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); + } + } } } \ No newline at end of file diff --git a/src/sig/BlockClump.java b/src/sig/BlockClump.java index 6a4b780..a140a88 100644 --- a/src/sig/BlockClump.java +++ b/src/sig/BlockClump.java @@ -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); diff --git a/src/sig/Board.java b/src/sig/Board.java index eff3cae..e291dbd 100644 --- a/src/sig/Board.java +++ b/src/sig/Board.java @@ -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; + } } } } diff --git a/src/sig/Meteo.java b/src/sig/Meteo.java index 2087f5f..c734d1a 100644 --- a/src/sig/Meteo.java +++ b/src/sig/Meteo.java @@ -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);