Add debug drawing mode

concurrentModificationException1
sigonasr2, Sig, Sigo 3 years ago
parent dbb8a0f88d
commit 4adb954e34
  1. BIN
      Meteo_Engine.jar
  2. 9
      src/sig/Block.java
  3. 17
      src/sig/BlockClump.java
  4. 33
      src/sig/Board.java
  5. 6
      src/sig/DebugMode.java
  6. 1
      src/sig/Meteo.java

Binary file not shown.

@ -1,6 +1,7 @@
package sig;
import java.awt.Graphics;
import java.awt.Color;
public class Block{
BlockState state;
@ -21,8 +22,12 @@ 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) {
g.setColor(state.getCol());
public void draw(Graphics g, double x, double y, int block_width, int block_height,int launched) {
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);
}
}

@ -4,6 +4,7 @@ import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.awt.Color;
public class BlockClump {
private List<Block> blocks;
@ -14,7 +15,7 @@ public class BlockClump {
Negative is for when block clumps are divided into smaller columns for re-sorting.
Positive is used for how much landing launch time before being split and falling.*/
public BlockClump(List<Block> blockList, double x, double y, double startspd, int width) {
public BlockClump(List<Block> blockList, double x, double y, double startspd, int width, int launched) {
this.blocks = new ArrayList<Block>();
this.blocks.addAll(blockList);
collisionColumnRanges = new int[width][];
@ -27,6 +28,7 @@ public class BlockClump {
this.x=x;
this.y=y;
this.yspd=startspd;
this.launched=launched;
}
public void updateBlockCollision() {
//Call this whenever the block structure changes. This will define what the top and bottom positions
@ -44,7 +46,18 @@ public class BlockClump {
}
public void drawBlocks(Graphics g, int originX, int originY, int block_width, int block_height) {
for (Block b : blocks) {
b.draw(g,originX+x*block_width,originY-y,block_width,block_height);
b.draw(g,originX+x*block_width,originY-y,block_width,block_height,launched);
}
}
public void drawClumpOutlines(Graphics g, int originX, int originY, int block_width, int block_height) {
if (Meteo.DEBUG_DRAWING==DebugMode.MODE0) {
g.setColor(new Color(0,255,0,128));
for (int i=0;i<collisionColumnRanges.length;i++) {
if (collisionColumnRanges[i][0]!=-1) {
g.drawRect((int)(x+i*block_width)+originX,(int)(originY-y-(block_height*(collisionColumnRanges[i][1]-collisionColumnRanges[i][0]))),block_width,block_height*(collisionColumnRanges[i][1]-collisionColumnRanges[i][0]+1));
g.drawRect((int)(x+i*block_width)+originX+1,(int)(originY+1-y-(block_height*(collisionColumnRanges[i][1]-collisionColumnRanges[i][0]))),block_width,block_height*(collisionColumnRanges[i][1]-collisionColumnRanges[i][0]+1));
}
}
}
}

@ -45,7 +45,7 @@ public class Board {
}
}
BlockClump defaultClump = new BlockClump(initialBlocks,0,260,0,width);
BlockClump defaultClump = new BlockClump(initialBlocks,0,260,0,width,120);
List<Block> initialBlocks2 = new ArrayList<Block>();
for (int x=0;x<boardWidth;x++) {
@ -53,19 +53,20 @@ public class Board {
initialBlocks2.add(new Block(x,y));
}
}
BlockClump defaultClump2 = new BlockClump(initialBlocks2,0,540,0,width);
BlockClump defaultClump2 = new BlockClump(initialBlocks2,0,540,0,width,120);
blockData.add(defaultClump);
blockData.add(defaultClump2);
}
public void run(long frames) {
if (frames%100==0) {
blockData.add(new BlockClump(Arrays.asList(new Block((int)(Math.random()*width),0)),0,590,0,width));
blockData.add(new BlockClump(Arrays.asList(new Block((int)(Math.random()*width),0)),0,590,0,width,-1));
}
outerloop:
for (BlockClump blocks : blockData) {
double FUTURE_FALL_POSITION = blocks.y+blocks.yspd+gravity;
boolean handleCollision = false;
outerloop:
for (int x=0;x<width;x++) {
if (blocks.collisionColumnRanges[x][0]!=-1) {
for (BlockClump blocks2 : blockData) {
@ -73,11 +74,13 @@ public class Board {
if (FUTURE_FALL_POSITION<blocks2.y) {
if (FUTURE_FALL_POSITION+blocks.collisionColumnRanges[x][1]*block_height>blocks2.y+(blocks2.collisionColumnRanges[x][0]+1)*block_height) {
HandleBlockLand(blocks, x, blocks2.y+(blocks2.collisionColumnRanges[x][0]+1)*block_height);
handleCollision=true;
continue outerloop;
}
} else {
if (FUTURE_FALL_POSITION+blocks.collisionColumnRanges[x][0]*block_height<blocks2.y+(blocks2.collisionColumnRanges[x][1]+1)*block_height) {
HandleBlockLand(blocks, x, blocks2.y+(blocks2.collisionColumnRanges[x][1]+1)*block_height);
handleCollision=true;
continue outerloop;
}
}
@ -85,13 +88,14 @@ public class Board {
}
}
}
if (FUTURE_FALL_POSITION>0) {
blocks.yspd=Math.max(blocks.yspd+gravity,max_fall_spd);
blocks.y+=blocks.yspd;
} else {
//We have hit the bottom.
blocks.yspd=0;
blocks.y=0;
if (!handleCollision) {
if (FUTURE_FALL_POSITION>0) {
blocks.yspd=Math.max(blocks.yspd+gravity,max_fall_spd);
blocks.y+=blocks.yspd;
} else {
//We have hit the bottom.
HandleBlockLand(blocks, x, 0);
}
}
//System.out.println(blocks.y);
}
@ -107,7 +111,7 @@ public class Board {
private void HandleBlockLand(BlockClump blocks, int x, double yset) {
blocks.yspd=0;
blocks.y=yset;
if (blocks.launched--==-1) {
if (blocks.launched--==0) {
SplitBlockClump(blocks);
}
}
@ -118,7 +122,7 @@ public class Board {
blockClumpAddList.add(
new BlockClump(
blocks.getBlocks().stream().filter((block)->block.x==column).collect(Collectors.toList()),
0,blocks.y,blocks.yspd,width)
0,blocks.y,blocks.yspd,width,blocks.launched)
);
}
}
@ -134,5 +138,8 @@ public class Board {
}
g.setColor(Color.BLACK);
g.fillRoundRect(DRAW_STARTX, DRAW_STARTY+block_height, DRAW_ENDX-DRAW_STARTX, 3, 3, 1);
for (BlockClump bc : blockData) {
bc.drawClumpOutlines(g,DRAW_STARTX,DRAW_STARTY,block_width,block_height);
}
}
}

@ -0,0 +1,6 @@
package sig;
public enum DebugMode {
OFF,
MODE0, //Displays blocks ready for connecting in black and block clumps with green rectangles.
}

@ -15,6 +15,7 @@ public class Meteo {
public static Board b;
public final static long TIMEPERTICK = 16666667l;
public static DebugMode DEBUG_DRAWING = DebugMode.MODE0;
public static void runGameLoop() {
FRAMECOUNT++;

Loading…
Cancel
Save