Block dragging.
This commit is contained in:
parent
f977a3d3b5
commit
79a410a563
BIN
Meteo_Engine.jar
BIN
Meteo_Engine.jar
Binary file not shown.
@ -300,4 +300,21 @@ public class Board {
|
||||
public void mouseExited(MouseEvent e) {
|
||||
//System.out.println("Exited: "+e.getPoint());
|
||||
}
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
//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).collect(Collectors.toList());
|
||||
for (Block b : adjacentBlocks) {
|
||||
if (new Rectangle(b.draw_x,b.draw_y,block_width,block_height).contains(e.getPoint())) {
|
||||
int oldY = clickBlock.y;
|
||||
clickBlock.y = b.y;
|
||||
b.y=oldY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
//System.out.println("Moved: "+e.getPoint());
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,9 @@ import javax.swing.JFrame;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
public class Meteo implements MouseListener{
|
||||
public class Meteo implements MouseListener,MouseMotionListener{
|
||||
public final static int SCREEN_WIDTH=640;
|
||||
public final static int SCREEN_HEIGHT=640;
|
||||
public static long FRAMECOUNT=0;
|
||||
@ -60,6 +61,7 @@ public class Meteo implements MouseListener{
|
||||
}.start();
|
||||
|
||||
f.getContentPane().addMouseListener(this);
|
||||
f.getContentPane().addMouseMotionListener(this);
|
||||
f.add(p);
|
||||
f.setSize(SCREEN_WIDTH,SCREEN_HEIGHT);
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
@ -95,4 +97,14 @@ public class Meteo implements MouseListener{
|
||||
public void mouseExited(MouseEvent e) {
|
||||
b.mouseExited(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
b.mouseDragged(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
b.mouseMoved(e);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user