Skip to content

Commit

Permalink
090307a archive
Browse files Browse the repository at this point in the history
  • Loading branch information
Sproinks committed Mar 19, 2009
1 parent f5b4734 commit 70f8814
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 93 deletions.
20 changes: 7 additions & 13 deletions Block.pde
Expand Up @@ -22,21 +22,12 @@ class Block {
stroke(0,150); // black border, mostly opaque
strokeWeight(3);

//translate(x,y);
fill(fillColor[0], fillColor[1], fillColor[2]);
rect(this.x+x, this.y+y,height,width);
fill(255);
text(this.x+x + "," + this.y+y, this.x+x, this.y+y);


/*
beginShape();
vertex(-height/2, height/2);
vertex(-height/2, -height/2);
vertex(height/2, -height/2);
vertex(height/2, height/2);
endShape(CLOSE);
*/
// debug text
//fill(255);
//text(this.x+x + "," + this.y+y, this.x+x, this.y+y);
}

// dead grid calls this
Expand All @@ -46,7 +37,10 @@ class Block {
strokeWeight(3);
fill(fillColor[0], fillColor[1], fillColor[2]);
rect(this.x, this.y,height,width);
text(x + "," + y, x, y);

// debug text
//fill(255);
//text(x + "," + y, x, y);
}

public void setX(float x) {
Expand Down
34 changes: 13 additions & 21 deletions LPiece.pde
@@ -1,4 +1,4 @@
class LPiece extends Piece implements Cloneable {
class LPiece extends Piece {

/*
3 #
Expand Down Expand Up @@ -30,14 +30,6 @@ class LPiece extends Piece implements Cloneable {
super.round(blocks[1]);
super.round(blocks[3]);
}

public Object clone() {
try {
return super.clone();
} catch (Exception e) {
return null;
}
}

public void setRotation(float angle) {
this.rotation = angle;
Expand All @@ -52,7 +44,7 @@ class LPiece extends Piece implements Cloneable {
// are we more right?
if (super.pivotPoint.getX() > wallWidth / 2) {
if (super.pivotPoint.getX() + blockSize * 3 < wallWidth) {
println("nowhere close near east wall");
//println("nowhere close near east wall");
return false;
} else {
float tmpRotation = rotation + 90.0f;
Expand All @@ -64,29 +56,29 @@ class LPiece extends Piece implements Cloneable {
tmpOffsetX[3] = sin(tmpRotation + radians(315)) * (blockSize + (blockSize / 2));

if (super.pivotPoint.getX()+tmpOffsetX[0] >= wallWidth) {
println("denied 0");
//println("denied 0");
return true;
}
if (super.pivotPoint.getX()+tmpOffsetX[1] >= wallWidth) {
println("denied 1");
//println("denied 1");
return true;
}
if (super.pivotPoint.getX()+tmpOffsetX[2] >= wallWidth) {
println("denied 2");
//println("denied 2");
return true;
}
if (super.pivotPoint.getX()+tmpOffsetX[3] >= wallWidth) {
println("denied 3");
//println("denied 3");
return true;
}
println("allowed west");
//println("allowed west");
return false;
}

// or are we more left?
} else {
if (super.pivotPoint.getX() - blockSize * 2 > wallStart) {
println("nowhere close near west wall");
//println("nowhere close near west wall");
return false;
} else {
float tmpRotation = rotation + 90.0f;
Expand All @@ -97,22 +89,22 @@ class LPiece extends Piece implements Cloneable {
tmpOffsetX[2] = sin(tmpRotation + radians(270)) * blockSize;
tmpOffsetX[3] = sin(tmpRotation + radians(315)) * (blockSize + (blockSize / 2));
if (super.pivotPoint.getX()+tmpOffsetX[0] < wallStart - blockSize/2) {
println("denied 0");
//println("denied 0");
return true;
}
if (super.pivotPoint.getX()+tmpOffsetX[1] < wallStart - blockSize/2) {
println("denied 1");
//println("denied 1");
return true;
}
if (super.pivotPoint.getX()+tmpOffsetX[2] < wallStart - blockSize/2) {
println("denied 2");
//println("denied 2");
return true;
}
if (super.pivotPoint.getX()+tmpOffsetX[3] < wallStart - blockSize/2) {
println("denied 3");
//println("denied 3");
return true;
}
println("allowed east");
//println("allowed east");
return false;
}

Expand Down
42 changes: 31 additions & 11 deletions Piece.pde
@@ -1,7 +1,7 @@
import java.util.ArrayList;

// blocks move together as one set of blocks, offset by shape pattern
class Piece implements Cloneable {
class Piece {

float x; // center x
float y; // center y
Expand All @@ -14,14 +14,6 @@ class Piece implements Cloneable {

}

public Object clone() {
try {
return super.clone();
} catch (Exception e) {
return null;
}
}

public void draw() {
for (int i=0; i < 4; i++) {
blocks[i].draw(x,y);
Expand Down Expand Up @@ -93,6 +85,34 @@ class Piece implements Cloneable {
return greatest;
}



// this is used when dropping pieces
public Block[] getMaxYBlocks() {
HashMap map = new HashMap();

for (int i=0; i<blocks.length; i++) {
Block test = (Block)map.get(blocks[i].getX());

if(test != null) {
if (blocks[i].getY() > test.getY()){
map.put(blocks[i].getX(), blocks[i]);
}
} else {
map.put(blocks[i].getX(), blocks[i]);
}

}

Block returnBlocks[] = new Block[map.size()];
int i = 0;

Set mapset= map.keySet();
Iterator iter = mapset.iterator();
while(iter.hasNext()){
Float currentKey = (Float)iter.next();
returnBlocks[i++] = (Block)map.get(currentKey);
}

return returnBlocks;
}

}

0 comments on commit 70f8814

Please sign in to comment.