/* Place a shop on level */ void placeShop(LEVELMAP *map) { int shopX; int shopY; int yi; shopX = randMap(2,map->width - 10); shopY = randMap(2,map->height - 16); map->grid[shopY][shopX+1] = OUTERWALL; map->grid[shopY][shopX-1] = OUTERWALL; map->grid[shopY-1][shopX] = OUTERWALL; map->grid[shopY-1][shopX-1] = OUTERWALL; map->grid[shopY-1][shopX+1] = OUTERWALL; map->grid[shopY+1][shopX-1] = WATER; map->grid[shopY+1][shopX+1] = WATER; map->grid[shopY][shopX] = SHOP; for (yi = shopY + 1; yi < shopY + 15; yi++) { map->grid[yi][shopX] = GRAVEL; } map->shop_loc.x = shopX; map->shop_loc.y = shopY; }
void placePortal(LEVELMAP *map) { int portalX; int portalY; int yi; portalX = randMap(2,map->width - 10); portalY = randMap(2,map->height - 16); map->portal_up_loc.x = portalX; map->portal_up_loc.y = portalY; map->grid[portalY][portalX] = PORTAL; for (yi = portalY + 1; yi < portalY + 15; yi++) { if (map->grid[yi][portalX] != OUTERWALL && map->grid[yi][portalX] != SHOP && map->grid[yi][portalX] != PORTAL) map->grid[yi][portalX] = GRAVEL; } portalX = randMap(2,map->width - 10); portalY = randMap(2,map->height - 16); map->portal_down_loc.x = portalX; map->portal_down_loc.y = portalY; map->grid[portalY][portalX] = PORTAL; for (yi = portalY + 1; yi < portalY + 15; yi++) { if (map->grid[yi][portalX] != OUTERWALL && map->grid[yi][portalX] != SHOP && map->grid[yi][portalX] != PORTAL) map->grid[yi][portalX] = GRAVEL; } }
/* Generates a random name for a level */ char *makeLevelName() { const char *letpairs = "..LEXEGEZACEBISOUSESARMAINDIREA.ERATENBERALAVETIEDORQUANTEISRION"; char *buf; int i; buf = (char *)malloc(sizeof(char) * 9); memset(buf,0,sizeof(buf)); for (i = 0; i < 8; i++) { buf[i] = letpairs[randMap(0,strlen(letpairs)-1)]; } buf[8] = 0; stripout(buf,'.'); for (i = 1; i < 8; i++) { buf[i] = tolower(buf[i]); } return buf; }
// Main Function void _main(void) { // This is where the level map is defined // The map is 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,1}};*/ int map1[12][20] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {8,7,0,0,0,9,7,9,7,0,0,0,0,0,9,8,8,8,8,8}, {0,0,7,0,9,0,0,0,0,7,0,0,0,9,0,0,0,0,0,0}, {0,0,0,8,0,0,0,0,0,0,7,0,9,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,9,7,0,0}, {0,0,0,0,0,0,0,9,7,0,0,0,0,0,0,9,0,0,7,0}, {0,9,8,8,7,0,9,0,0,7,0,0,0,0,9,0,0,0,0,8}, {8,0,0,0,0,8,0,0,0,0,7,0,0,9,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,7,9,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; int key=0; int laser = 0; int justLaser = 0; int missile = 0; int justMissile = 0; int missileSlow = 2; short int keys[8]; POSITION laserPos; POSITION oldLaserPos; POSITION missilePos; POSITION oldMissilePos; POSITION oldRType; POSITION rTypePos = {0,4}; int score = 0; int forward = 0; //int map_x_location=0; //POSITION pos = {80,5}; //int pos = 0; INT_HANDLER interrupt1 = GetIntVec(AUTO_INT_1); // this will save auto int 1 // print a simple title and disclaimer clrscr(); printf("A game by Ben Cherry \nversion 0.2 Beta \nUse at your own risk! \nreport any bugs to me\nArrow keys - move ship\n2nd-fire straight laser\ndiamond-fire down missile\nDestroy the blocks!\nGame may become unstable\npast the ground raise!\nPress Enter to Begin"); while (ngetchx() != KEY_ENTER){} clrscr(); // seed the random numbers randomize(); // get the key masks getKeyMasks(keys); // DESTROY auto-interrupt 1 so as not to mess up _rowread SetIntVec(AUTO_INT_1,DUMMY_HANDLER); if (!GrayOn ()) return; Draw_Map(map1, rTypePos, laserPos, laser, missilePos, missile); // the main game loop while (!quit()) { // if the user has a missile out, deal with it if (missile && missileSlow == 2) { missileSlow = 1; oldMissilePos = missilePos; missilePos.x++; missilePos.y++; if (missilePos.x > 20) missile = 0; if (blowWall(missilePos,map1)) { map1[missilePos.y][missilePos.x]-=2;//= 0; /**/score++; /**/if (map1[missilePos.y][missilePos.x] < 0) map1[missilePos.y][missilePos.x] = 0; missile = 0; justMissile = 0; Draw_Map(map1,rTypePos,laserPos,laser,missilePos,missile); } // if the shot was just fired, then there wont be one to erase if (!justMissile && missile) { moveMissile(oldMissilePos,missilePos); } else if (missile) { drawMissile(missilePos); justMissile = 0; } } else { missileSlow++; } // if the user has a laser shot that is still going, continue it if (laser) { oldLaserPos = laserPos; laserPos.x++; if (laserPos.x > 20) laser=0; if (blowWall(laserPos,map1)) { map1[laserPos.y][laserPos.x]--; //= 0; /**/if (map1[laserPos.y][laserPos.x] == 0) score++; laser = 0; justLaser = 0; Draw_Map(map1,rTypePos,laserPos,laser, missilePos, missile); } // if the shot was just fired, then there wont be one to erase if (!justLaser && laser) { moveLaser(oldLaserPos,laserPos); } else if (laser){ drawLaser(laserPos); justLaser = 0; } } // scroll the screen forward one block every third time through the main loop if (forward == 3) { randMap(&map1); //rTypePos.x++; forward = 0; Draw_Map(map1,rTypePos,laserPos,laser, missilePos, missile); } else { forward++; } // if you ran into a wall, quit if (detectWall(rTypePos,map1)) break; key = _rowread(ARROW_ROW); // if the user pressed right, move the ship right if (key & keys[RIGHT]) { oldRType = rTypePos; rTypePos.x++; if (rTypePos.x > 20) rTypePos.x--; if (!detectWall(rTypePos,map1)){ moveRType(oldRType,rTypePos); } else { //rTypePos.x--; break; } } // If the user pressed left, move the ship left if (key & keys[LEFT]) { oldRType = rTypePos; //rTypePos.x--; if (rTypePos.x - 1 >= 0) rTypePos.x--; if (!detectWall(rTypePos,map1)){ moveRType(oldRType,rTypePos); } else { //rTypePos.x++; break; } } // if the user pressed up, move the ship up if (key & keys[UP]) { oldRType = rTypePos; //rTypePos.y--; if (rTypePos.y - 1 >= 0) rTypePos.y--; if (!detectWall(rTypePos,map1)) { moveRType(oldRType,rTypePos); } else { //rTypePos.y++; break; } } // if the user pressed down, move the ship down if (key & keys[DOWN]) { oldRType = rTypePos; rTypePos.y++; if (rTypePos.y > 12) rTypePos.y = 12; if (!detectWall(rTypePos,map1)) { moveRType(oldRType,rTypePos); } else { //rTypePos.y--; break; } } // if 2nd was pushed, fire the laser if (key & keys[SECOND]) { if (!laser) { justLaser = 1; laser = 1; laserPos.x = rTypePos.x + 1; laserPos.y = rTypePos.y; } } // if diamond was pushed fire the downward missiles if (key & keys[DIAMOND]) { if (!missile) { justMissile = 1; missile = 1; missileSlow = 2; missilePos.x = rTypePos.x; missilePos.y = rTypePos.y; } } // slow down the program because _rowread is too fast delay(); } // somehow the user left the game, either by crashing or quitting, so make sure to disable all changes GrayOff(); SetIntVec(AUTO_INT_1,interrupt1); clrscr(); printf("You destroyed %d blocks!",score); while (ngetchx() != KEY_ENTER){} }