void advanceGame(void* gameMemory, OOGameInput* input, OOGameOutput* output) { cbgame * game = (cbgame*) gameMemory; oofloat respawnTime = 2.f; if(game->p1.score == CombatGame_ScoreLimit) { //Player 1 wins } else if (game->p2.score == CombatGame_ScoreLimit) { //Player 2 Wins } if(!game->p1.alive && game->time >= game->p1.timeOfDeath + respawnTime) { respawnPlayer(game, &game->p1); } else if (!game->p2.alive && game->time >= game->p2.timeOfDeath + respawnTime) { respawnPlayer(game, &game->p2); } game->input = input; game->output = output; if( !game->initialised ) { initGame(game); } game->moveDelta = game->p1.x; updateGame(game); game->moveDelta -= game->p1.x; clearScreen(game); moveWall(game); drawPlayer(game, &game->p2); drawPlayer(game, &game->p1); drawArena(game); if(game->p1.missile.isFiring) { drawMissile(game,&game->p1); } if(game->p2.missile.isFiring) { drawMissile(game,&game->p2); } game->time += game->input->dt; }
void Draw_Map(int map_array[12][20], POSITION pos, POSITION laserPos, int laser, POSITION missilePos, int missile) { //int x = map_x_location; int x = 0; int y = 0; SetPlane (LIGHT_PLANE); ClrScr (); SetPlane (DARK_PLANE); ClrScr (); drawRType(pos); if (laser) drawLaser(laserPos); if (missile) drawMissile(missilePos); // Well.. the map_x_location will keep track of where we are on the X-plane on the map array // This way we mask out the stuff in the array that we use.. So we will only read 30x8 elements of the // array (instead of 60x8 which it is at the moment.. ).. This might sound unuseful, and it sort of is // with a small array as this one.. but i'm guessing you will create worlds that are much much bigger.. // so.. to gain more speed.. we mask it out ;) /*while (x<20) {// Again, we can't view more than 30 blocks.. so.. don't calculate more than 30 blocks if ((map_array[y][x]==7)) { // If the array at this location is equal to 1, place a ground piece Sprite8(x*8, y*8, 8, ground_down, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_down, GetPlane (LIGHT_PLANE), SPRT_XOR); } if ((map_array[y][x]==8)) { // .. and if it's 2, place block1 Sprite8(x*8, y*8, 8, ground_flat, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_flat, GetPlane (LIGHT_PLANE), SPRT_XOR); } if (map_array[y][x]==9) { Sprite8(x*8, y+8, 8, ground_up, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); Sprite8(x*8, y+8, 8, ground_up, GrayGetPlane(DARK_PLANE), SPRT_XOR); } y++; // Now.. we're increasing the Y value.. note that i'm drawing the world from LEFT to RIGHT // I've seen people who draw their world TOP to DOWN or otherwise, but i found LEFT to RIGHT // is the best way to draw the world.. if (y>11) { // We've reached the limit.. restore the Y value, and move 1 block row forward.. y=0; x++; } }*/ for (x = 0; x <= 19; x++) { for (y = 0; y <= 11; y++) { if (map_array[y][x] == 7) { Sprite8(x*8, y*8, 8, ground_down, GrayGetPlane(DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_down, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); } else if (map_array[y][x] == 8) { Sprite8(x*8, y*8, 8, ground_flat, GrayGetPlane(DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_flat, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); } else if (map_array[y][x] == 9) { Sprite8(x*8, y*8, 8, ground_up, GrayGetPlane(DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_up, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); } } } }
// all draw functions that get called in render funciton void drawGame_Textures(Game * game) { drawBackground(game); drawSpike(game); glBindTexture(GL_TEXTURE_2D, 0); drawWater(); drawPlatform(game,5); drawMissile(game); drawSkeleton(game); // used to allow non textures objects to maintain their color glBindTexture(GL_TEXTURE_2D, 0); }
// function that draws the screen void Draw_Map(int map_x_location, char map_array[12][MAP_SIZE], POSITION pos, POSITION laserPos, int laser, POSITION missilePos, int missile) { int x = map_x_location; int y = 0; // clear both planes SetPlane (LIGHT_PLANE); ClrScr(); SetPlane (DARK_PLANE); ClrScr(); // draw ship, and missiles and cannons if they exist drawShip(pos, map_x_location); if (laser) drawLaser(laserPos, map_x_location); if (missile == 1) drawMissile(missilePos, map_x_location); if (missile == -1) drawUpMissile(missilePos, map_x_location); // Well.. the map_x_location will keep track of where we are on the X-plane on the map array // This way we mask out the stuff in the array that we use.. So we will only read 20x12 elements of the // array (instead of MAP_SIZEx12 which it is at the moment.. ) while (x < (map_x_location + 20)) {// Again, we can't view more than 20 blocks.. so.. don't calculate more than 20 blocks if ((map_array[y][x] == 1)) { // If the array at this location is equal to 1, place a broken piece Sprite8((x - map_x_location) * 8, y * 8, 8, broken2_dark, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, broken2_light, GetPlane (LIGHT_PLANE), SPRT_XOR); } if ((map_array[y][x] == 2)) { // If the array at this location is equal to 1, place a broken piece Sprite8((x - map_x_location) * 8, y * 8, 8, broken1_dark, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, broken1_light, GetPlane (LIGHT_PLANE), SPRT_XOR); } if ((map_array[y][x] == 3)) { // .. and if it's 2, place block1 Sprite8((x - map_x_location) * 8, y * 8, 8, block1_dark, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, block1_light, GetPlane (LIGHT_PLANE), SPRT_XOR); } if ((map_array[y][x] == 4)) { // a 3 means the indestructible block Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_light, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_dark, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_mid, GrayGetPlane(DARK_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_dark, GrayGetPlane(DARK_PLANE), SPRT_XOR); } y++; // Now.. we're increasing the Y value.. note that i'm drawing the world from LEFT to RIGHT // I've seen people who draw their world TOP to DOWN or otherwise, but i found LEFT to RIGHT // is the best way to draw the world.. if (y > 11) { // We've reached the limit.. restore the Y value, and move 1 block row forward.. y = 0; x++; } } }
inline void moveMissile(POSITION oldPos, POSITION newPos) { eraseMissile(oldPos); drawMissile(newPos); }
inline void eraseMissile(POSITION pos) { drawMissile(pos); }
// Main Function void _main(void) { // This is where the level map is defined // The map is 12 blocks of height 8 tall, and that fills the screen // 0s are blank, 1s are ground blocks, and 2s are the other blocks /*int map1[12][82] = { {0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,2,2,2,0,0,0,2,2,2,2,2,2,2,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0}, {0,0,0,2,0,0,0,0,2,2,0,0,0,2,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,2,2,0,0,0,2,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,2,0,0,2,0,0,2,2,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,2,0,2,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0}, {0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,2,0,2,0,2,0,2,2,2,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,2,0,2,0,2,0,2,2,2,0,0,0}, {0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,0,0,0,2,0,0,2,2,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,0,0,0,2,0,0,2,2,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0}, {0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,0,0,0,0,2,0,0,0,2,0,2,2,2,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,0,0,0,0,2,0,0,0,2,0,2,2,2,0,0,0}, {0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,0,0,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,0,0,0,2,0,2,0,0,0,0,0}, {0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,2,0,0,0,0,0,0,0,2,2,0,2,0,2,2,2,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,2,0,0,0,0,0,0,0,2,2,0,2,0,2,2,2,0,0,0}, {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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){} }
inline void moveMissile(POSITION oldPos, POSITION newPos, int map_x_location) { eraseMissile(oldPos,map_x_location); drawMissile(newPos,map_x_location); }
inline void eraseMissile(POSITION pos, int map_x_location) { drawMissile(pos,map_x_location); }
// the main function void _main(void) { unsigned int difficulty = NORMAL; short int key=0; short int keys[8]; unsigned int level_num = 1; unsigned short int score = 0; int done = 0; unsigned int money = 0; int cannon_level = 1; int missile_level = 0; char map[12][MAP_SIZE]; // seed the random numbers randomize(); // get the key masks getKeyMasks(keys); INT_HANDLER interrupt1 = GetIntVec(AUTO_INT_1); // this will save auto int 1 // draw title screen and wait for keypress GrayOn(); drawTitle(2); ngetchx(); //draw background title screen and menu drawTitle(1); drawWords(difficulty); POSITION pointer = {10,0}; drawPointer(pointer); // the menu loop while (1) { key = ngetchx(); if (key == KEY_ENTER && pointer.y != OPTIONS) { if (pointer.y == PLAY) break; if (pointer.y == HIGH_SCORES) printHiScores(); if (pointer.y == HELP) doHelp(); if (pointer.y == ABOUT) { SetIntVec(AUTO_INT_1,interrupt1); GrayOff(); exit(0); } GraySetAMSPlane(LIGHT_PLANE); clrscr(); GraySetAMSPlane(DARK_PLANE); clrscr(); drawTitle(1); drawWords(difficulty); pointer=(POSITION) { 10,0 }; drawPointer(pointer); } if (key == KEY_LEFT && pointer.y == OPTIONS && difficulty < VERY_EASY) { difficulty+=1; GraySetAMSPlane(LIGHT_PLANE); clrscr(); GraySetAMSPlane(DARK_PLANE); clrscr(); drawTitle(1); drawPointer(pointer); drawWords(difficulty); } if (key == KEY_RIGHT && pointer.y == OPTIONS && difficulty > IMPOSSIBLE) { difficulty-=1; GraySetAMSPlane(LIGHT_PLANE); clrscr(); GraySetAMSPlane(DARK_PLANE); clrscr(); drawTitle(1); drawPointer(pointer); drawWords(difficulty); } if (key == KEY_UP || key == KEY_DOWN) drawPointer(pointer); if (key == KEY_UP && pointer.y > 0) pointer.y--; if (key == KEY_DOWN && pointer.y < 4) pointer.y++; if (key == KEY_UP || key == KEY_DOWN) drawPointer(pointer); } key = 0; // turn off gray, so we can destroy auto-int-1 and not mess it up GrayOff(); // DESTROY auto-interrupt 1 so as not to mess up _rowread SetIntVec(AUTO_INT_1,DUMMY_HANDLER); // turn gray back on GrayOn(); // randomize the map randomMap(difficulty, map, level_num); //the main game loop while (!quit() && !done) { done = 0; int fin = 0; int win = 0; int forward = 0; int map_x_location = 0; int laser = 0; int justLaser = 0; int missile = 0; int justMissile = 0; int missileSlow = 2; POSITION laserPos; POSITION oldLaserPos; POSITION missilePos; POSITION oldMissilePos; POSITION oldShip; POSITION ShipPos = {0,5}; // we need to disable gray temporarily to do the shop screen... GrayOff(); SetIntVec(AUTO_INT_1, interrupt1); shop(&money, &cannon_level, &missile_level); SetIntVec(AUTO_INT_1, DUMMY_HANDLER); GrayOn(); // draws the level Draw_Map(map_x_location, map, ShipPos, laserPos, laser, missilePos, missile); // the loop for the action in the level while (!quit()) { // if the user has a missile out, deal with it if (missile && missileSlow == 2) { missileSlow = 1; oldMissilePos = missilePos; missilePos.x++; missilePos.y+=missile; if (missilePos.x > map_x_location + 20) missile = 0; if (missilePos.y < 0 || missilePos.y > 12) { missile = 0; eraseMissile(missilePos, map_x_location); } if (blowWall(missilePos,map)) { if (map[missilePos.y][missilePos.x] < 4) { map[missilePos.y][missilePos.x]-=3; if (map[missilePos.y][missilePos.x] == 0) { score++; money+=BLOCK_VALUE; } } if (map[missilePos.y][missilePos.x] < 0) map[missilePos.y][missilePos.x] = 0; missile = 0; justMissile = 0; Draw_Map(map_x_location,map,ShipPos,laserPos,laser,missilePos,missile); } // if the shot was just fired, then there wont be one to erase if (!justMissile && missile == 1) { moveMissile(oldMissilePos,missilePos,map_x_location); } else if (missile == 1) { drawMissile(missilePos,map_x_location); justMissile = 0; } else if (!justMissile && missile == -1) { moveUpMissile(oldMissilePos, missilePos, map_x_location); } else if (missile == -1) { drawUpMissile(missilePos, map_x_location); 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 > map_x_location + 20) laser=0; if (blowWall(laserPos,map)) { if (map[laserPos.y][laserPos.x] < 4) { map[laserPos.y][laserPos.x]-=cannon_level; if (map[laserPos.y][laserPos.x] <= 0) { score++; money+=BLOCK_VALUE; map[laserPos.y][laserPos.x] = 0; } } else if (map[laserPos.y][laserPos.x] == 4 && cannon_level == 4) { map[laserPos.y][laserPos.x] = 1; } laser = 0; justLaser = 0; Draw_Map(map_x_location,map,ShipPos,laserPos,laser, missilePos, missile); } // if the shot was just fired, then there wont be one to erase if (!justLaser && laser) { moveLaser(oldLaserPos,laserPos,map_x_location); } else if (laser) { drawLaser(laserPos,map_x_location); justLaser = 0; } } // scroll the screen forward one block every (difficulty) time through the main loop if (forward == difficulty) { map_x_location++; ShipPos.x++; forward = 0; if (map_x_location >= MAP_SIZE - 20) { win = 1; level_num++; break; } // if you ran into a wall, quit if (detectWall(ShipPos,map)) { win = 1; score /= 2 ; break; } Draw_Map(map_x_location,map,ShipPos,laserPos,laser, missilePos, missile); } else { forward++; } // if you ran into a wall, quit if (detectWall(ShipPos,map)) { win = 1; score = 0; break; } if (_rowread(~((short)(1<<1))) & (1<<6) && _rowread(~((short)(1<<2))) & (1<<6)) { win = 1; level_num++; break; } // get keypresses key = _rowread(ARROW_ROW); // if the user pressed right, move the ship right if (key & keys[RIGHT]) { oldShip = ShipPos; ShipPos.x++; if (ShipPos.x > map_x_location + 18) ShipPos.x--; if (!detectWall(ShipPos,map)) { moveShip(oldShip,ShipPos,map_x_location); } else { win = 1; score = 0; break; } } // If the user pressed left, move the ship left if (key & keys[LEFT]) { oldShip = ShipPos; ShipPos.x--; if (ShipPos.x < map_x_location) ShipPos.x++; if (!detectWall(ShipPos,map)) { moveShip(oldShip,ShipPos,map_x_location); } else { win = 1; score = 0; break; } } // if the user pressed up, move the ship up if (key & keys[UP]) { oldShip = ShipPos; if (ShipPos.y - 1 < 0) { ShipPos.y = 0; } else { ShipPos.y--; } if (!detectWall(ShipPos,map)) { moveShip(oldShip,ShipPos,map_x_location); } else { win = 1; score = 0; break; } } // if the user pressed down, move the ship down if (key & keys[DOWN]) { oldShip = ShipPos; ShipPos.y++; if (ShipPos.y > 10) ShipPos.y = 10; if (!detectWall(ShipPos,map)) { moveShip(oldShip,ShipPos,map_x_location); } else { win = 1; score = 0; break; } } // if 2nd was pushed, fire the laser if (key & keys[SECOND]) { if (!laser) { justLaser = 1; laser = 1; laserPos.x = ShipPos.x + 1; laserPos.y = ShipPos.y; } } // if diamond was pushed fire the downward missiles if (key & keys[DIAMOND]) { if (missile_level == 3 || missile_level == 1) { if (!missile) { justMissile = 1; missile = 1; missileSlow = 2; missilePos.x = ShipPos.x; missilePos.y = ShipPos.y; } } } // if shift was pushed fire the upward missiles if (key & keys[SHIFT]) { if (missile_level == 2 || missile_level == 3) { if (!missile) { justMissile = 1; missile = -1; missileSlow = 2; missilePos.x = ShipPos.x; missilePos.y = ShipPos.y; } } } /*if (key & keys[ALPHA]) { score += 10; }*/ // slow down the program because _rowread is too fast delay(); } // back to the overall game loop if (win) { if (level_num <= LEVEL_NUM) { won(difficulty, map, level_num); } else { fin = 1; break; } } } // the user left, either by winning or quitting, so make sure everything is reset so the calc will be fine GrayOff(); SetIntVec(AUTO_INT_1,interrupt1); hiScoresGo(score, difficulty, level_num); }