diff --git a/Meteo_Engine.jar b/Meteo_Engine.jar index 1c280b0..3b221ca 100644 Binary files a/Meteo_Engine.jar and b/Meteo_Engine.jar differ diff --git a/src/sig/Board.java b/src/sig/Board.java index 5d037ef..eff3cae 100644 --- a/src/sig/Board.java +++ b/src/sig/Board.java @@ -1,7 +1,9 @@ package sig; import java.awt.Graphics; +import java.awt.event.MouseEvent; import java.awt.Color; +import java.awt.Rectangle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -20,6 +22,10 @@ public class Board { int block_width,block_height; double vspeed; int attack_counter=0; + + BlockClump clumpClickId; + Block clickBlockX; + final static BlockState[] STARTINGSTATES = {BlockState.BLUE, BlockState.GREEN, BlockState.ORANGE, @@ -256,4 +262,31 @@ 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. + int MOUSEX = e.getX(); + int MOUSEY = y-e.getY(); + 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)); + } + } + } + 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()); + } } diff --git a/src/sig/Meteo.java b/src/sig/Meteo.java index c43c5da..2087f5f 100644 --- a/src/sig/Meteo.java +++ b/src/sig/Meteo.java @@ -4,7 +4,10 @@ import java.util.Random; import javax.swing.JFrame; -public class Meteo { +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +public class Meteo implements MouseListener{ public final static int SCREEN_WIDTH=640; public final static int SCREEN_HEIGHT=640; public static long FRAMECOUNT=0; @@ -22,12 +25,11 @@ public class Meteo { b.run(FRAMECOUNT); } - public static void main(String[] args) { + Meteo(JFrame f) { r = new Random(437210983125739812l); double[] val = {0,0,}; b = new Board(SCREEN_WIDTH/2,SCREEN_HEIGHT/2,24,24,8,14,-0.065,5,4,-2,val); - JFrame f = new JFrame("Meteo Engine"); Panel p = new Panel(); new Thread() { @@ -57,9 +59,40 @@ public class Meteo { } }.start(); + f.addMouseListener(this); f.add(p); f.setSize(SCREEN_WIDTH,SCREEN_HEIGHT); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } + + public static void main(String[] args) { + JFrame f = new JFrame("Meteo Engine"); + new Meteo(f); + } + + @Override + public void mouseClicked(MouseEvent e) { + b.mouseClicked(e); + } + + @Override + public void mousePressed(MouseEvent e) { + b.mousePressed(e); + } + + @Override + public void mouseReleased(MouseEvent e) { + b.mouseReleased(e); + } + + @Override + public void mouseEntered(MouseEvent e) { + b.mouseEntered(e); + } + + @Override + public void mouseExited(MouseEvent e) { + b.mouseExited(e); + } } \ No newline at end of file