Compare commits

...

18 Commits

Author SHA1 Message Date
Nic0Nic0Nii 09286d3c9c Resolved bottoming out edge cases with collisions. No more empty block bugs. 3 years ago
Nic0Nic0Nii c68177f5f5 Resolved bottoming out edge cases with collisions. No more empty block bugs. 3 years ago
Nic0Nic0Nii c542d07708 zzz 3 years ago
Nic0Nic0Nii b7bcc03e1f Typo... 3 years ago
Nic0Nic0Nii b60881e533 Setup test environment. 3 years ago
Nic0Nic0Nii 8515f20cc9 Testing here. 3 years ago
Nic0Nic0Nii 6153279f6d Merge branch 'master' of https://github.com/sigonasr2/meteo_engine 3 years ago
Nic0Nic0Nii df50a64803 Testing 3 years ago
Nic0Nic0Nii 350d91f16e Test 3 years ago
Nic0Nic0Nii ea484ddc11 co-author included. 3 years ago
Nic0Nic0Nii a27b216dfc Revert "Sample joint commit." 3 years ago
Nic0Nic0Nii 548c38309d Sample joint commit. 3 years ago
Nic0Nic0Nii ff520f5814 Add setup shell file and coauthors file. 3 years ago
Nic0Nic0Nii 436dce0901 update gitpod.yml 3 years ago
Nic0Nic0Nii 6117e6021d Add proper gitpod.yml 3 years ago
Nic0Nic0Nii 8ef5b04212 Mouse block dragging. 3 years ago
Nic0Nic0Nii 79a410a563 Block dragging. 3 years ago
Nic0Nic0Nii f977a3d3b5 Remove all iterator concurrent checks. 3 years ago
  1. 7
      .gitpod.yml
  2. BIN
      Meteo_Engine.jar
  3. 45
      coauthors.sh
  4. 3
      gitpod.yml
  5. 18
      src/sig/BlockClump.java
  6. 153
      src/sig/Board.java
  7. 16
      src/sig/CollisionRangeIdentifier.java
  8. 35
      src/sig/Meteo.java
  9. 11
      src/sig/MouseEventType.java
  10. 12
      src/sig/MouseQueue.java

@ -0,0 +1,7 @@
# List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/
tasks:
- init: sh ./coauthors.sh
vscode:
extensions:
- redhat.java
- mhutchie.git-graph

Binary file not shown.

@ -0,0 +1,45 @@
npm i -g git-mob
cat <<-EOF > ~/.git-coauthors
{
"coauthors": {
"sig": {
"name": "sigonasr2",
"email": "sigonasr2@gmail.com"
}
}
}
EOF
git mob sig
cat <<-EOF > .git/hooks/prepare-commit-msg
#!/usr/bin/env node
let exec = require('child_process').exec,
fs = require('fs');
const commitMessage = process.argv[2];
// expect .git/COMMIT_EDITMSG
if(/COMMIT_EDITMSG/g.test(commitMessage)){
let contents = "";
exec("git mob-print",
function (err, stdout) {
if(err) {
process.exit(0);
}
// opens .git/COMMIT_EDITMSG
contents = fs.readFileSync(commitMessage);
if(contents.indexOf(stdout.trim()) !== -1) {
process.exit(0);
}
const commentPos = contents.indexOf('# ');
const gitMessage = contents.slice(0, commentPos);
const gitComments = contents.slice(commentPos)
fs.writeFileSync(commitMessage, gitMessage + stdout + gitComments);
process.exit(0);
});
}
EOF
chmod +x .git/hooks/prepare-commit-msg
echo "Environment is setup!"

@ -1,3 +0,0 @@
vscode:
extensions:
- redhat.java

