// C Source File // Created 12/22/2002; 11:56:16 PM #define USE_TI89 // Produce .89z File #define OPTIMIZE_ROM_CALLS // Use ROM Call Optimization #define SAVE_SCREEN // Save/Restore LCD Contents #include // Include All Header Files static unsigned char bullet[] = {0b0000000, 0b0100010, 0b0011100, 0b0010100, //Bullet Picture 0b0011100, 0b0100010, 0b0000000}; static unsigned char ship[5][7] = {{0b1111111, 0b1110111, 0b0110110, 0b0011100, //Up Ship Picture 0b0001000, 0b0000000, 0b0000000}, {0b0000011, 0b0000111, 0b0001111, 0b0011001, //Right Ship Picture 0b0001111, 0b0000111, 0b0000011}, {0b0000000, 0b0000000, 0b0001000, 0b0011100, //Down Ship Picture 0b0110110, 0b1110111, 0b1111111}, {0b1100000, 0b1110000, 0b1111000, 0b1001100, //Left Ship Picture 0b1111000, 0b1110000, 0b1100000}, {0b0001100, 0b0011100, 0b1111110, 0b1111111, //Player Ship Picture 0b0111111, 0b0011100, 0b0011000}}; static unsigned char MAP_PIC[9][7] = {{0b0000000, 0b0000000, 0b0000000, 0b0001000, //Space 0b0000000, 0b0000000, 0b0000000}, {0b0011100, 0b0111010, 0b1111101, 0b1011101, //Sphere 0b1011111, 0b0101110, 0b0011100}, {0b0011100, 0b0100010, 0b1000001, 0b1000001, //Non-Sphere 0b1000001, 0b0100010, 0b0011100}, {0b0111110, 0b1010101, 0b1010101, 0b1101011, //Anna Kate 0b1010101, 0b1010101, 0b0111110}, {0b0011100, 0b0100010, 0b1000001, 0b1100001, //Door 0b1100001, 0b1000001, 0b1111111}, {0b0000000, 0b0000000, 0b1100101, 0b1111111, //Key 0b1100000, 0b0000000, 0b0000000}, {0b0001100, 0b0010000, 0b1010110, 0b1001001, //Portal 0b0110101, 0b0000100, 0b0011000}, {0b0000000, 0b0000000, 0b0000000, 0b0001000, //Invisible Wall 0b0000000, 0b0000000, 0b0000000}, {0b0000000, 0b0101010, 0b0000000, 0b0100010, //Safe Zone 0b0000000, 0b0101010, 0b0000000}}; //These are Levels for the game. Each number in the map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0,7,7,7,0,0,0}, {7,7,7,7,8,0,7,7,7,7,7,0,7,8,7,0,7,0,7,0}, {0,0,0,0,0,0,7,0,0,0,0,8,7,0,7,0,7,0,7,0}, {0,7,7,7,7,7,7,0,7,7,7,7,7,0,7,7,7,0,7,8}, {8,7,8,1,1,1,1,0,7,8,0,0,0,0,0,0,0,0,7,0}, {0,7,7,7,7,7,7,7,7,0,7,7,7,4,7,7,1,7,7,0}, {0,0,0,0,0,0,0,0,0,0,7,1,1,1,1,7,1,7,5,0}, {0,0,7,1,1,1,7,1,1,1,7,1,1,1,1,7,1,7,1,8}}, {{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,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,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}}; int CURRENT_MAP[11][20]; int current_level = 0; int spheres = 0; int keys = 0; enum {UP, RIGHT, DOWN, LEFT, SHIP}; int move[5][2] = {{0,LEFT}, //Syntax: {pixels, direction} {0,UP}, {0,RIGHT}, {0,DOWN}, {0,0}}; int ship_x[] = {79,151,79,0,9}; int ship_y[] = {2,46,90,46,11}; int bullet_x[] = {0,0,0,153}; int bullet_y[] = {93,0,0,0}; char *OFF_SCREEN = 0; //Prototypes void init(void); void paint(void); void end(void); void reset(void); int reverse(int); int getrow(int); int getcol(int); // Main Function void _main(void) { int count1; init(); reset(); //Game Loop for(;;) { //Set Player in Motion If ship isnt already moving //Up | If ship isnt out of bounds if(_rowread(0xFE)&0x1 && move[SHIP][0] == 0 && getrow(ship_y[SHIP]) > 0) { //Check what player will land on //(The following checks are done BEFORE the player moves) switch(CURRENT_MAP[getrow(ship_y[SHIP]-7)][getcol(ship_x[SHIP])]) { case 4: if(keys > 0) { keys--; CURRENT_MAP[getrow(ship_y[SHIP]-7)][getcol(ship_x[SHIP])] = 0; } break; case 7: CURRENT_MAP[getrow(ship_y[SHIP]-7)][getcol(ship_x[SHIP])] = 3; case 3: break; case 5: keys++; CURRENT_MAP[getrow(ship_y[SHIP]-7)][getcol(ship_x[SHIP])] = 0; default: move[SHIP][0] = 7; move[SHIP][1] = UP; } } //Right if(_rowread(0xFE)&0x8 && move[SHIP][0] == 0 && getcol(ship_x[SHIP]) < 19) { switch(CURRENT_MAP[getrow(ship_y[SHIP])][getcol(ship_x[SHIP]+7)]) { case 4: if(keys > 0) { keys--; CURRENT_MAP[getrow(ship_y[SHIP])][getcol(ship_x[SHIP]+7)] = 0; } break; case 7: CURRENT_MAP[getrow(ship_y[SHIP])][getcol(ship_x[SHIP]+7)] = 3; case 3: break; case 5: keys++; CURRENT_MAP[getrow(ship_y[SHIP])][getcol(ship_x[SHIP]+7)] = 0; default: move[SHIP][0] = 7; move[SHIP][1] = RIGHT; } } //Down if(_rowread(0xFE)&0x4 && move[SHIP][0] == 0 && getrow(ship_y[SHIP]) < 10) { switch(CURRENT_MAP[getrow(ship_y[SHIP]+7)][getcol(ship_x[SHIP])]) { case 4: if(keys > 0) { keys--; CURRENT_MAP[getrow(ship_y[SHIP]+7)][getcol(ship_x[SHIP])] = 0; } break; case 7: CURRENT_MAP[getrow(ship_y[SHIP]+7)][getcol(ship_x[SHIP])] = 3; case 3: break; case 5: keys++; CURRENT_MAP[getrow(ship_y[SHIP]+7)][getcol(ship_x[SHIP])] = 0; default: move[SHIP][0] = 7; move[SHIP][1] = DOWN; } } //Left if(_rowread(0xFE)&0x2 && move[SHIP][0] == 0 && getcol(ship_x[SHIP]) > 0) { switch(CURRENT_MAP[getrow(ship_y[SHIP])][getcol(ship_x[SHIP]-7)]) { case 4: if(keys > 0) { keys--; CURRENT_MAP[getrow(ship_y[SHIP])][getcol(ship_x[SHIP]-7)] = 0; } break; case 7: CURRENT_MAP[getrow(ship_y[SHIP])][getcol(ship_x[SHIP]-7)] = 3; case 3: break; case 5: keys++; CURRENT_MAP[getrow(ship_y[SHIP])][getcol(ship_x[SHIP]-7)] = 0; default: move[SHIP][0] = 7; move[SHIP][1] = LEFT; } } //Esc if(_rowread(0xBF)&0x1) { break; } //Set Enemy in Motion for(count1 = 0; count1 < 4; count1++) { switch(count1) { case UP: case DOWN: if(move[count1][0] == 0) { if(getcol(ship_x[count1]) > 0 && getcol(ship_x[count1]) < 19) move[count1][0] = 7; else { move[count1][1] = reverse(move[count1][1]); //Reverse direction if out of bounds move[count1][0] = 7; } } break; case LEFT: case RIGHT: if(move[count1][0] == 0) { if(getrow(ship_y[count1]) > 0 && getrow(ship_y[count1]) < 10) move[count1][0] = 7; else { move[count1][1] = reverse(move[count1][1]); move[count1][0] = 7; } } break; } } //Moves Player and Enemy for(count1 = 0; count1 < 5; count1++) { if(move[count1][0] != 0) { switch(move[count1][1]) { case UP: ship_y[count1]--; break; case RIGHT: ship_x[count1]++; break; case DOWN: ship_y[count1]++; break; case LEFT: ship_x[count1]--; break; } move[count1][0]--; //Moves 2 pixels a frame by repeating the routine //if(move[count1][0] != 1 && move[count1][0] % 2 == 1) //continue; } } //Check what player landed on // (The following checks are done AFTER the player moves) if(move[SHIP][0] == 0) { switch(CURRENT_MAP[getrow(ship_y[SHIP])][getcol(ship_x[SHIP])]) { case 6: //Landed on a Portal ship_x[SHIP] = random(20)*7+9; ship_y[SHIP] = random(11)*7+11; break; case 1: //Landed on a Sphere CURRENT_MAP[getrow(ship_y[SHIP])][getcol(ship_x[SHIP])] = 2; spheres--; if(spheres == 0) { current_level++; reset(); } break; } } //Shoot bullets if enemy and player ships line up if(ship_x[UP] == ship_x[SHIP] && move[UP][0] == 0 && bullet_y[UP] >= 93) { bullet_x[UP] = ship_x[UP]; bullet_y[UP] = 7; } if(ship_x[DOWN] == ship_x[SHIP] && move[DOWN][0] == 0 && bullet_y[DOWN] <= 0) { bullet_x[DOWN] = ship_x[DOWN]; bullet_y[DOWN] = 85; } if(ship_y[RIGHT] == ship_y[SHIP] && move[RIGHT][0] == 0 && bullet_x[RIGHT] <= 0) { bullet_y[RIGHT] = ship_y[RIGHT]; bullet_x[RIGHT] = 146; } if(ship_y[LEFT] == ship_y[SHIP] && move[LEFT][0] == 0 && bullet_x[LEFT] >= 153) { bullet_y[LEFT] = ship_y[LEFT]; bullet_x[LEFT] = 5; } //Move bullets if(bullet_y[UP] < 93) bullet_y[UP]++; if(bullet_x[RIGHT] > 0) bullet_x[RIGHT]--; if(bullet_y[DOWN] > 0) bullet_y[DOWN]--; if(bullet_x[LEFT] < 153) bullet_x[LEFT]++; //Check if Bullet Hit Player for(count1 = 0; count1 < 4; count1++) { if(bullet_x[count1]+7 > ship_x[SHIP] && bullet_x[count1] < ship_x[SHIP]+7 && bullet_y[count1]+7 > ship_y[SHIP] && bullet_y[count1] < ship_y[SHIP]+7 && CURRENT_MAP[getrow(ship_y[SHIP])][getcol(ship_x[SHIP])] != 8) //If player isnt on a safe zone { //ngetchx(); //init(); reset(); } } paint(); } end(); } void init(void) { OFF_SCREEN = malloc(LCD_SIZE); PortSet(OFF_SCREEN, 239, 127); OSSetSR (0x0700); } void paint(void) { int count1, count2; ClrScr(); //Paint Game Boundaries DrawLine(9,9,150,9,A_NORMAL); //Horizontal Lines DrawLine(9,89,150,89,A_NORMAL); DrawLine(8,10,8,88,A_NORMAL); //Vertical Lines DrawLine(151,10,151,88,A_NORMAL); //Paint Level Map for(count1 = 0; count1 < 11; count1++) //Row { for(count2 = 0; count2 < 20; count2++) //Column { Sprite8(count2*7+9, count1*7+11, 7, MAP_PIC[CURRENT_MAP[count1][count2]], OFF_SCREEN, A_NORMAL); } } //Paint Ships for(count1 = 0; count1 < 5; count1++) { Sprite8(ship_x[count1],ship_y[count1],7,ship[count1],OFF_SCREEN,A_NORMAL); } //Paint Bullets if(bullet_y[UP] < 93) Sprite8(bullet_x[UP],bullet_y[UP],7,bullet,OFF_SCREEN,A_NORMAL); if(bullet_x[RIGHT] > 0) Sprite8(bullet_x[RIGHT],bullet_y[RIGHT],7,bullet,OFF_SCREEN,A_NORMAL); if(bullet_y[DOWN] > 0) Sprite8(bullet_x[DOWN],bullet_y[DOWN],7,bullet,OFF_SCREEN,A_NORMAL); if(bullet_x[LEFT] < 153) Sprite8(bullet_x[LEFT],bullet_y[LEFT],7,bullet,OFF_SCREEN,A_NORMAL); //Draw Virtual Screen memcpy(LCD_MEM, OFF_SCREEN, LCD_SIZE); } void reset(void) { int count1,count2; move[0][0] = 0; move[0][1] = LEFT; move[1][0] = 0; move[1][1] = UP; move[2][0] = 0; move[2][1] = RIGHT; move[3][0] = 0; move[3][1] = DOWN; move[4][0] = 0; move[4][1] = 0; ship_x[0] = 79; ship_x[1] = 151; ship_x[2] = 79; ship_x[3] = 0; ship_x[4] = 9; ship_y[0] = 2; ship_y[1] = 46; ship_y[2] = 90; ship_y[3] = 46; ship_y[4] = 11; bullet_x[0] = 0; bullet_x[1] = 0; bullet_x[2] = 0; bullet_x[3] = 153; bullet_y[0] = 93; bullet_y[1] = 0; bullet_y[2] = 0; bullet_y[3] = 0; spheres = 0; keys = 0; //Copy Level Map to CURRENT_MAP for(count1 = 0; count1 < 11; count1++) //Row { for(count2 = 0; count2 < 20; count2++) //Column { if(LEVEL_MAP[current_level][count1][count2] == 1) //Counts how many spheres on the map spheres++; CURRENT_MAP[count1][count2] = LEVEL_MAP[current_level][count1][count2]; } } } //Returns row in relation to map, given a Y coordinate int getrow(int y) { return (y-11)/7; } //Returns column in relation to map, given an X coordinate int getcol(int x) { return (x-9)/7; } //Returns the opposite of the given direction int reverse(int x) { switch(x) { case LEFT: return RIGHT; break; case RIGHT: return LEFT; break; case UP: return DOWN; break; case DOWN: return UP; break; default: return SHIP; } } void end(void) { PortRestore(); free(OFF_SCREEN); OSSetSR (0x0000); }