// Copyright 2001,2002,2006 Matt Baker // // This file is part of bd. // // bd is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // bd is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with bd; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define USE_TI89 // Compile for TI-89 //#define USE_TI92PLUS // Compile for TI-92 Plus //#define USE_V200 // Compile for V200 //#define MIN_AMS 100 // Compile for AMS 1.00 or higher #define SAVE_SCREEN // Save/Restore LCD Contents #include // Include All Header Files #include "sprites.h" #include "string.h" #if defined(USE_TI89) && defined(USE_TI92PLUS) #error Cannot produce both versions at once #elif defined(USE_TI89) #define SPRITE_W 12 // This is the sprite width #define SPRITE_H 12 // This is the sprite height #define SCREEN_W 160 #define SCREEN_H 100 #elif defined(USE_TI92PLUS) || defined(USE_V200) #define SPRITE_W 16 // This is the sprite width #define SPRITE_H 16 // This is the sprite height #define SCREEN_W 240 #define SCREEN_H 128 #else #error Please define either USE_TI89 or USE_TI92PLUS or USE_V200 #endif #define BOARD_W 50 // Board width #define BOARD_H 50 // Board height #define NUM_LEVELS 11 #define BLANK 0 // These are sprite nums #define BRICK 1 #define BLOCK 2 #define DOOR 3 #define GUY_LEFT 4 #define GUY_RIGHT 5 #define INTRO 0 // game state #define PLAY 1 #define EXIT 2 #define RELOAD 3 #define LOAD 4 #define UPLEVEL 5 #define DOWNLEVEL 6 #define LOOKAROUND 7 #define PLUS 43 #define MINUS 45 char board[BOARD_W][BOARD_H]; // the board char dispx, dispy, levelw, levelh, carryblock, state, mainMenuState; int guyx, guyy, curr_level, introtmp; unsigned char virtual[3840]; // for screen buffer //char passwords[11][4] = {"tcP", "ARo", "CKs", "daN", "BAH", "Ion", "Twe", "nTy", "iRC", "JmK", "wTF"}; char passwords[11][4] = {"gTo", "mWu", "SDh", "aCf", "PRF", "Ren", "ITv", "Zrx", "aLa", "ARp", "uQY"}; //----------------------------------------------------------------------------------------- // Initilizes the board //----------------------------------------------------------------------------------------- void initBoard() { int x, y; for(y = 0; y < BOARD_W; y++) { for(x = 0; x < BOARD_H; x++) { board[x][y] = BLANK; } } } //----------------------------------------------------------------------------------------- // Puts a line of board on the board //----------------------------------------------------------------------------------------- void lineat(int y, char* ob) { unsigned int x; for(x = 0; x < strlen(ob); x++) { switch(ob[x]) { case 32: // space board[x][y] = BLANK; break; case 66: // B board[x][y] = BRICK; break; case 79: // O board[x][y] = BLOCK; break; case 68: //D board[x][y] = DOOR; break; case 77: //M board[x][y] = GUY_LEFT; break; } } } //----------------------------------------------------------------------------------------- // Loads a level //----------------------------------------------------------------------------------------- void load_level(int level) { initBoard(); if (level == 1) { lineat(1, "B B"); lineat(2, "B B"); lineat(3, "B B"); lineat(4, "B B"); lineat(5, "B B"); lineat(6, "B B B B"); lineat(7, "BD B B O B O M B"); lineat(8, "BBBBBBBBBBBBBBBBBBBB"); dispx = 8; dispy = 2; levelw = 20; levelh = 8; guyx = 16; guyy = 7; carryblock = 0; } else if (level == 2) { lineat(1 , " B BB BB "); lineat(2 , " B B "); lineat(3 , "BB B "); lineat(4 , "BD B "); lineat(5 , "BB B"); lineat(6 , " B B O B"); lineat(7 , " B BO OOM B"); lineat(8 , " BBBBB BBBBBBBBBBBBB"); lineat(9 , " B OB "); lineat(10, " BBBBB "); dispx = 10; dispy = 3; levelw = 22; levelh = 10; guyx = 18; guyy = 7; carryblock = 0; } else if (level == 3) { lineat(1 , " B "); lineat(2 , " B BBBBBBBBBBBBB "); lineat(3 , "B B B B"); lineat(4 , "B B B"); lineat(5 , "B OB"); lineat(6 , "B OOB"); lineat(7 , "B BBB M BO BB "); lineat(8 , "B B B B BBBBB "); lineat(9 , "B B BOO BB B "); lineat(10 , "BDB BBBBBB BB "); lineat(11, "BBB BB BBB "); dispx = 3; dispy = 3; levelw = 19; levelh = 11; guyx = 9; guyy = 7; carryblock = 0; } else if (level == 4) { lineat(1 , " B "); lineat(2 , " B B "); lineat(3 , " B B B "); lineat(4 , " B B B B "); lineat(5 , " BBB B B B "); lineat(6 , " B B B B"); lineat(7 , " B BB B"); lineat(8 , " B OB"); lineat(9 , " B OOB"); lineat(10, " B M BBB"); lineat(11, "BB B B B "); lineat(12, "BD B O BBBBB "); lineat(13, "BBBBB B O O BBB "); lineat(14, " B B O B BO B "); lineat(15, " B BBBBBBBBBB "); lineat(16, " BBB "); dispx = 11; dispy = 6; levelw = 24; levelh = 16; guyx = 17; guyy = 10; carryblock = 0; } else if (level == 5) { lineat(1 , " BBB BBBBBBBBB "); lineat(2 , " BBBB BBBB B"); lineat(3 , "B B"); lineat(4 , "B B"); lineat(5 , "B B"); lineat(6 , "B B B"); lineat(7 , "B B B"); lineat(8 , "B BOOOO B"); lineat(9 , "BD BBBBBBBM B"); lineat(10, "BB BBB BB B OB"); lineat(11, " B B B BB OOB"); lineat(12, " B B B BB OOOB"); lineat(13, " BBB B BBBBBBBB"); lineat(14, " BBB "); dispx = 7; dispy = 5; levelw = 22; levelh = 14; guyx = 12; guyy = 9; carryblock = 0; } else if (level == 6) { lineat(1 , " BBB BBBB"); lineat(2 , " B BBBBBBBBBBBBB B"); lineat(3 , "BB B"); lineat(4 , "BD B"); lineat(5 , "BB B"); lineat(6 , " B OOB"); lineat(7 , " BOO B O BBB"); lineat(8 , " BOOO BMOOO B "); lineat(9 , " BOOOO BBBBB B "); lineat(10, " BBBBB BBB BBB "); lineat(11, " B OB "); lineat(12, " BB BBB "); lineat(13, " BBB "); dispx = 9; dispy = 4; levelw = 21; levelh = 13; guyx = 13; guyy = 8; carryblock = 0; } else if (level == 7) { lineat(1 , " B BBBBB BB BBB "); lineat(2 , " B B B B B B B B "); lineat(3 , " B BB BB BB B"); lineat(4 , " B B B B B"); lineat(5 , " B OB"); lineat(6 , " B OB"); lineat(7 , "BB OOB"); lineat(8 , "BD O BBB"); lineat(9 , "BB B O B BB B "); lineat(10, " B B O BB O MBBBB "); lineat(11, " BB B OOO BB OOOB "); lineat(12, " B BBBBBB BBBBBBB "); lineat(13, " BB B BBB "); lineat(14, " BBB "); dispx = 11; dispy = 6; levelw = 24; levelh = 14; guyx = 17; guyy = 10; carryblock = 0; } else if (level == 8) { lineat(1 , " BBB BBBB BBBBBBB "); lineat(2 , "B B B B B B "); lineat(3 , "B B B BB B"); lineat(4 , "BO BBB B B BBB B"); lineat(5 , "BOO BB BB B B"); lineat(6 , "BBBB BB BD B"); lineat(7 , " BB BB BB B"); lineat(8 , " B O B B B B"); lineat(9 , " B OB B B B B"); lineat(10, " B BBB B B B OB"); lineat(11, " B B B BB OOB"); lineat(12, "B B BBBBBB"); lineat(13, "B O B"); lineat(14, "B O BBB OB"); lineat(15, "B BBB OOB"); lineat(16, "B O O M OOOB"); lineat(17, "BBBBBBBBBBBBBBBBBBBBBBBBBBB"); dispx = 15; dispy = 10; levelw = 27; levelh = 17; guyx = 20; guyy = 16; carryblock = 0; } else if (level == 9) { lineat(1 , " BBB "); lineat(2 , " B B "); lineat(3 , " B B BBBBB"); lineat(4 , " B BB B"); lineat(5 , " B O B"); lineat(6 , " B OO OB"); lineat(7 , " B BBB OOB"); lineat(8 , " B M BBBB"); lineat(9 , "B O B"); lineat(10, "BD BBB B"); lineat(11, "BB BB B OB"); lineat(12, " B BBO BB BBBB"); lineat(13, " B BBBBBBB BB "); lineat(14, " BBB B B BB "); lineat(15, " B BB BBB "); lineat(16, " BBB "); dispx = 7; dispy = 4; levelw = 20; levelh = 16; guyx = 14; guyy = 8; carryblock = 0; } else if (level == 10) { lineat(1 , " BBBBBBBBBBBBBBBBBBBBB "); lineat(2 , " BB B B "); lineat(3 , "BBBBO OOBO OOO OBB "); lineat(4 , "B BB B BBBBB OBBB BB B"); lineat(5 , "B B BB BBB BBB B"); lineat(6 , "B BB BBOOOO B"); lineat(7 , "BD BBBBBBB B"); lineat(8 , "BB B BBB BB"); lineat(9 , " B O B B BB B"); lineat(10, " B B B BB B"); lineat(11, " BBBB BB BBBBB"); lineat(12, " BBBBB M B"); lineat(13, " B B B"); lineat(14, " B BB BBBBBBBB"); lineat(15, " B BB B "); lineat(16, " B O OB "); lineat(17, " BO BBBBBBBBBBB OOB "); lineat(18, " BOO BB BB OOOB "); lineat(19, " BBBBBB BBBBBB "); dispx = 9; dispy = 8; levelw = 27; levelh = 19; guyx = 14; guyy = 12; carryblock = 0; } else if (level == 11) { lineat(1 , "BBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); lineat(2 , "B B B B"); lineat(3 , "B OBOO BBBBB B"); lineat(4 , "BO BBB OBB O BB D B B"); lineat(5 , "BOO BBB M O B B B"); lineat(6 , "BBB OOB B O B B"); lineat(7 , "B BBBB B BBB BBB B"); lineat(8 , "BO B B B O B"); lineat(9 , "BOO BBB B BO B BBBB"); lineat(10, "BBBB O BBB B BBO B O B B"); lineat(11, "B O BBB OB B B"); lineat(12, "B O OO B BBBB B"); lineat(13, "B BBBBBBBBB BBBBB B"); lineat(14, "B O OBB B B"); lineat(15, "BBBB O B OOB B"); lineat(16, "BOBB B B BBBB B"); lineat(17, "BBOBBB B B OOO O B"); lineat(18, "BOBOBOBB B OOO B"); lineat(19, "BBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); dispx = 8; dispy = 2; levelw = 29; levelh = 19; guyx = 13; guyy = 5; carryblock = 0; } } //----------------------------------------------------------------------------------------- // draws a white bar to the screen. //----------------------------------------------------------------------------------------- void white_bar(int x, int y, unsigned int height, unsigned int howManyBytesLong) { unsigned int i, j; for(i=0; i 0)) // left bound check { dispx = guyx - 5; } if ((dispx + 12 - guyx <= 4) && (dispx < (levelw - 12))) // right bound check { dispx = guyx - 7; } if ((dispy + 8 - guyy <= 3) && (dispy <= (levelh - 8))) // bot bound check { dispy = guyy - 4; } if ((guyy - dispy <= 3) && (dispy > 0)) // top bound check { dispy = guyy - 4; } } void playLevel() { int key, tmpx, tmpy; while (state == PLAY) { tmpx = guyx; tmpy=guyy; key = ngetchx(); if (key == KEY_LEFT) { if (board[guyx-1][guyy] == BLANK) // if there is not something in his path { board[guyx][guyy] = BLANK; guyx = guyx - 1; board[guyx][guyy] = GUY_LEFT; obFall(guyx, guyy); // fall if it needs to if (carryblock) { if (board[tmpx-1][tmpy-1] != BLANK) { obFall(tmpx, tmpy-1); carryblock = 0; } else { board[tmpx][tmpy-1] = BLANK; board[guyx][guyy-1] = BLOCK; } } adjustview(); draw_board(); if (board[guyx][guyy+1] == DOOR) // if we fell and landed on a door { state = LOAD; } }else if (board[guyx-1][guyy] == DOOR) { state = LOAD; } else { board[guyx][guyy] = GUY_LEFT; draw_board(); } } else if (key == KEY_RIGHT) { if (board[guyx+1][guyy] == BLANK) // if there is not something in his path { board[guyx][guyy] = BLANK; guyx = guyx + 1; board[guyx][guyy] = GUY_RIGHT; obFall(guyx, guyy); if (carryblock) { if (board[tmpx+1][tmpy-1] != BLANK) { obFall(tmpx, tmpy-1); carryblock = 0; } else { board[tmpx][tmpy-1] = BLANK; board[guyx][guyy-1] = BLOCK; } } adjustview(); draw_board(); if (board[guyx][guyy+1] == DOOR) // if we fell and landed on a door { state = LOAD; } } else if (board[guyx+1][guyy] == DOOR) { state = LOAD; } else { board[guyx][guyy] = GUY_RIGHT; draw_board(); } }else if (key == KEY_UP) { if (board[guyx][guyy] == GUY_LEFT) // if its a left guy { if ((board[guyx-1][guyy] != BLANK) && (board[guyx-1][guyy-1] == BLANK)) { if (!((carryblock) && (board[guyx-1][guyy-2] != BLANK))) { if (!((!(carryblock)) && (board[guyx][guyy-1] != BLANK))) { board[guyx][guyy] = BLANK; guyx = guyx - 1; guyy = guyy - 1; board[guyx][guyy] = GUY_LEFT; if (carryblock) { board[tmpx][tmpy-1] = BLANK; board[guyx][guyy-1] = BLOCK; } adjustview(); draw_board(); } } } else if (board[guyx-1][guyy-1] == DOOR) { state = LOAD; } } else { if ((board[guyx+1][guyy] != BLANK) && (board[guyx+1][guyy-1] == BLANK)) { if (!((carryblock) && (board[guyx+1][guyy-2] != BLANK))) { if (!((!(carryblock)) && (board[guyx][guyy-1] != BLANK))) { board[guyx][guyy] = BLANK; guyx = guyx + 1; guyy = guyy - 1; board[guyx][guyy] = GUY_RIGHT; if (carryblock) { board[tmpx][tmpy-1] = BLANK; board[guyx][guyy-1] = BLOCK; } adjustview(); draw_board(); } } } else if (board[guyx+1][guyy-1] == DOOR) { state = LOAD; } } }else if (key == KEY_DOWN) { if (carryblock == 0) { if ((board[guyx][guyy] == GUY_LEFT) && (board[guyx][guyy-1] == BLANK)) { if ((board[guyx-1][guyy] == BLOCK) && (board[guyx-1][guyy-1] == BLANK)) // pick up block { board[guyx-1][guyy] = BLANK; board[guyx][guyy-1] = BLOCK; carryblock = 1; draw_board(); } } else if (board[guyx][guyy-1] == BLANK) { if ((board[guyx+1][guyy] == BLOCK) && (board[guyx+1][guyy-1] == BLANK)) // pick up block { board[guyx+1][guyy] = BLANK; board[guyx][guyy-1] = BLOCK; carryblock = 1; draw_board(); } } } else { if (board[guyx][guyy] == GUY_LEFT) { if ((board[guyx-1][guyy] == BLANK) && (board[guyx-1][guyy-1] == BLANK)) // put it down { board[guyx][guyy-1] = BLANK; board[guyx-1][guyy] = BLOCK; carryblock = 0; obFall(guyx-1, guyy); draw_board(); } else if ((board[guyx-1][guyy] != BLANK) && (board[guyx-1][guyy-1] == BLANK)) // stack it { board[guyx][guyy-1] = BLANK; board[guyx-1][guyy-1] = BLOCK; carryblock = 0; obFall(guyx-1, guyy-1); draw_board(); } } else { if ((board[guyx+1][guyy] == BLANK) && (board[guyx+1][guyy-1] == BLANK)) // put it down { board[guyx][guyy-1] = BLANK; board[guyx+1][guyy] = BLOCK; carryblock = 0; obFall(guyx+1, guyy); draw_board(); } else if ((board[guyx+1][guyy] != BLANK) && (board[guyx+1][guyy-1] == BLANK)) // stack it { board[guyx][guyy-1] = BLANK; board[guyx+1][guyy-1] = BLOCK; carryblock = 0; obFall(guyx+1, guyy-1); draw_board(); } } } }else if (key == KEY_CLEAR) { state = RELOAD; // }else if (key == PLUS) // { // state = UPLEVEL; // }else if (key == MINUS) // { // state = DOWNLEVEL; }else if (key == KEY_MODE) { state = LOOKAROUND; }else if (key == KEY_ESC) { state = EXIT; } else { draw_board(); } } } //----------------------------------------------------------------------------------------- // Lookaround - procedure that allows user to look around //----------------------------------------------------------------------------------------- void lookaround() { int key, tmpx, tmpy; key = KEY_ESC; // so it does not equal mode tmpx = dispx; tmpy = dispy; MoveTo(30,0); printf("Look Mode"); memcpy (LCD_MEM, virtual, LCD_SIZE); while (key != KEY_MODE) { key = ngetchx(); if (key == KEY_UP) { if (dispy > 1) dispy--; draw_board(); }else if (key == KEY_DOWN) { if (dispy <= levelh-8) dispy++; draw_board(); }else if (key == KEY_RIGHT) { if (dispx < levelw-12) dispx++; draw_board(); }else if (key == KEY_LEFT) { if (dispx > 0) dispx--; draw_board(); } } dispx = tmpx; dispy = tmpy; draw_board(); MoveTo(30,0); printf("Play Mode"); memcpy (LCD_MEM, virtual, LCD_SIZE); } //----------------------------------------------------------------------------------------- // This is the driver it controls switching of levels and looking around //----------------------------------------------------------------------------------------- void driver() { while (state != EXIT) { if(state != LOOKAROUND) // don't want to load if looking around { load_level(curr_level); draw_board(); } state = PLAY; playLevel(); switch(state) { case LOAD: // request to go to next level if (curr_level < NUM_LEVELS) curr_level++; else { MoveTo(30,0); printf("You beat the game!!!"); memcpy (LCD_MEM, virtual, LCD_SIZE); ngetchx(); curr_level = 1; } break; case RELOAD: // request to reload current level state = LOAD; curr_level = curr_level; break; case UPLEVEL: // request to reload current level state = LOAD; if (curr_level < NUM_LEVELS) curr_level++; break; case DOWNLEVEL: // request to reload current level state = LOAD; if (curr_level > 1) curr_level--; break; case LOOKAROUND: // request ot look around map lookaround(); break; } } } //----------------------------------------------------------------------------------------- // Adjust View //----------------------------------------------------------------------------------------- void introadjustview() { if ((guyx - dispx <= 5) && (dispx > 0)) // left bound check { dispx = guyx - 5; } if ((dispx + 12 - guyx <= 4) && (dispx < (levelw - 12))) // right bound check { dispx = guyx - 7; } if ((dispy + 8 - guyy <= 3) && (dispy <= (levelh - 8))) // bot bound check { dispy = guyy - 4; } if ((guyy - dispy <= 2) && (dispy > 0)) // top bound check { dispy = guyy - 4; } } //----------------------------------------------------------------------------------------- // intro move //----------------------------------------------------------------------------------------- void intromovenow(int ob) { int tmpx = guyx, tmpy = guyy; if (ob == 0) // LEFT MOVE { if (board[guyx-1][guyy] == BLANK) // if there is not something in his path { board[guyx][guyy] = BLANK; guyx = guyx - 1; board[guyx][guyy] = GUY_LEFT; obFall(guyx, guyy); // fall if it needs to if (carryblock) { board[tmpx][tmpy-1] = BLANK; board[guyx][guyy-1] = BLOCK; } introadjustview(); draw_board(); } else { board[guyx][guyy] = GUY_LEFT; draw_board(); } } else if (ob == 1) // RIGHT MOVE { board[guyx][guyy] = BLANK; guyx = guyx + 1; board[guyx][guyy] = GUY_RIGHT; obFall(guyx, guyy); introadjustview(); if (carryblock) { board[tmpx][tmpy-1] = BLANK; board[guyx][guyy-1] = BLOCK; } draw_board(); } else if (ob == 2) // PICKUP/PUTDOWN { if (carryblock == 0) { if (board[guyx][guyy] == GUY_LEFT) { if ((board[guyx-1][guyy] == BLOCK) && (board[guyx-1][guyy-1] == BLANK)) // pick up block { board[guyx-1][guyy] = BLANK; board[guyx][guyy-1] = BLOCK; carryblock = 1; draw_board(); } } else { if ((board[guyx+1][guyy] == BLOCK) && (board[guyx+1][guyy-1] == BLANK)) // pick up block { board[guyx+1][guyy] = BLANK; board[guyx][guyy-1] = BLOCK; carryblock = 1; draw_board(); } } } else { if (board[guyx][guyy] == GUY_LEFT) { if ((board[guyx-1][guyy] == BLANK) && (board[guyx-1][guyy-1] == BLANK)) // put it down { board[guyx][guyy-1] = BLANK; board[guyx-1][guyy] = BLOCK; carryblock = 0; obFall(guyx-1, guyy); draw_board(); } else if ((board[guyx-1][guyy] != BLANK) && (board[guyx-1][guyy-1] == BLANK)) // stack it { board[guyx][guyy-1] = BLANK; board[guyx-1][guyy-1] = BLOCK; carryblock = 0; obFall(guyx-1, guyy-1); draw_board(); } } else { if ((board[guyx+1][guyy] == BLANK) && (board[guyx+1][guyy-1] == BLANK)) // put it down { board[guyx][guyy-1] = BLANK; board[guyx+1][guyy] = BLOCK; carryblock = 0; obFall(guyx+1, guyy); draw_board(); } else if ((board[guyx+1][guyy] != BLANK) && (board[guyx+1][guyy-1] == BLANK)) // stack it { board[guyx][guyy-1] = BLANK; board[guyx+1][guyy-1] = BLOCK; carryblock = 0; obFall(guyx+1, guyy-1); draw_board(); } } } } else if (ob == 3) { if (board[guyx][guyy] == GUY_LEFT) // if its a left guy { if ((board[guyx-1][guyy] != BLANK) && (board[guyx-1][guyy-1] == BLANK)) { board[guyx][guyy] = BLANK; guyx = guyx - 1; guyy = guyy - 1; board[guyx][guyy] = GUY_LEFT; if (carryblock) { board[tmpx][tmpy-1] = BLANK; board[guyx][guyy-1] = BLOCK; } introadjustview(); draw_board(); } else if (board[guyx-1][guyy-1] == DOOR) { // currlevel = currlevel + 1; // loadlevel(currlevel); // repaint(); } } else { if ((board[guyx+1][guyy] != BLANK) && (board[guyx+1][guyy-1] == BLANK)) { board[guyx][guyy] = BLANK; guyx = guyx + 1; guyy = guyy - 1; board[guyx][guyy] = GUY_RIGHT; if (carryblock) { board[tmpx][tmpy-1] = BLANK; board[guyx][guyy-1] = BLOCK; } introadjustview(); draw_board(); } else if (board[guyx+1][guyy-1] == DOOR) { // currlevel = currlevel + 1; // loadlevel(currlevel); // repaint(); } } } } //----------------------------------------------------------------------------------------- // intro move //----------------------------------------------------------------------------------------- void intromove() { introtmp = introtmp + 1; if (introtmp == 1) { intromovenow(0); }else if (introtmp == 2) { intromovenow(2); }else if (introtmp == 3) { intromovenow(0); }else if (introtmp == 4) { intromovenow(2); }else if (introtmp == 5) { intromovenow(3); }else if (introtmp == 6) { intromovenow(3); }else if (introtmp == 7) { intromovenow(0); }else if (introtmp == 8) { intromovenow(3); }else if (introtmp == 9) { intromovenow(0); }else if (introtmp == 10) { intromovenow(3); }else if (introtmp == 11) { intromovenow(1); }else if (introtmp == 12) { intromovenow(3); }else if (introtmp == 13) { intromovenow(1); }else if (introtmp == 14) { intromovenow(0); }else if (introtmp == 15) { intromovenow(2); }else if (introtmp == 16) { intromovenow(0); }else if (introtmp == 17) { intromovenow(0); }else if (introtmp == 18) { intromovenow(3); }else if (introtmp == 19) { intromovenow(0); }else if (introtmp == 20) { intromovenow(0); }else if (introtmp == 21) { intromovenow(2); }else if (introtmp == 22) { intromovenow(3); }else if (introtmp == 23) { intromovenow(3); }else if (introtmp == 24) { intromovenow(0); }else if (introtmp == 25) { intromovenow(0); }else if (introtmp == 26) { load_level(curr_level); draw_board(); introtmp = 0; } } // Custom String Input Function void InputStr(char *buffer, unsigned short maxlen) { SCR_STATE ss; short key; unsigned short i = 0; buffer[0] = 0; SaveScrState (&ss); do { MoveTo (ss.CurX, ss.CurY); printf ("%s_ ", buffer); memcpy (LCD_MEM, virtual, LCD_SIZE); // Note that two spaces are required only if the F_4x6 font is used key = ngetchx (); if (key >= ' ' && key <= '~' && i < maxlen) buffer[i++] = key; else if (key == KEY_BACKSPACE && i) i--; buffer[i] = 0; } while (key != KEY_ENTER); } // Main Function void _main(void) { int key, GO, tmpFlag, i; char pass[4]; OSFreeTimer(USER_TIMER); OSRegisterTimer(USER_TIMER,15); PortSet (virtual, 239, 127); FontSetSys (F_6x8); state = INTRO; introtmp = 0; curr_level = 1; load_level(curr_level); mainMenuState = 0; draw_board(); GO = 1; // run while(GO == 1) { OSTimerRestart(USER_TIMER); intromove(); while(!OSTimerExpired(USER_TIMER) && (GO == 1)) // while its not time to move again if (kbhit()) { key = ngetchx(); if (key == KEY_LEFT) { MoveTo(30,0); if (mainMenuState > 0) // bounds check mainMenuState--; else mainMenuState = 3; draw_board(); } else if (key == KEY_RIGHT) { if (mainMenuState < 3) // bounds check mainMenuState++; else mainMenuState = 0; draw_board(); } else if ((key == KEY_ENTER))// || (key == RR_HOME)) { if (mainMenuState == 0) { curr_level = 1; state = LOAD; draw_board(); driver(); state = INTRO; introtmp = 0; curr_level = 1; load_level(curr_level); mainMenuState = 0; draw_board(); } else if (mainMenuState == 1) // Enter password { #if defined(USE_TI89) && defined(USE_TI92PLUS) #error Cannot produce both versions at once #elif defined(USE_TI89) white_bar(5*8, 26, 36, 10); // white out the back DrawLine (40, 35, 40, 35+9*3, A_NORMAL); // draw box left DrawLine (40+10*8-1, 35, 40+10*8-1, 35+9*3, A_NORMAL); // right DrawLine (40, 35+9*3, 40+10*8-1, 35+9*3, A_NORMAL); // bot printf_xy(50,26+1,"Block Dude"); not_bar(5*8, 26, 9, 10); printf_xy(5*8+2,26+9+1,"Please Enter"); printf_xy(5*8+2,26+9+9+1,"The Password"); memcpy (LCD_MEM, virtual, LCD_SIZE); MoveTo(68,26+9+9+9+1); InputStr (pass, 3); tmpFlag = 1; for(i=0; i<11; i++) if (strcmp(pass, passwords[i]) == 0) { tmpFlag = 0; // found level curr_level = i+1; state = LOAD; draw_board(); driver(); state = INTRO; introtmp = 0; curr_level = 1; load_level(curr_level); mainMenuState = 0; draw_board(); } if (tmpFlag == 1) { curr_level = 1; state = LOAD; draw_board(); driver(); state = INTRO; introtmp = 0; curr_level = 1; load_level(curr_level); mainMenuState = 0; draw_board(); } #elif defined(USE_TI92PLUS) || defined(USE_V200) white_bar(12*8, 26, 36, 10); // white out the back DrawLine (12*8, 35, 12*8, 35+9*3, A_NORMAL); // draw box DrawLine (12*8+10*8-1, 35, 12*8+10*8-1, 35+9*3, A_NORMAL); DrawLine (12*8, 35+9*3, 12*8+10*8-1, 35+9*3, A_NORMAL); printf_xy(12*8+10,26+1,"Block Dude"); not_bar(12*8, 26, 9, 10); printf_xy(12*8+2,26+9+1,"Please Enter"); printf_xy(12*8+2,26+9+9+1,"The Password"); memcpy (LCD_MEM, virtual, LCD_SIZE); MoveTo(125,26+9+9+9+1); InputStr (pass, 3); tmpFlag = 1; for(i=0; i<11; i++) if (strcmp(pass, passwords[i]) == 0) { tmpFlag = 0; // found level curr_level = i+1; state = LOAD; draw_board(); driver(); state = INTRO; introtmp = 0; curr_level = 1; load_level(curr_level); mainMenuState = 0; draw_board(); } if (tmpFlag == 1) { curr_level = 1; state = LOAD; draw_board(); driver(); state = INTRO; introtmp = 0; curr_level = 1; load_level(curr_level); mainMenuState = 0; draw_board(); } #else #error Please define either USE_TI89 or USE_TI92PLUS #endif } else if (mainMenuState == 2) // help { #if defined(USE_TI89) && defined(USE_TI92PLUS) #error Cannot produce both versions at once #elif defined(USE_TI89) clrscr(); printf("The object of this game is\n"); printf("to reach the door in each\n"); printf("level. If you are unsure\n"); printf("where it is you can hold\n"); printf("2nd down and use the arrow\n"); printf("keys to scroll freely.\n"); printf("You can only climb one\n"); printf("block at a time and lift\n"); printf("only one block at a time.\n"); printf("To lift up a block press\n"); printf("down. To set it down"); memcpy (LCD_MEM, virtual, LCD_SIZE); ngetchx(); clrscr(); printf("press down again. CLEAR\n"); printf("will give you the choice\n"); printf("of restarting or quitting.\n"); printf("There are 11 levels in\n"); printf("this game."); memcpy (LCD_MEM, virtual, LCD_SIZE); ngetchx(); #elif defined(USE_TI92PLUS) || defined(USE_V200) clrscr(); printf("The object of this game is to reach the\n"); printf("door in each level. If you are unsure\n"); printf("where it is you can press MODE to\n"); printf("switch into look mode. In look mode\n"); printf("you can use the arrow keys to scroll\n"); printf("freely. To switch back to play mode\n"); printf("press MODE again. You can only climb\n"); printf("one block at a time and lift only one\n"); printf("block at a time. To lift up a block\n"); printf("press down. To set it down press down\n"); printf("again. CLEAR will restart the level.\n"); printf("ESC will quit. There are 11 levels in\n"); printf("this game."); memcpy (LCD_MEM, virtual, LCD_SIZE); ngetchx(); #else #error Please define either USE_TI89 or USE_TI92PLUS #endif } else if (mainMenuState == 3) { GO = 0; } } else if (key == KEY_ESC) { // let them escape with escape key GO = 0; } } } PortRestore (); }