@ -38,7 +38,10 @@ public class BlockClump {
for (int i=0;i<collisionColumnRanges.length;i++) {
collisionColumnRanges[i] = new int[]{-1,-1};
}
for (Block b : blocks) {updateBlockCollisionRangeWithBlock(b);}
for (int i=0;i<blocks.size();i++) {
Block b = blocks.get(i);
updateBlockCollisionRangeWithBlock(b);
}
}
public void addBlock(Block...blocks) {
//Adds the block to the strucutre. Update collision column ranges to reflect the new bounds.
@ -55,7 +58,8 @@ public class BlockClump {
updateBlockCollision();
}
public void drawBlocks(Graphics g, int originX, int originY, int block_width, int block_height, Block selectedBlock) {
for (Block b : blocks) {
for (int i=0;i<blocks.size();i++) {
Block b = blocks.get(i);
b.draw(g,originX+x,originY-y,block_width,block_height,launched,selectedBlock!=null&&selectedBlock.equals(b));
if (Meteo.DEBUG_DRAWING==DebugMode.MODE2) {
g.setColor(Color.BLACK);
@ -68,8 +72,8 @@ public class BlockClump {
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));
g.drawRect((int)(x+i*block_width)+originX,(int)(originY-y-(block_height*(collisionColumnRanges[i][1]))),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]))),block_width,block_height*(collisionColumnRanges[i][1]-collisionColumnRanges[i][0]+1));
}
}
}
@ -105,10 +109,12 @@ public class BlockClump {
return "BlockClump [blocks=" + blocks + ", x=" + x + ", y=" + y + ", yspd=" + yspd + "]";
}
public static void drawDebugBlockClumps(Graphics g, int originX, int originY, int block_width, int block_height, List<BlockClump> blockData) {
for (BlockClump bc : blockData) {
for (int i=0;i<blockData.size();i++) {
BlockClump bc = blockData.get(i);
bc.drawClumpOutlines(g,originX,originY,block_width,block_height);
}
for (BlockClump bc : blockData) {
for (int i=0;i<blockData.size();i++) {
BlockClump bc = blockData.get(i);
bc.drawClumpDots(g,originX,originY,block_width,block_height);
}
}

@ -58,30 +58,50 @@ public class Board {
}
outerloop:
for (BlockClump blocks : blockData) {
for (int i=0;i<blockData.size();i++) {
BlockClump blocks = blockData.get(i);
DestroyOutsideBlocks(blocks);
if (checkForMatches(blocks)) {continue;}
double FUTURE_FALL_POSITION = blocks.y+blocks.yspd+gravity;
for (int x=0;x<width;x++) {
List<CollisionRangeIdentifier> ranges = new ArrayList<CollisionRangeIdentifier>();
for (int k=0;k<blocks.collisionColumnRanges.length;k++) {
int[] range = blocks.collisionColumnRanges[k];
ranges.add(new CollisionRangeIdentifier(k, range));
}
ranges = ranges.stream().sorted((a,b)->a.range[0]-b.range[0]).collect(Collectors.toList());
//System.out.println(ranges);
for (int l=0;l<ranges.size();l++) {
int x=ranges.get(l).index;
if (blocks.collisionColumnRanges[x][0]!=-1) {
for (BlockClump blocks2 : blockData) {
for (int j=0;j<blockData.size();j++) {
BlockClump blocks2 = blockData.get(j);
if (!blocks.equals(blocks2)&&blocks2.collisionColumnRanges[x][1]!=-1) {
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);
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);
if (blocks.launched==-1) {
CombineAToB(blocks,blocks2);
blocks.launched=-2;
if (blocks.yspd>0) {
if (blocks2.y+(blocks2.collisionColumnRanges[x][0])*block_height>FUTURE_FALL_POSITION+(blocks.collisionColumnRanges[x][1])*block_height) {
if (FUTURE_FALL_POSITION+(blocks.collisionColumnRanges[x][1])*block_height>blocks2.y+(blocks2.collisionColumnRanges[x][0])*block_height) {
CombineAToBFromBelow(blocks,blocks2);
HandleBlockLand(blocks, x, blocks2.y+(blocks2.collisionColumnRanges[x][0])*block_height-blocks.maxBlockHeight*block_height);
continue outerloop;
}
}
} else {
if (FUTURE_FALL_POSITION+(blocks.collisionColumnRanges[x][0])*block_height<=0) { //Handle reaching the ground.
HandleBlockLand(blocks, x, 0);
continue outerloop;
} else
if (blocks2.y<FUTURE_FALL_POSITION+(blocks.collisionColumnRanges[x][0])*block_height) {
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);
System.out.println(ranges);
if (blocks.launched==-1) {
CombineAToB(blocks,blocks2);
blocks.launched=-2;
}
continue outerloop;
}
continue outerloop;
}
}
}
}
}
}
}
}
}
@ -124,7 +144,8 @@ public class Board {
List<BlockClump> groundedClumps = blockData.stream().filter((cl)->cl.y==0).collect(Collectors.toList());
if (groundedClumps.size()>1) {
BlockClump base = groundedClumps.remove(0);
for (BlockClump bc : groundedClumps) {
for (int i=0;i<groundedClumps.size();i++) {
BlockClump bc = groundedClumps.get(i);
base.addBlock(bc.getBlocks().toArray(new Block[bc.getBlocks().size()]));
}
blockClumpDeleteList.addAll(groundedClumps);
@ -149,7 +170,8 @@ public class Board {
int minY=Integer.MAX_VALUE;
List<Block> newClumpBlocks = new ArrayList<Block>();
newClumpBlocks.addAll(markedBlocks);
for (Block b : markedBlocks) {
for (int i=0;i<markedBlocks.size();i++) {
Block b = markedBlocks.get(i);
b.state = BlockState.IGNITED;
//All blocks above marked blocks now join the clump.
newClumpBlocks.addAll(blocks.getSortedBlocksOnCol(b.x).stream().filter((block)->!newClumpBlocks.contains(block)&&block.y>b.y).collect(Collectors.toList()));
@ -157,11 +179,12 @@ public class Board {
}
//For now just get rid of them.
RemoveBlocks(blocks,newClumpBlocks.toArray(new Block[newClumpBlocks.size()]));
for (Block b : newClumpBlocks) {
for (int i=0;i<newClumpBlocks.size();i++) {
Block b = newClumpBlocks.get(i);
b.y-=minY;
}
blockClumpAddList.add(
new BlockClump(newClumpBlocks, blocks.x, blocks.y+minY*block_height+4, launch_power, width, 120)
new BlockClump(newClumpBlocks, blocks.x, blocks.y+minY*block_height, launch_power, width, 120)
);
}
return markedBlocks.size()>0;
@ -210,7 +233,8 @@ public class Board {
return markedBlocks;
}
private void CombineAToB(BlockClump A, BlockClump B) {
for (Block b : A.getBlocks()) {
for (int i=0;i<A.getBlocks().size();i++) {
Block b = A.getBlocks().get(i);
b.y = B.collisionColumnRanges[b.x][1]+1;
B.addBlock(b);
}
@ -226,7 +250,8 @@ public class Board {
SplitBlockClump(blocks);
}
if (blocks.launched<=0) {
for (Block b : blocks.getBlocks()) {
for (int i=0;i<blocks.getBlocks().size();i++) {
Block b = blocks.getBlocks().get(i);
if (b.state==BlockState.IGNITED) {
b.state=STARTINGSTATES[(int)(Meteo.r.nextInt(3))];
}
@ -251,7 +276,8 @@ public class Board {
final int DRAW_STARTY = (int)(y + block_height*((double)height/2));
final int DRAW_ENDX = (int)(x + block_width*((double)width/2));
for (BlockClump bc : blockData) {
for (int i=0;i<blockData.size();i++) {
BlockClump bc = blockData.get(i);
bc.drawBlocks(g,DRAW_STARTX,DRAW_STARTY,block_width,block_height,clickBlock);
}
g.setColor(Color.BLACK);
@ -262,32 +288,59 @@ 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.
clickBlock=null;
clumpClickId=null;
outer:
for (BlockClump bc : blockData) {
for (Block b : bc.getBlocks()) {
if (new Rectangle(b.draw_x,b.draw_y,block_width,block_height).contains(e.getPoint())) {
clickBlock=b;
clumpClickId=bc;
break outer;
public void handleMouse(MouseQueue mq) {
MouseEvent e = mq.ev;
switch (mq.type) {
case CLICK:
//System.out.println("Clicked: "+e.getPoint());
break;
case DRAG:
//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&&clickBlock.x==block.x).collect(Collectors.toList());
for (Block b : adjacentBlocks) {
if (new Rectangle(0,b.draw_y,Meteo.SCREEN_WIDTH,block_height).contains(e.getPoint())) {
int newY = b.y;
b.y=clickBlock.y;
clickBlock.y = newY;
break;
}
}
}
}
break;
case ENTER:
//System.out.println("Entered: "+e.getPoint());
break;
case EXIT:
//System.out.println("Exited: "+e.getPoint());
break;
case MOVE:
//System.out.println("Moved: "+e.getPoint());
break;
case PRESS:
//System.out.println("Pressed: "+e.getPoint());
//Adjust Y coordinate based on where the board is positioned.
clickBlock=null;
clumpClickId=null;
outer:
for (int i=0;i<blockData.size();i++) {
BlockClump bc = blockData.get(i);
for (int j=0;j<bc.getBlocks().size();j++) {
Block b = bc.getBlocks().get(j);
if (new Rectangle(b.draw_x,b.draw_y,block_width,block_height).contains(e.getPoint())) {
clickBlock=b;
clumpClickId=bc;
break outer;
}
}
}
break;
case RELEASE:
//System.out.println("Released: "+e.getPoint());
break;
default:
break;
}
}
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());
}
}

@ -0,0 +1,16 @@
package sig;
import java.util.Arrays;
public class CollisionRangeIdentifier {
int index;
int[] range;
CollisionRangeIdentifier(int index,int[] range) {
this.index=index;
this.range=range;
}
@Override
public String toString() {
return "CollisionRangeIdentifier [index=" + index + ", range=" + Arrays.toString(range) + "]";
}
}

@ -1,13 +1,16 @@
package sig;
import java.util.Random;
import java.util.List;
import java.util.ArrayList;
import javax.swing.JFrame;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
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;
@ -20,8 +23,15 @@ public class Meteo implements MouseListener{
public final static long TIMEPERTICK = 16666667l;
public static DebugMode DEBUG_DRAWING = DebugMode.MODE2;
public static List<MouseQueue> MOUSE_QUEUE = new ArrayList<MouseQueue>();
public static void runGameLoop() {
FRAMECOUNT++;
for (int i=0;i<MOUSE_QUEUE.size();i++) {
MouseQueue mq = MOUSE_QUEUE.get(i);
b.handleMouse(mq);
}
MOUSE_QUEUE.clear();
b.run(FRAMECOUNT);
}
@ -60,6 +70,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);
@ -73,26 +84,36 @@ public class Meteo implements MouseListener{
@Override
public void mouseClicked(MouseEvent e) {
b.mouseClicked(e);
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.CLICK,e));
}
@Override
public void mousePressed(MouseEvent e) {
b.mousePressed(e);
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.PRESS,e));
}
@Override
public void mouseReleased(MouseEvent e) {
b.mouseReleased(e);
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.RELEASE,e));
}
@Override
public void mouseEntered(MouseEvent e) {
b.mouseEntered(e);
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.ENTER,e));
}
@Override
public void mouseExited(MouseEvent e) {
b.mouseExited(e);
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.EXIT,e));
}
@Override
public void mouseDragged(MouseEvent e) {
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.DRAG,e));
}
@Override
public void mouseMoved(MouseEvent e) {
MOUSE_QUEUE.add(new MouseQueue(MouseEventType.MOVE,e));
}
}

@ -0,0 +1,11 @@
package sig;
public enum MouseEventType {
CLICK,
PRESS,
RELEASE,
ENTER,
EXIT,
DRAG,
MOVE;
}

@ -0,0 +1,12 @@
package sig;
import java.awt.event.MouseEvent;
public class MouseQueue {
MouseEventType type;
MouseEvent ev;
MouseQueue(MouseEventType type,MouseEvent ev) {
this.type=type;
this.ev=ev;
}
}
Loading…
Cancel
Save