TiTRIS

unfinished Tetris clone for TI-nspire CX
git clone git://squid-tech.com/TiTRIS.git
Log | Files | Refs | README

commit c76bcbbe01abcda71632a5fbac70b18b146024fc
parent 8af9fbe17b3f191644b0155f059fd8df97ef76c8
Author: joshiemoore <jxm5210@g.rit.edu>
Date:   Thu, 27 Sep 2018 23:47:00 -0400

Implement drawActivePiece() function

Diffstat:
Mgraphics.c | 21+++++++++++++++++++++
Mgraphics.h | 10++++++++++
2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/graphics.c b/graphics.c @@ -29,9 +29,30 @@ void drawBoard(SDL_Surface* screen) { } } + void colorTile(SDL_Surface* screen, int row, int col, Uint32 color) { int x = boardLeft + (col * TILE_SIZE) + (col * 2) + 1; int y = (row * TILE_SIZE) + (row * 2) + 1; boxColor(screen, x, y, x + TILE_SIZE, y + TILE_SIZE, color); +} + + +void drawActivePiece(SDL_Surface* screen, short shape, Uint32 color, int row, int col) { + // draw each row + for (int i = 0; i < 4; i++) { + unsigned short pieceRow = (shape >> (i * 4)) & 0x000F; + + if (pieceRow == 0) continue; + + // draw each tile + for (int j = 0; j < 4; j++) { + if ((pieceRow & (1 << j)) != 0) { + colorTile(screen, + row + 3 - i, + col + 3 - j, + color); + } + } + } } \ No newline at end of file diff --git a/graphics.h b/graphics.h @@ -16,9 +16,19 @@ */ void drawBoard(SDL_Surface* screen); + /** * Color a single tile on the game board. */ void colorTile(SDL_Surface* screen, int row, int col, Uint32 color); + +/** + * Draw the current active piece on the board. + * Piece must be rotated before passing it to this function. + * Function draws from the bottom-right up. + */ +void drawActivePiece(SDL_Surface* screen, short shape, Uint32 color, int row, int col); + + #endif \ No newline at end of file