/********************************************************************************* *Trapped for TI-Nspire *Copyright (C) 2010-2011 Danny Clark * Contact: *Contributors: * Olivier Armad, Writer of Ndless Functions *Special Thanks To: * Justin Shaler, Creator of Trapped for the TI-83 Family * Olivier Armad, Creator of Ndless * Bayley Wang, Writer of Ndless Static Library *Project Started on August 2, 2010 at 9:25:59 PM *Project based on Block Dude Nspire by Danny Clark **********************************************************************************/ #include #include "utils.h" //asm(".string \"PRG\"\n"); int main(void) { int level=0,guyx,guyy,box,win=0,dir,x,y,beat,moved,bmove,bomb=0,gbomb=0,spike=0,lad=0,gbombe=0,inc=1; char currentlevel[25][40]; char currentladders[25][40]; char levelinfo[6]; showSimpleDialogBox("Trapped for TI-Nspire","Trapped for TI-Nspire\n\n Hold down the number key of the level you want to start with while hold a key to exit this dialog box!\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"); level=1; //level keycode check if(isKeyPressed(KEY_NSPIRE_1)) { level=1; } if(isKeyPressed(KEY_NSPIRE_2)){ level=2; } if(isKeyPressed(KEY_NSPIRE_3)){ level=3; } if(isKeyPressed(KEY_NSPIRE_4)) { level=4; } if(isKeyPressed(KEY_NSPIRE_5)) { level=5; }/* if(isKeyPressed(KEY_NSPIRE_6)) { level=6; } if(isKeyPressed(KEY_NSPIRE_7)) { level=7; } if(isKeyPressed(KEY_NSPIRE_8)) { level=8; } if(isKeyPressed(KEY_NSPIRE_9)) { level=9; } if(isKeyPressed(KEY_NSPIRE_0)) { level=10; }*/ //while the escape key is not pressed while (!isKeyPressed(KEY_NSPIRE_ESC)) { //set current level for(x=0;x<25;x++) { for(y=0;y<40;y++) { currentlevel[x][y]=setlevel(level,x,y); } } //set ladders (these are a seperate layer in order to ensure Block Dude Nspire Game Engine compatibility) for(x=0;x<25;x++) { for(y=0;y<40;y++) { currentladders[x][y]=setladder(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,currentladders,levelinfo); box=0; //Game Engine while(!win) { levelinfo[0]=guyx; levelinfo[1]=guyy; if(isKeyPressed(KEY_NSPIRE_TAB)&¤tladders[guyy][guyx]&&!box&&!bomb&&!gbomb) { lad=1; currentlevel[guyy][guyx]=202; while(lad) { if(isKeyPressed(KEY_NSPIRE_UP)) { if(currentladders[guyy-1][guyx]) { currentlevel[guyy][guyx]=0; guyy--; currentlevel[guyy][guyx]=202; levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000); } } if(isKeyPressed(KEY_NSPIRE_DOWN)) { if(currentladders[guyy+1][guyx]&&!currentlevel[guyy+1][guyx]) { currentlevel[guyy][guyx]=0; guyy++; currentlevel[guyy][guyx]=202; levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000); } if(!currentladders[guyy+1][guyx]&&!currentlevel[guyy+1][guyx]) { currentladders[guyy][guyx]=2; while(currentlevel[guyy+1][guyx]==0) { currentlevel[guyy][guyx]=0; guyy++; currentlevel[guyy][guyx]=3; levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000/3); } lad=0; } } if(isKeyPressed(KEY_NSPIRE_LEFT)) { if(currentladders[guyy][guyx-1]==2) { currentlevel[guyy][guyx]=0; guyx--; currentlevel[guyy][guyx]=202; } else { lad=0; break; } levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000); } if(isKeyPressed(KEY_NSPIRE_RIGHT)) { if(currentladders[guyy][guyx+1]==2) { currentlevel[guyy][guyx]=0; guyx++; currentlevel[guyy][guyx]=202; } else { lad=0; break; } levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000); } } } //If left is pressed... if (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; moved=1; //If he has a box, move that too. if (box||bomb||gbomb) { if(currentlevel[guyy-1][guyx-1]==1||currentlevel[guyy-1][guyx-1]==2) { currentlevel[guyy-1][guyx]=0; if(box) { currentlevel[guyy][guyx]=2; box=0; } if(bomb) { currentlevel[guyy][guyx]=6; bomb=0; } if(gbomb) { currentlevel[guyy][guyx]=7; gbomb=0; } moved=1; } else { currentlevel[guyy-1][guyx]=0; if(box) { currentlevel[guyy-1][guyx-1]=2; } if(bomb) { currentlevel[guyy-1][guyx-1]=6; } if(gbomb) { currentlevel[guyy-1][guyx-1]=7; } } } //change the guy position guyx--; if(moved) { levelinfo[0]=guyx; levelinfo[1]=guyy; currentlevel[guyy][guyx]=200; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000/2); currentlevel[guyy][guyx]=3; } if(currentlevel[guyy+1][guyx]==4) { win=1; } if(currentlevel[guyy+1][guyx]==10) { spike=1; } //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(currentlevel[guyy+1][guyx]==4) { win=1;beat=1; } if(currentlevel[guyy+1][guyx]==10) { spike=1; } //if he has a box, move that too if(box||bomb||gbomb) { currentlevel[guyy-2][guyx]=0; if(box) { currentlevel[guyy-1][guyx]=2; } if(bomb) { currentlevel[guyy-1][guyx]=6; } if(gbomb) { currentlevel[guyy-1][guyx]=7; } } drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000/8); } } //draw the updated level levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000/2); } //If the right key is pressed if (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; moved=1; //move the box too if (box||bomb||gbomb) { if(currentlevel[guyy-1][guyx+1]==1||currentlevel[guyy-1][guyx+1]==2) { currentlevel[guyy-1][guyx]=0; if(box) { currentlevel[guyy][guyx]=2; box=0; } if(bomb) { currentlevel[guyy][guyx]=6; bomb=0; } if(gbomb) { currentlevel[guyy][guyx]=7; gbomb=0; } moved=1; } else { currentlevel[guyy-1][guyx]=0; if(box) { currentlevel[guyy-1][guyx+1]=2; } if(bomb) { currentlevel[guyy-1][guyx+1]=6; } if(gbomb) { currentlevel[guyy-1][guyx+1]=7; } } } //change guy position guyx++; if(moved) { levelinfo[0]=guyx; levelinfo[1]=guyy; currentlevel[guyy][guyx]=201; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000/2); currentlevel[guyy][guyx]=5; } if(currentlevel[guyy+1][guyx]==4) { win=1; } if(currentlevel[guyy+1][guyx]==10) { spike=1; } //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(currentlevel[guyy+1][guyx]==4) { win=1; beat=1; } if(currentlevel[guyy+1][guyx]==10) { spike=1; } //move the box too if he has one if(box||bomb||gbomb) { currentlevel[guyy-2][guyx]=0; if(box) { currentlevel[guyy-1][guyx]=2; } if(bomb) { currentlevel[guyy-1][guyx]=6; } if(gbomb) { currentlevel[guyy-1][guyx]=7; } } drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000/8); } } //draw the level levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000/2); } //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 anything... if ((box||bomb||gbomb)&&!currentlevel[guyy-1][guyx+dir]) { //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; while(currentlevel[guyy+bmove][guyx+dir]==0) { currentlevel[guyy-1][guyx]=0; currentlevel[guyy+(bmove-1)][guyx+dir]=0; if(box) { currentlevel[guyy+bmove][guyx+dir]=2; } if(bomb) { currentlevel[guyy+bmove][guyx+dir]=6; } if(gbomb) { currentlevel[guyy+bmove][guyx+dir]=7; } 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||currentlevel[guyy-1][guyx+dir]!=6||currentlevel[guyy-1][guyx+dir]!=7)&&moved) { if(currentlevel[guyy-1][guyx+dir]==0) { currentlevel[guyy-1][guyx]=0; if(box) { currentlevel[guyy-1][guyx+dir]=2; box=0; } if(bomb) { currentlevel[guyy-1][guyx+dir]=6; bomb=0; } if(gbomb) { currentlevel[guyy-1][guyx+dir]=7; gbomb=0; } } } box=0; bomb=0; gbomb=0; } //if the guy didn't have a box and there is one available, pick it up else if(!currentlevel[guyy-1][guyx]){ if (!box) { if(currentlevel[guyy][guyx+dir]==2) { if(currentlevel[guyy-1][guyx+dir]!=1&¤tlevel[guyy-1][guyx+dir]!=2&¤tlevel[guyy-1][guyx+dir]!=6&¤tlevel[guyy-1][guyx+dir]!=7) { currentlevel[guyy][guyx+dir]=0; currentlevel[guyy-1][guyx]=2; box=1; } } } if (!bomb) { if(currentlevel[guyy][guyx+dir]==6) { if(currentlevel[guyy-1][guyx+dir]!=1&¤tlevel[guyy-1][guyx+dir]!=2&¤tlevel[guyy-1][guyx+dir]!=6&¤tlevel[guyy-1][guyx+dir]!=7) { currentlevel[guyy][guyx+dir]=0; currentlevel[guyy-1][guyx]=6; bomb=1; } } } if (!gbomb) { if(currentlevel[guyy][guyx+dir]==7) { if(currentlevel[guyy-1][guyx+dir]!=1&¤tlevel[guyy-1][guyx+dir]!=2&¤tlevel[guyy-1][guyx+dir]!=6&¤tlevel[guyy-1][guyx+dir]!=7) { currentlevel[guyy][guyx+dir]=0; currentlevel[guyy-1][guyx]=7; gbomb=1; } } } } //redraw the level levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000); while(isKeyPressed(KEY_NSPIRE_DOWN)); } //if the player presses up... if (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||currentlevel[guyy][guyx+dir]==6||currentlevel[guyy][guyx+dir]==7||currentlevel[guyy][guyx+dir]==11||currentlevel[guyy][guyx+dir]==9) { //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&¤tlevel[guyy-1][guyx]!=11) { 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,bomb, or gold bomb too if (box||bomb||gbomb) { 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; if(box) { currentlevel[guyy-2][guyx+dir]=2; } if(bomb) { currentlevel[guyy-2][guyx+dir]=6; } if(gbomb) { currentlevel[guyy-2][guyx+dir]=7; } } } //reset guy position guyx+=dir; guyy--; } } //redraw level if(dir==1) { currentlevel[guyy][guyx]=5; } levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000); } //if esc is pressed, exit loop if(isKeyPressed(KEY_NSPIRE_ESC)) { return 0; } //if control is pressed, explosions! (or push blocks) if(isKeyPressed(KEY_NSPIRE_CTRL)) { if (currentlevel[guyy][guyx]==3) { dir=-1; } else { dir=1; } if(!gbomb&&!box&&!bomb&&(currentlevel[guyy][guyx+dir]==6||currentlevel[guyy][guyx]==7)) { gbombe=0; if(currentlevel[guyy][guyx]==7) { gbombe=1; } currentlevel[guyy][guyx+dir]=100; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000/4); currentlevel[guyy][guyx+dir]=101; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000/4); if(currentlevel[guyy][guyx+(2*dir)]!=11) { currentlevel[guyy][guyx+(2*dir)]=102; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000/4); currentlevel[guyy][guyx+(2*dir)]=0; x=1; inc=0; while(currentlevel[guyy+x][guyx+(dir<<1)]==0) { x++; inc++; } x=1; if (currentlevel[guyy-x][guyx+(2*dir)]==2||currentlevel[guyy-x][guyx+(2*dir)]==6||currentlevel[guyy-x][guyx+(2*dir)]==7) { while(currentlevel[guyy-x][guyx+(dir*2)]==2||currentlevel[guyy-x][guyx+(dir*2)]==6||currentlevel[guyy-x][guyx+(dir*2)]==7) { currentlevel[guyy-x+1+inc][guyx+(2*dir)]=currentlevel[guyy-x][guyx+(2*dir)]; currentlevel[guyy-x][guyx+(2*dir)]=0; x++; } } } if(gbombe) { currentlevel[guyy][guyx+dir]=7; } else if (!gbombe) { currentlevel[guyy][guyx+dir]=0; x=1; inc=0; while(currentlevel[guyy+x][guyx+(dir<<1)]==0) { x++; inc++; } x=1; if(currentlevel[guyy-x][guyx+dir]==2||currentlevel[guyy-x][guyx+dir]==6||currentlevel[guyy-x][guyx+dir]==7) { while(currentlevel[guyy-x][guyx+dir]==2||currentlevel[guyy-x][guyx+dir]==6||currentlevel[guyy-x][guyx+dir]==7) { currentlevel[guyy-x+1+inc][guyx+dir]=currentlevel[guyy-x][guyx+dir]; currentlevel[guyy-x][guyx+dir]=0; x++; } } } } if(currentlevel[guyy][guyx+dir]==9&¤tlevel[guyy][guyx+(dir<<1)]==0) { currentlevel[guyy][guyx+dir]=0; currentlevel[guyy][guyx+(dir<<1)]=9; x=1; while(currentlevel[guyy-x][guyx+dir]==2||currentlevel[guyy-x][guyx+dir]==6||currentlevel[guyy-x][guyx+dir]==7||currentlevel[guyy-x][guyx+dir]==9) { currentlevel[guyy-x+1][guyx+dir]=currentlevel[guyy-x][guyx+dir]; currentlevel[guyy-x][guyx+dir]=0; x++; } x=1; while(currentlevel[guyy+x][guyx+(dir<<1)]==0) { currentlevel[guyy+x-1][guyx+(dir<<1)]=0; currentlevel[guyy+x][guyx+(dir<<1)]=9; x++; } } levelinfo[0]=guyx; levelinfo[1]=guyy; drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000/2); } //if home is pressed, subtract one from level number, win level (will just redraw level in original position) if(isKeyPressed(KEY_NSPIRE_MENU)||spike) { level--; win=1; beat=0; spike=0; } if(isKeyPressed(KEY_NSPIRE_CLICK)) { if(currentlevel[guyy][guyx]==3) { currentlevel[guyy][guyx]=5; } else { currentlevel[guyy][guyx]=3; } drawlevel(currentlevel,currentladders,levelinfo); slowdown(500000); } } //dialog boxes with level codes if(level==5) { showSimpleDialogBox("You Won","Congratulations!\nYou beat all 5 levels!"); return 0; } else { level++; win=0; switch(level) { case 1: showSimpleDialogBox("Level 1","Level 1!"); break; case 2: showSimpleDialogBox("Level 2","Level 2!"); break; case 3: showSimpleDialogBox("Level 3","Level 3!"); break; case 4: showSimpleDialogBox("Level 4","Level 4!"); break; case 5: showSimpleDialogBox("Level 5","Level 5!"); break; case 6: showSimpleDialogBox("Level 6","Level 6!"); break; case 7: showSimpleDialogBox("Level 7","Level 7!"); 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; } //repeat the loop continue; } } return 0; }