TiTRIS

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

commit c5f2616bc50b0a11a3a83235d22ec9df1f6f6cf7
parent c22f6349d58442650358d1aabfdd45d4775394c9
Author: joshiemoore <jxm5210@g.rit.edu>
Date:   Fri, 28 Sep 2018 18:27:46 -0400

Add very basic game loop

Diffstat:
Mtitris.c | 40++++++++++++++++++++++++++++++++++------
1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/titris.c b/titris.c @@ -6,6 +6,7 @@ // library includes #include <os.h> +#include <keys.h> #include <SDL/SDL_config.h> #include <SDL/SDL.h> @@ -37,6 +38,16 @@ const short SHAPES[7][4] = {0xC600, 0x4C80, 0xC600, 0x4C80} }; + +// GAME STATE +// player position +int curRow, curCol = 0; + +int curPiece = 4; +int rot = 0; + + + int main(void) { // init screen SDL_Surface* screen; @@ -44,13 +55,30 @@ int main(void) { screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, has_colors ? 16 : 8, SDL_SWSURFACE); - // draw initial blank screen - SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); - - drawBoard(screen); + // main game loop + while (true) { + // blank screen + SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); - SDL_Flip(screen); - wait_key_pressed(); + // draw the board + drawBoard(screen); + + // draw the current active piece + drawActivePiece(screen, SHAPES[curPiece][rot], COLORS[curPiece], curRow, curCol); + + SDL_Flip(screen); + + + if (isKeyPressed(KEY_NSPIRE_6)) { + curCol++; + } else if (isKeyPressed(KEY_NSPIRE_4)) { + curCol--; + } else if (isKeyPressed(KEY_NSPIRE_ESC)) { + break; + } + + SDL_Delay(100); + } SDL_Quit();