Added mouse event detection.
This commit is contained in:
parent
e47758f30a
commit
06f5a93e6c
BIN
Meteo_Engine.jar
BIN
Meteo_Engine.jar
Binary file not shown.
@ -1,7 +1,9 @@
|
|||||||
package sig;
|
package sig;
|
||||||
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -20,6 +22,10 @@ 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;
|
||||||
|
|
||||||
|
BlockClump clumpClickId;
|
||||||
|
Block clickBlockX;
|
||||||
|
|
||||||
final static BlockState[] STARTINGSTATES = {BlockState.BLUE,
|
final static BlockState[] STARTINGSTATES = {BlockState.BLUE,
|
||||||
BlockState.GREEN,
|
BlockState.GREEN,
|
||||||
BlockState.ORANGE,
|
BlockState.ORANGE,
|
||||||
@ -256,4 +262,31 @@ public class Board {
|
|||||||
g.drawString(Integer.toString(blockData.size()),4,Meteo.SCREEN_HEIGHT-20);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,10 @@ import java.util.Random;
|
|||||||
|
|
||||||
import javax.swing.JFrame;
|
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_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;
|
||||||
@ -22,12 +25,11 @@ public class Meteo {
|
|||||||
b.run(FRAMECOUNT);
|
b.run(FRAMECOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
Meteo(JFrame f) {
|
||||||
r = new Random(437210983125739812l);
|
r = new Random(437210983125739812l);
|
||||||
double[] val = {0,0,};
|
double[] val = {0,0,};
|
||||||
b = new Board(SCREEN_WIDTH/2,SCREEN_HEIGHT/2,24,24,8,14,-0.065,5,4,-2,val);
|
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();
|
Panel p = new Panel();
|
||||||
|
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@ -57,9 +59,40 @@ public class Meteo {
|
|||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
|
||||||
|
f.addMouseListener(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);
|
||||||
f.setVisible(true);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user