/*********************************************************************** *Block Dude Nspire *Project Started on July 11, 2010 at 08:36:47 AM *Version 1.0 Finished on August 1, 2010 at 11:15:58 PM *Version 1.0 Released on www.ticalc.org on August 11, 2010 at 8:35:03 PM ************************************************************************/ /* NOTE: The game engine is located in the main function. The drawing engine is in "utils.c." In the game engine, all of the scrolling routines are commented out because scrolling is now completly controled by the drawing engine, located in "utils.c." */ #include #include "utils.h" //#include "console.h" //#include "string.h" //#define input(a) (cget(scrbuf, tmpbuf, &x, &y, (a))) //#define print(a) (cprint(scrbuf, tmpbuf, &x, &y, (a))) asm(".string \"PRG\"\n"); int main(void) { int level=0,guyx,guyy,box,win=0,dir,x,y,beat,moved,bmove; char currentlevel[20][40]; char levelinfo[6]; *(volatile unsigned*) 0x90110B00=0x00; *(volatile unsigned*) 0x900F0020=0x86; showSimpleDialogBox("Block Dude Nspire","If you have a Level Keycode, press the ESC key then press the three keys to go to the level\n\nIf you accidentally press ESC, press HOME to go to level 1.\n\nPress ENTER to start on level 1\n\nControls:\nLeft - Move Guy Left\nRight - Move Guy Right\nUp - Make Guy Climb Brick/Block\nDown - Make Guy Pick Up/Put Down Block\nHome - Restart Level\nEsc - Exit Game"); if(!isKeyPressed(KEY_NSPIRE_ESC)) {level=1;} //level keycode check while(!level) { if(isKeyPressed(KEY_NSPIRE_HOME)) { level=1; } if(isKeyPressed(KEY_NSPIRE_THETA)&&isKeyPressed(KEY_NSPIRE_PI)&&isKeyPressed(KEY_NSPIRE_EE)){ level=2; } if(isKeyPressed(KEY_NSPIRE_TENX)&&isKeyPressed(KEY_NSPIRE_Z)&&isKeyPressed(KEY_NSPIRE_SIN)){ level=3; } if(isKeyPressed(KEY_NSPIRE_CLEAR)&&isKeyPressed(KEY_NSPIRE_SPACE)&&isKeyPressed(KEY_NSPIRE_PERIOD)) { level=4; } if(isKeyPressed(KEY_NSPIRE_B)&&isKeyPressed(KEY_NSPIRE_COS)&&isKeyPressed(KEY_NSPIRE_LTHAN)) { level=5; } if(isKeyPressed(KEY_NSPIRE_W)&&isKeyPressed(KEY_NSPIRE_R)&&isKeyPressed(KEY_NSPIRE_D)) { level=6; } if(isKeyPressed(KEY_NSPIRE_TAB)&&isKeyPressed(KEY_NSPIRE_DIVIDE)&&isKeyPressed(KEY_NSPIRE_4)) { level=7; } if(isKeyPressed(KEY_NSPIRE_1)&&isKeyPressed(KEY_NSPIRE_CAPS)&&isKeyPressed(KEY_NSPIRE_GTHAN)) { level=8; } if(isKeyPressed(KEY_NSPIRE_7)&&isKeyPressed(KEY_NSPIRE_PLUS)&&isKeyPressed(KEY_NSPIRE_COLON)) { level=9; } if(isKeyPressed(KEY_NSPIRE_F)&&isKeyPressed(KEY_NSPIRE_QUES)&&isKeyPressed(KEY_NSPIRE_CTRL)) { level=10; } if(isKeyPressed(KEY_NSPIRE_MENU)&&isKeyPressed(KEY_NSPIRE_C)&&isKeyPressed(KEY_NSPIRE_T)){ level=11; } if(isKeyPressed(KEY_NSPIRE_COS)&&isKeyPressed(KEY_NSPIRE_PERIOD)&&isKeyPressed(KEY_NSPIRE_B)) { level=12; } if(isKeyPressed(KEY_NSPIRE_TAB)&&isKeyPressed(KEY_NSPIRE_PI)&&isKeyPressed(KEY_NSPIRE_9)) { level=13; } } //while the escape key is not pressed while (!isKeyPressed(KEY_NSPIRE_ESC)) { //set current level for(x=0;x<20;x++) { for(y=0;y<40;y++) { currentlevel[x][y]=setlevel(level,x,y); } } //set current level info for(x=0;x<6;x++) { levelinfo[x]=setlevelinfo(level,x); } //set guy position guyx=levelinfo[0]; guyy=levelinfo[1]; //draw the level drawlevel(currentlevel,levelinfo); box=0; //Game Engine while(!win) { levelinfo[0]=guyx; levelinfo[1]=guyy; //If left is pressed... while(isKeyPressed(KEY_NSPIRE_LEFT)) { //change the current pic of the guy to face left currentlevel[guyy][guyx]=3; //If the door is there, exit the game loop if(currentlevel[guyy][guyx-1]==4) { win=1;beat=1; } //If the space to the left is open, move the guy if(currentlevel[guyy][guyx-1]==0) { currentlevel[guyy][guyx]=0; currentlevel[guyy][guyx-1]=3; //If he has a box, move that too. if (box) { if(currentlevel[guyy-1][guyx-1]==1||currentlevel[guyy-1][guyx-1]==2) { currentlevel[guyy][guyx]=2; currentlevel[guyy-1][guyx]=0; box=0; } else { currentlevel[guyy-1][guyx]=0; currentlevel[guyy-1][guyx-1]=2; } } //change the guy position /*if(guyx-7<=levelinfo[2]){ if(levelinfo[2]!=0){ levelinfo[2]--; } }*/ guyx--; //if there is not a brick/box under the guy, move him down while(currentlevel[guyy+1][guyx]==0) { currentlevel[guyy][guyx]=0; guyy++; currentlevel[guyy][guyx]=3; /*if(guyy+7>=levelinfo[3]&&guyy+7!=levelinfo[5]){ levelinfo[3]++; }*/ if(currentlevel[guyy+1][guyx]==4) { win=1;beat=1; } //if he has a box, move that too if(box) { currentlevel[guyy-2][guyx]=0; currentlevel[guyy-1][guyx]=2; } } } //draw the updated level levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,levelinfo); if(isKeyPressed(KEY_NSPIRE_LEFT)){ slowdown();} } //If the right key is pressed while (isKeyPressed(KEY_NSPIRE_RIGHT)) { //change the current pic of the guy to face right currentlevel[guyy][guyx]=5; //if there is a brick/block to the right, do nothing if(currentlevel[guyy][guyx+1]==1||currentlevel[guyy][guyx+1]==2) { } //if the door is to the right, exit this loop if(currentlevel[guyy][guyx+1]==4) { win=1;beat=1; } //If there is a blank spot, move right if(currentlevel[guyy][guyx+1]==0) { currentlevel[guyy][guyx]=0; currentlevel[guyy][guyx+1]=5; //move the box too if (box) { if(currentlevel[guyy-1][guyx+1]==1||currentlevel[guyy-1][guyx+1]==2) { currentlevel[guyy][guyx]=2; currentlevel[guyy-1][guyx]=0; box=0; } else { currentlevel[guyy-1][guyx]=0; currentlevel[guyy-1][guyx+1]=2; } } //change guy position guyx++; /*if(guyx+7>=levelinfo[2]){ if(guyx+11!=levelinfo[4]) { levelinfo[2]++; } }*/ //check if guy can be moved down after moving, and if so, move him while(currentlevel[guyy+1][guyx]==0) { currentlevel[guyy][guyx]=0; guyy++; currentlevel[guyy][guyx]=5; /*if(guyy+7>=levelinfo[3]&&guyy+11<=levelinfo[5]){ levelinfo[3]++; }*/ if(currentlevel[guyy+1][guyx]==4) { win=1; beat=1; } //move the box too if he has one if(box) { currentlevel[guyy-2][guyx]=0; currentlevel[guyy-1][guyx]=2; } } } //draw the level levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,levelinfo); if(isKeyPressed(KEY_NSPIRE_RIGHT)){ slowdown();} } //if down is pressed if (isKeyPressed(KEY_NSPIRE_DOWN)) { //set moved to true moved=1; //determine if guy is facing left or right if (currentlevel[guyy][guyx]==3) { dir=-1; } else { dir=1; } //if he has a box... if (box) { //if spot to left or right is open put block there. If the space below that is open, keep moving until it hits a brick or another block bmove=0; if(currentlevel[guyy-1][guyx+dir]==0) { while(currentlevel[guyy+bmove][guyx+dir]==0) { currentlevel[guyy-1][guyx]=0; currentlevel[guyy+(bmove-1)][guyx+dir]=0; currentlevel[guyy+bmove][guyx+dir]=2; box=0; moved=0; bmove++; } } //If the space to the left up one square is open... if((currentlevel[guyy][guyx+dir]==1||currentlevel[guyy][guyx+dir]==2)&&moved) { if(currentlevel[guyy-1][guyx+dir]==0) { currentlevel[guyy-1][guyx]=0; currentlevel[guyy-1][guyx+dir]=2; box=0; } } } //if the guy didn't have a box and there is one available, pick it up else if(!box&¤tlevel[guyy][guyx+dir]==2&¤tlevel[guyy-1][guyx+dir]!=1&¤tlevel[guyy-1][guyx+dir]!=2&¤tlevel[guyy-1][guyx]!=1&¤tlevel[guyy-1][guyx]!=2) { currentlevel[guyy][guyx+dir]=0; currentlevel[guyy-1][guyx]=2; box=1; } //redraw the level levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,levelinfo); slowdown(); while(isKeyPressed(KEY_NSPIRE_DOWN)); } //if the player presses up... while(isKeyPressed(KEY_NSPIRE_UP)) { //set the direction if (currentlevel[guyy][guyx]==3) { dir=-1; } else { dir=1; } //check if up move is possible if (currentlevel[guyy][guyx+dir]==0) { } if (currentlevel[guyy][guyx+dir]==1||currentlevel[guyy][guyx+dir]==2) { if (currentlevel[guyy-1][guyx+dir]==1||currentlevel[guyy-1][guyx+dir]==2) { } //check for a win if (currentlevel[guyy-1][guyx+dir]==4) { win=1; beat=1; } //move guy if(currentlevel[guyy-1][guyx+dir]==0&¤tlevel[guyy-1][guyx]!=1) { currentlevel[guyy][guyx]=0; if (dir==1) { currentlevel[guyy-1][guyx+dir]=5; } else if (dir==-1) { currentlevel[guyy-1][guyx+dir]=3; } //move box too if (box) { if(currentlevel[guyy-2][guyx+dir]==1||currentlevel[guyy-2][guyx+dir]==2) { currentlevel[guyy-1][guyx+dir]=0; if (dir==1) { currentlevel[guyy-1][guyx+dir]=0; } else if (dir==-1) { currentlevel[guyy-1][guyx+dir]=0; } guyx-=dir; guyy++; } else { currentlevel[guyy-1][guyx]=0; currentlevel[guyy-2][guyx+dir]=2; } } //reset guy position guyx+=dir; guyy--; //scrolling up /*if(guyy-5<=levelinfo[3]){ if(levelinfo[3]!=0) { levelinfo[3]--; } } //scrolling left if(dir==-1) { if(guyx-7<=levelinfo[2]&&levelinfo[2]!=0){ levelinfo[2]--; } } //scrolling right if(dir==1) { if(guyx+7>=levelinfo[2]+11){ levelinfo[2]++; } }*/ } } //redraw level levelinfo[0]=guyx; levelinfo[1]=guyy; if (dir==-1){ currentlevel[guyy][guyx]=3; } else if (dir) { currentlevel[guyy][guyx]=5; } drawlevel(currentlevel,levelinfo); if(isKeyPressed(KEY_NSPIRE_UP)) {slowdown();} } //if esc is pressed, exit loop if(isKeyPressed(KEY_NSPIRE_ESC)) { return 0; } //if home is pressed, subtract one from level number, win level (will just redraw level in original position) if(isKeyPressed(KEY_NSPIRE_HOME)) { level--; win=1; beat=0; } } //dialog boxes with level codes if(level==13) { showSimpleDialogBox("You Won","Congratulations!\nYou beat all 13 levels!"); return 0; } else { level++; win=0; *(volatile unsigned*) 0x90110B00=0x00; *(volatile unsigned*) 0x90110B00=0x10; switch(level) { case 1: showSimpleDialogBox("Level 1","Level Keycode:\nPress the Home Key"); break; case 2: showSimpleDialogBox("Level 2","Level Keycode:\nPress the Pi, Theta, and EE Keys"); break; case 3: showSimpleDialogBox("Level 3","Level Keycode:\nPress the 10^X, Z, and Sine Keys"); break; case 4: showSimpleDialogBox("Level 4","Level Keycode:\nPress the Clear, Space, and Period Keys"); break; case 5: showSimpleDialogBox("Level 5","Level Keycode:\nPress the B, Cosine, and Less Than Keys"); break; case 6: showSimpleDialogBox("Level 6","Level Keycode:\nPress the W, R, and D Keys"); break; case 7: showSimpleDialogBox("Level 7","Level Keycode:\nPress the Tab, Divide, and 4 Keys"); break; case 8: showSimpleDialogBox("Level 8","Level Keycode:\nPress the 1, Caps, and Greater Than Keys"); break; case 9: showSimpleDialogBox("Level 9","Level Keycode:\nPress the 7, Plus, and Colon Keys"); break; case 10: showSimpleDialogBox("Level 10","Level Keycode:\nPress the F, ?, and Ctrl Keys"); break; case 11: showSimpleDialogBox("Level 11","Level Keycode:\nPress the Menu, C, and T Keys"); break; case 12: showSimpleDialogBox("Level 12","Level Keycode:\nPress the Cosine, Period, and B Keys"); break; case 13: showSimpleDialogBox("Level 13","Level Keycode:\nPress the Tab, Pi, and 9 Keys"); } //repeat the loop *(volatile unsigned*) 0x90110B00=0x00; continue; } } return 0; }