Skip to content

Commit

Permalink
All blocks have been implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
graninas committed Jul 20, 2014
1 parent d915448 commit d25f755
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Tetris.pde
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
static final int w = 4;
static final int h = 20; // 60
static final int framesInSecond = 30;
static final float gameSpeed = framesInSecond / 2.0;
static final float gameSpeed = framesInSecond / 5.0; // moving down ~5 times in second

float updatingThreshold = 0;
Game game;
Expand Down
160 changes: 160 additions & 0 deletions TetrisBlockConstruct.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
BlockPart[] getIBlockParts(int direction) {
BlockPart[] parts = new BlockPart[BlockPartsCount];
if ((direction == East) || (direction == West)) {
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(1,0);
parts[2] = new BlockPart(2,0);
parts[3] = new BlockPart(3,0);
} else {
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(0,2);
parts[3] = new BlockPart(0,3);
}
return parts;
}

BlockPart[] getOBlockParts() {
BlockPart[] parts = new BlockPart[BlockPartsCount];
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(1,0);
parts[2] = new BlockPart(0,1);
parts[3] = new BlockPart(1,1);
return parts;
}

BlockPart[] getTBlockParts(int direction) {
BlockPart[] parts = new BlockPart[BlockPartsCount];
switch (direction) {
case East:
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(1,0);
parts[2] = new BlockPart(2,0);
parts[3] = new BlockPart(1,1);
break;
case South:
parts[0] = new BlockPart(1,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(1,1);
parts[3] = new BlockPart(1,2);
break;
case North:
parts[0] = new BlockPart(1,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(1,1);
parts[3] = new BlockPart(2,1);
break;
case West:
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(1,1);
parts[3] = new BlockPart(0,2);
break;
}
return parts;
}

BlockPart[] getSBlockParts(int direction) {
BlockPart[] parts = new BlockPart[BlockPartsCount];
switch (direction) {
case East:
case West:
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(1,1);
parts[3] = new BlockPart(1,2);
break;
case South:
case North:
parts[0] = new BlockPart(0,1);
parts[1] = new BlockPart(1,0);
parts[2] = new BlockPart(1,1);
parts[3] = new BlockPart(2,1);
break;
}
return parts;
}

BlockPart[] getZBlockParts(int direction) {
BlockPart[] parts = new BlockPart[BlockPartsCount];
switch (direction) {
case East:
case West:
parts[0] = new BlockPart(1,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(1,1);
parts[3] = new BlockPart(0,2);
break;
case South:
case North:
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(1,0);
parts[2] = new BlockPart(1,1);
parts[3] = new BlockPart(2,1);
break;
}
return parts;
}

BlockPart[] getJBlockParts(int direction) {
BlockPart[] parts = new BlockPart[BlockPartsCount];
switch (direction) {
case East:
parts[0] = new BlockPart(1,0);
parts[1] = new BlockPart(1,1);
parts[2] = new BlockPart(0,2);
parts[3] = new BlockPart(1,2);
break;
case South:
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(1,1);
parts[3] = new BlockPart(2,1);
break;
case North:
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(1,0);
parts[2] = new BlockPart(0,1);
parts[3] = new BlockPart(0,2);
break;
case West:
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(1,0);
parts[2] = new BlockPart(2,0);
parts[3] = new BlockPart(2,1);
break;
}
return parts;
}

BlockPart[] getLBlockParts(int direction) {
BlockPart[] parts = new BlockPart[BlockPartsCount];
switch (direction) {
case East:
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(0,2);
parts[3] = new BlockPart(1,2);
break;
case South:
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(1,0);
parts[3] = new BlockPart(2,0);
break;
case North:
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(1,0);
parts[2] = new BlockPart(1,1);
parts[3] = new BlockPart(1,2);
break;
case West:
parts[0] = new BlockPart(0,1);
parts[1] = new BlockPart(1,1);
parts[2] = new BlockPart(2,0);
parts[3] = new BlockPart(2,1);
break;
}
return parts;
}

59 changes: 4 additions & 55 deletions TetrisBlockProcess.pde
Original file line number Diff line number Diff line change
@@ -1,65 +1,14 @@
BlockPart[] getIBlockParts(int direction) {
BlockPart[] parts = new BlockPart[BlockPartsCount];
if ((direction == East) || (direction == West)) {
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(1,0);
parts[2] = new BlockPart(2,0);
parts[3] = new BlockPart(3,0);
} else {
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(0,2);
parts[3] = new BlockPart(0,3);
}
return parts;
}

BlockPart[] getOBlockParts() {
BlockPart[] parts = new BlockPart[BlockPartsCount];
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(1,0);
parts[2] = new BlockPart(0,1);
parts[3] = new BlockPart(1,1);
return parts;
}

BlockPart[] getTBlockParts(int direction) {
BlockPart[] parts = new BlockPart[BlockPartsCount];
switch (direction) {
case East:
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(1,0);
parts[2] = new BlockPart(2,0);
parts[3] = new BlockPart(1,1);
break;
case South:
parts[0] = new BlockPart(1,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(1,1);
parts[3] = new BlockPart(1,2);
break;
case North:
parts[0] = new BlockPart(1,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(1,1);
parts[3] = new BlockPart(2,1);
break;
case West:
parts[0] = new BlockPart(0,0);
parts[1] = new BlockPart(0,1);
parts[2] = new BlockPart(1,1);
parts[3] = new BlockPart(0,2);
break;
}
return parts;
}

BlockPart[] getBlockParts(Block block) {
switch(block.type) {
case I: return getIBlockParts(block.direction);
case O: return getOBlockParts();
case T: return getTBlockParts(block.direction);

case S: return getSBlockParts(block.direction);
case Z: return getZBlockParts(block.direction);
case J: return getJBlockParts(block.direction);
case L: return getLBlockParts(block.direction);
// TODO: implement other blocks
}

Expand Down

0 comments on commit d25f755

Please sign in to comment.