Ability to select blocks.
This commit is contained in:
parent
06f5a93e6c
commit
d96f29c3c5
BIN
Meteo_Engine.jar
BIN
Meteo_Engine.jar
Binary file not shown.
@ -6,6 +6,7 @@ import java.awt.Color;
|
|||||||
public class Block{
|
public class Block{
|
||||||
BlockState state;
|
BlockState state;
|
||||||
int x,y; //Relative to its block clump
|
int x,y; //Relative to its block clump
|
||||||
|
int draw_x,draw_y;
|
||||||
final static BlockState[] STARTINGSTATES = {BlockState.BLUE,
|
final static BlockState[] STARTINGSTATES = {BlockState.BLUE,
|
||||||
BlockState.GREEN,
|
BlockState.GREEN,
|
||||||
BlockState.ORANGE,
|
BlockState.ORANGE,
|
||||||
@ -22,12 +23,23 @@ public class Block{
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "Block [state=" + state + ", x=" + x + ", y=" + y + "]";
|
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) {
|
if (Meteo.DEBUG_DRAWING==DebugMode.MODE0&&launched<=-1) {
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
} else {
|
} else {
|
||||||
g.setColor(state.getCol());
|
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();
|
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) {
|
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) {
|
if (Meteo.DEBUG_DRAWING==DebugMode.MODE2) {
|
||||||
g.setColor(Color.BLACK);
|
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);
|
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;
|
int attack_counter=0;
|
||||||
|
|
||||||
BlockClump clumpClickId;
|
BlockClump clumpClickId;
|
||||||
Block clickBlockX;
|
Block clickBlock;
|
||||||
|
|
||||||
final static BlockState[] STARTINGSTATES = {BlockState.BLUE,
|
final static BlockState[] STARTINGSTATES = {BlockState.BLUE,
|
||||||
BlockState.GREEN,
|
BlockState.GREEN,
|
||||||
@ -252,7 +252,7 @@ public class Board {
|
|||||||
final int DRAW_ENDX = (int)(x + block_width*((double)width/2));
|
final int DRAW_ENDX = (int)(x + block_width*((double)width/2));
|
||||||
|
|
||||||
for (BlockClump bc : blockData) {
|
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.setColor(Color.BLACK);
|
||||||
g.fillRoundRect(DRAW_STARTX, DRAW_STARTY+block_height, DRAW_ENDX-DRAW_STARTX, 3, 3, 1);
|
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) {
|
public void mousePressed(MouseEvent e) {
|
||||||
//System.out.println("Pressed: "+e.getPoint());
|
//System.out.println("Pressed: "+e.getPoint());
|
||||||
//Adjust Y coordinate based on where the board is positioned.
|
//Adjust Y coordinate based on where the board is positioned.
|
||||||
int MOUSEX = e.getX();
|
clickBlock=null;
|
||||||
int MOUSEY = y-e.getY();
|
clumpClickId=null;
|
||||||
|
outer:
|
||||||
for (BlockClump bc : blockData) {
|
for (BlockClump bc : blockData) {
|
||||||
Rectangle bounds = new Rectangle((int)(bc.x+x),(int)(bc.y+y),width*block_width,bc.maxBlockHeight*block_height);
|
for (Block b : bc.getBlocks()) {
|
||||||
if (bounds.contains(MOUSEX,MOUSEY)) {
|
if (new Rectangle(b.draw_x,b.draw_y,block_width,block_height).contains(e.getPoint())) {
|
||||||
System.out.println("Clicked inside clump "+bc);
|
clickBlock=b;
|
||||||
break;
|
clumpClickId=bc;
|
||||||
} else {
|
break outer;
|
||||||
System.out.println("Off by "+(bc.x+x-MOUSEX)+","+(bc.y+y-MOUSEY));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public class Meteo implements MouseListener{
|
|||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
|
||||||
f.addMouseListener(this);
|
f.getContentPane().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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user