}
- public void resetTiles(int tilecount) {
+ protected void resetTiles(int tilecount) {
tileArray = new Bitmap[tilecount];
}
{
if (this.collisionTest(x, y))
{
- currentPiece = prePiece;
- currentPiece.x = MAPWIDTH/2-2;
- currentPiece.y = -1;
- prePiece = newBlock();
- prePiece.x=MAPWIDTH+2;
- prePiece.y=GREY/4;
+ if (y == 1)
+ {
+ currentPiece = prePiece;
+ currentPiece.x = MAPWIDTH/2-2;
+ currentPiece.y = -1;
+ prePiece = newBlock();
+ prePiece.x=MAPWIDTH+2;
+ prePiece.y=GREY/4;
+ }
}
else
{
int newx = currentPiece.x + cx;
int newy = currentPiece.y + cy;
- //Check boundaries
+ //Check grid boundaries
for(int x=0; x<4; x++)
for(int y=0; y<4; y++)
if(currentPiece.size[x][y] != Tile.NOCOLOR)
- if (newy + y == MAPHEIGHT)
+ if ((newy + y == MAPHEIGHT) || (newy + y < 0) || (newx + x == MAPWIDTH) || (newx + x < 0))
return true;
- //Check collisions
+ //Check collisions with other blocks
for(int x=0; x< MAPWIDTH; x++)
for(int y=0; y< MAPHEIGHT; y++)
if(x >= newx && x < newx + 4)
return false;
}
-
-
- @Override
- protected void onDraw(Canvas canvas) {
- canvas.drawColor(Color.BLACK);
- int aux = 0;
-
- //draw moving block
- for (Piece piece : Piece.values())
- {
- for(int xmy=0; xmy<4; xmy++)
- for(int ymx=0; ymx<4; ymx++)
- if(piece.size[xmy][ymx] != Tile.NOCOLOR)
- canvas.drawBitmap(tileArray[piece.size[xmy][ymx].getColor()],
- piece.x+(xmy*TILESIZE), piece.y+aux+(ymx*TILESIZE), null);
- aux = aux + 64;
- }
- }
}
\ No newline at end of file