void space(void) { byte c; byte move_left, move_right; char delay_count; byte do_exit; move_left = 0; move_right = 0; shot_y = 0; shot_x = 0; inv_shot_y = 0; inv_shot_x = 0; do_exit = 0; clrbuf(); init_game(); delay_count = 0; do { clrbuf(); draw_invaders(); draw_tank(tank_pos); // tank shot tank_shot(); // invader shot invaders_shot(); buf2screen(); // delay invader movement if (++delay_count >= 5 - ((char)inv_pos_y / 3)) { delay_count = 0; move_invaders(); } // delay if (inv_count < 14) delay_ms((14 - inv_count)); // read keyboard c = io_read(129); if (c == 0xe0) { c = io_read(129); if (c == 0x6b) { // left down move_left = 1; } else if (c == 0x74) { // right down move_right = 1; } else if (c == 0x6b + 0x80) { // left up move_left = 0; } else if (c == 0x74 + 0x80) { // right up move_right = 0; } } else if (c == 0x29) { // shoot if (shot_y == 0) { shot_x = (tank_pos + 1) * 2 + 1; shot_y = 90; } } else if (c == 0x76) { // escape do_exit = 1; } // move tank if (move_left) { if (tank_pos > 0) tank_pos -= 1; } else if (move_right) { if (tank_pos < 76) tank_pos += 1; } } while (!do_exit); }
void tetris(void) { char c, part_no; byte i, stop, start; show_splashscreen(); io_write(5, 42); io_write(6, 15); draw_playfield(); start_song(); start = 1; while (1) { if (start) { next_part_no = rand() % 7; lines = 0; curr_y = 10; remove_complete_lines(); clear_next_part(); while (io_read(128) != 255); do { vputs(95, 65, "GET READY"); buf2screen(); delay_ms(300); vputs(95, 65, " "); buf2screen(); delay_ms(300); } while (io_read(128) == 255); start = 0; } stop = 0; curr_x = 5; curr_y = 1; clear_next_part(); part_no = next_part_no; next_part_no = rand() % 7; draw_next_part(); select_part(part_no); draw_curr_part(); buf2screen(); while (!stop) { for (i = 0; i < 20 && !stop; i++) { if (lines < 20) delay_ms(35); else if (lines < 50) delay_ms(25); else if (lines < 70) delay_ms(18); else if (lines < 100) delay_ms(12); else delay_ms(8); if (!stop) { c = io_read(128); if (c == ' ') { // rotate part rotate_curr_part(); buf2screen(); } else if (c == 0) { // left, right, down c = io_read(128); if (c == 75) { // left move_left(); buf2screen(); } else if (c == 77) { // right move_right(); buf2screen(); } else if (c == 80) { // down while (!move_down()) buf2screen(); buf2screen(); stop = 1; } } else if (c == 27) return; } // if (!stop) } if (!stop) { stop = move_down(); buf2screen(); } } remove_complete_lines(); if (curr_y <= 2) { clear_playfield(); vputs(95, 65, "GAME OVER"); buf2screen(); getchar(); vputs(95, 65, " "); start = 1; } } }