Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 118 lines (97 sloc) 3.703 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
class ZPiece extends Piece {

/*
# 1 336633 (green)
## 02
# 3

*/

public ZPiece(float x, float y) {
super.setX(x);
super.setY(y);

blocks[0] = new Block(x + offsetX[0], y + offsetY[0], blockSize, "#336633");
blocks[1] = new Block(x + offsetX[1], y + offsetY[1], blockSize, "#336633");
blocks[2] = new Block(x + offsetX[2], y + offsetY[2], blockSize, "#336633");
blocks[3] = new Block(x + offsetX[3], y + offsetY[3], blockSize, "#336633");

update();

// 45 deg pieces don't line up right
// TODO: figure out math to get rid of this
super.round(blocks[0]);
super.round(blocks[1]);
super.round(blocks[2]);
super.round(blocks[3]);
}

public void setRotation(float angle) {
if(angle >= radians(0.0f) && angle <= radians(90.0f)) {
this.rotation = radians(90.0f);
} else if (angle >= radians(90.0f) && angle <= radians(180.0f)) {
this.rotation = radians(0.0f);
}
}

public boolean rotateCollideX(float wallStart, float wallWidth) {
// update test coords for coll test
testUpdate();
return(super.rotateCollideX(wallStart, wallWidth));
}

public boolean rotateCollideY(float roomStart, float roomWidth) {
// are we near the bottom?
if (super.pivotPoint.getY() < roomWidth / 2) {
if (super.pivotPoint.getY() + blockSize * 3 < roomWidth) {
// we are nowhere near the bottom
return false;
} else {
testUpdate();
return(super.rotateCollideYHit(roomStart, roomWidth));
}
}
// default return
return false;
}

public boolean rotateCollide(Block deadGrid[][], Point2d playField[], int gridSizeX, int gridSizeY) {
//println("rotateCollide in LPiece");
// are we near the grid, if not, don't waste cycles
if (super.nearGrid(deadGrid, playField, gridSizeX, gridSizeY)) {
testUpdate();
// call super method to check for hit
//println("rotateCollide in LPiece");
return(super.rotateCollideHit(deadGrid, gridSizeX, gridSizeY, testOffsetX, testOffsetY, playField));
}
return false;
}

/* Call this whenever moving or rotating */
public void update() {

offsetX[0] = 0;
offsetX[1] = sin(rotation + radians(45)) * (blockSize + (blockSize / 2));
offsetX[2] = sin(rotation + radians(90)) * blockSize;
offsetX[3] = sin(rotation + radians(180)) * blockSize;

offsetY[0] = 0;
offsetY[1] = cos(rotation + radians(225)) * (blockSize + (blockSize / 2));
offsetY[2] = cos(rotation + radians(270)) * blockSize;
offsetY[3] = cos(rotation + radians(0)) * blockSize;

for (int i=0; i<4; i++) {
blocks[i].setX(super.pivotPoint.getX() + offsetX[i]);
blocks[i].setY(super.pivotPoint.getY() + offsetY[i]);
}

// rounding to line up with grid
// TODO: better way?
super.round(blocks[0]);
super.round(blocks[1]);
super.round(blocks[2]);
super.round(blocks[3]);

}

// this method is called to test collision without updating position, it's like look-ahead
public void testUpdate() {
testRotation = rotation + radians(90.0f);

testOffsetX[0] = 0;
testOffsetX[1] = sin(testRotation + radians(45)) * (blockSize + (blockSize / 2));
testOffsetX[2] = sin(testRotation + radians(90)) * blockSize;
testOffsetX[3] = sin(testRotation + radians(180)) * blockSize;

        testOffsetY[0] = 0;
testOffsetY[1] = cos(testRotation + radians(225)) * (blockSize + (blockSize / 2));
testOffsetY[2] = cos(testRotation + radians(270)) * blockSize;
testOffsetY[3] = cos(testRotation + radians(0)) * blockSize;

// round our test offsets to blocksize
for (int i=0; i<4; i++) {
testOffsetX[i] = Math.round(testOffsetX[i] / blockSize) * blockSize;
testOffsetY[i] = Math.round(testOffsetY[i] / blockSize) * blockSize;
}
}

}
Something went wrong with that request. Please try again.