include "cpc464.ccz80"; // Use de Amstrad library byte i = 32; // Declare a byte variable and initialize it with 32 repeat (224) // Loop of 224 pass printc(i++); // Call to printc function (included in cpc464.ccz80 library) and post-increment the i variable return; // Ends program an return to BASIC
ccz80 program.ccz80 /org=#A000
// Oh Mummy 2!// Well, it's a little tribute to that great gameinclude "cpc464.ccz80", "CPC_image.ccz80";// Data spritearray byte sprite_man_left_stop = { 0, 0, 0, 0, 0, 7, 14, 0, 3, 15, 15, 0, 0, 190, 135, 0, 51, 255, 224, 0, 0, 191, 134, 0, 0, 103, 120, 0, 0, 7, 60, 128, 0, 159, 240, 128, 0, 191, 233, 0, 0, 23, 15, 0, 0, 3, 14, 0, 0, 3, 12, 0, 0, 3, 12, 0, 0, 51, 204, 0, 0, 119, 204, 0 }, sprite_man_left_move = { 0, 0, 0, 0, 0, 7, 14, 0, 3, 15, 15, 0, 0, 190, 135, 0, 51, 255, 224, 0, 0, 191, 134, 0, 0, 103, 120, 0, 0, 7, 240, 0, 51, 240, 225, 0, 51, 240, 195, 0, 0, 13, 15, 8, 1, 14, 15, 12, 1, 15, 7, 76, 3, 14, 3, 238, 51, 204, 17, 204, 119, 204, 51, 136 }, sprite_man_right_stop = { 0, 0, 0, 0, 0, 7, 14, 0, 0, 15, 15, 12, 0, 30, 215, 0, 0, 112, 255, 204, 0, 22, 223, 0, 0, 225, 110, 0, 16, 195, 14, 0, 16, 240, 159, 0, 0, 121, 223, 0, 0, 15, 142, 0, 0, 7, 12, 0, 0, 3, 12, 0, 0, 3, 12, 0, 0, 51, 204, 0, 0, 51, 238, 0 }, sprite_man_right_move = { 0, 0, 0, 0, 0, 7, 14, 0, 0, 15, 15, 12, 0, 30, 215, 0, 0, 112, 255, 204, 0, 22, 223, 0, 0, 225, 110, 0, 0, 240, 14, 0, 0, 120, 240, 204, 0, 60, 240, 204, 1, 15, 11, 0, 3, 15, 7, 8, 35, 14, 15, 8, 119, 12, 7, 12, 51, 136, 51, 204, 17, 204, 51, 238 }, sprite_mummy_left = { 0, 0, 0, 0, 0, 16, 192, 0, 0, 48, 224, 0, 0, 48, 224, 0, 0, 48, 192, 0, 0, 16, 224, 0, 16, 240, 224, 0, 48, 240, 160, 0, 48, 32, 224, 0, 0, 48, 224, 0, 0, 48, 224, 0, 0, 48, 240, 0, 0, 112, 112, 0, 0, 112, 48, 128, 0, 224, 48, 128, 16, 224, 112, 128 }, sprite_mummy_right = { 0, 0, 0, 0, 0, 48, 128, 0, 0, 112, 192, 0, 0, 112, 192, 0, 0, 48, 192, 0, 0, 112, 128, 0, 0, 112, 240, 128, 0, 80, 240, 192, 0, 112, 64, 192, 0, 112, 192, 0, 0, 112, 192, 0, 0, 240, 192, 0, 0, 224, 224, 0, 16, 192, 224, 0, 16, 192, 112, 0, 16, 224, 112, 128 };// Program variablesbyte i, n, n1, n2, c;byte x_man, y_man, step_man, x_man_prev, y_man_prev, lives, score, alive; // Man variablesbyte x_stone, y_stone; // Rock variablesbyte x_exit, y_exit; // Screen variablesword p, q, s;array byte background_man[64]; // Background man bufferarray byte music_block[13]; // Music timer buffergosub Initialization; // Global initializationlocate(1,1); printc(253);while (1) // Main loop{ gosub Presentation; gosub InitializeGame; // Game initialization while (lives) { gosub InitializeScreen; // Current screen initialization q = notes; every(12, PlayMusic, music_block); // Initialize music while (alive && !(x_man == x_exit && y_man == y_exit)) { repeat (4) frame(); // For reduce game speed // Evaluate man moving if (*char_address(x_man, y_man + 2) == 0 && *char_address(x_man + 1, y_man + 2) == 0) // Under man is nothing { ++y_man; } else { if (testkey(67) != -1 && y_man > 3 && *char_address(x_man, y_man - 1) == 0 && *char_address(x_man + 1, y_man - 1) == 0) // Jump { --y_man; } if (testkey(34) != -1 && x_man > 1 && *char_address(x_man - 1, y_man) == 0 && *char_address(x_man - 1, y_man + 1) == 0) // Left { --x_man; step_man = 0; } if (testkey(27) != -1 && x_man < 39 && *char_address(x_man + 2, y_man) == 0 && *char_address(x_man + 2, y_man + 1) == 0) // Right { ++x_man; step_man = 1; } } gosub TestManMoved; // Move stone or create new if (y_stone) // Stone is falling { ++y_stone; if (((x_stone == x_man || x_stone == x_man + 1) && y_stone == y_man) || testkey(66) != -1) // Lost live { alive = 0; for (s = 500; s <= 2000; s += 500) sound(2, s, 25, 15, 0, 0, 0); // Sound for lost for (i = 1; i <= 2; ++i) { locate(2 * lives + 29, i); printc(18); // Erase man of screen top } --lives; if (lives) { pen(1); locate(7, 12); prints("Press SPACE to continue ..."); while (testkey(47) == -1); } } else if (*char_address(x_stone, y_stone) != 0) // Stone founds another stone, floor or exit door { y_stone = 0; pen(2); locate(1, 2); printw(++score); // Update score } else // Stone continue falling { pen(2); locate(x_stone, y_stone - 1); printc(' '); locate(x_stone, y_stone); printc(253); } } else // Create new stone { if (rand() % 5 == 0) // Calculate new column stone by random { x_stone = rand() % 38 + 1 + (x_exit == 1) * 2; } else // Calculate new column stone try filling the spaces where there is not stone { n1 = x_exit == 1 ? 3 : 1; n2 = x_exit == 1 ? 40 : 38; i = 24; c = 0; do { for (n = n1; n <= n2; ++n) if (*char_address(n, i) == 0 || i == y_man + 1 && (n == x_man || n == x_man + 1)) ++c; if (c == 0) --i; } while (c == 0); // Calculate in i the first row where there is a column witout stone // Calculate random number between 1 and number of columns without stone in row i and search the column of that position in row i without stone for (c = rand() % c + 1, x_stone = n1, n = 1; n <= c; ++n, ++x_stone) while (!(*char_address(x_stone, i) == 0 || i == y_man + 1 && (x_stone == x_man || x_stone == x_man + 1))) ++x_stone; --x_stone; } y_stone = 3; } } if (alive) { for (s = 1000; s >= 500; s -= 100) sound(2, s, 5, 15, 0, 0, 0); // Sound for win if (--y_exit < 4) y_exit = 20; // Increment height of exit door } remain(music_block); // Finalize music } if (!lives) { pen(1); locate(12, 12); prints("G A M E O V E R"); locate(7, 14); prints("Press SPACE to continue ..."); while (testkey(47) == -1); }} // End main loopTestManMoved: // Test if man is moved and update image in screenif (x_man != x_man_prev || y_man != y_man_prev){ put_image(x_man_prev, y_man_prev, background_man); get_image(x_man, y_man, background_man); put_image(x_man, y_man, step_man ? (x_man % 2 ? sprite_man_right_stop : sprite_man_right_move) : (x_man % 2 ? sprite_man_left_stop : sprite_man_left_move)); x_man_prev = x_man; y_man_prev = y_man;}return;PlayMusic: // Play musicarray word notes = { 379, 338, 319, 338, 379, 379, 338, 319, 253, 338, 319, 379, 379, 338, 319, 338, 338, 379, 379, 338, 319, 253, 338, 319, 379, 269, 253, 253, 253, 253, 239, 253, 284, 338, 319, 284, 284, 284, 284, 253, 284, 319, 0 };sound(1, **q, 20, 12, 0, 0, 0);if (**(q += 2) == 0) q = notes;return;// ***************** InitializeScreen:// *****************cls();paper(1);locate(1,25);printc(18);paper(0); // Floorfor (i = 1; i <= lives; ++i) put_image(2 * i + 29, 1, sprite_man_right_move); // Livespen(1);locate(1, 1);prints("Score");pen(2);locate(1, 2);printw(score); // Scorepen(2);locate(15, 1);prints("Oh Mummy 2!");locate(15, 2);repeat (11) printc(#9A);put_image(12, 1, sprite_mummy_right);put_image(27, 1, sprite_mummy_left); // Titlex_exit = (rand() % 2 ? 39 : 1); // Calculate side of exit doorpen(1);locate(x_exit, y_exit - 1);prints("\xFE\xFF");locate(x_exit, y_exit + 2);prints("\xD0\xD0"); // Exit doorx_man = x_man_prev = 19;y_man = y_man_prev = 23;step_man = 1; // 0 for left, 1 for rightalive = 1;get_image(x_man, y_man, background_man);put_image(x_man, y_man, sprite_man_right_stop); // Man// Create some initial stonespen(2);repeat (25){ // Calculate new stone column do x_stone = rand() % 40 + 1; while (x_stone >= x_man - 1 && x_stone <= x_man + 3); for (y_stone = 24; *char_address(x_stone, y_stone) != 0; --y_stone); // Calculate stone row locate (x_stone, y_stone); printc(253);}y_stone = 0;return;// *************** InitializeGame:// ***************score = 0;lives = 5;y_exit = 20;return;// ************* Presentation:// *************array byte presentation_move_block[13]; // Block for timercls();put_image(1, 1, sprite_mummy_left);put_image(39, 1, sprite_mummy_right);pen(2);locate(6, 2);prints("\x9A\x9A\x9A O h M u m m y 2 ! \x9A\x9A\x9A\r\n\n\n");pen(1);prints(" You are in an egyptian pyramid and\r\nthe ceiling is falling. You need avoid\r\n");prints("the falling stones and jump to top them\r\nin order to arrive to exit door.");locate(3, 15);prints("O left P right Q jump ESC exit");pen(2);locate(8, 25);prints("Press RETURN to start ...");// Define man animationx_man = x_man_prev = 1;y_man = y_man_prev = 19;step_man = 1; // 0 for left, 1 for rightevery(10, PresentationMove, presentation_move_block);q = notes;every(12, PlayMusic, music_block);while (testkey(18) == -1);remain(presentation_move_block);remain(music_block);return;PresentationMove: // Man animation routinegosub TestManMoved;if (step_man) if (x_man < 39) ++x_man; else step_man = 0;else if (x_man > 1) --x_man; else step_man = 1;return;// *************** Initialization:// ***************array byte inks = { 0, 26 ,10, 16 }, clock[4], symbol_table[24];array byte symbol_stone = { 126, 215, 169, 203, 241, 143, 227, 126 }, symbol_exit1 = { 117, 69, 98, 69, 117, 0, 255, 255 }, symbol_exit2 = { 92, 72, 72, 72, 72, 0, 255, 255 };// Symbolssymbolafter(253, symbol_table);symbol(253, symbol_stone);symbol(254, symbol_exit1);symbol(255, symbol_exit2);// Screenmode(1);border(*inks, *inks);for (i = 0, p = inks; i <= 3; ++i, ++p) ink(i, *p, *p);paper(0);cls();srand(**time(clock)); // Initialize seed for random numbersreturn;
function word char_address(byte, byte){ "ld hl,3", "add hl,sp", "ld a,(hl)", "inc hl", "inc hl", "ld h,(hl)", "ld l,a", "dec h", "dec l", "jp __scr_char_position"}function byte get_image(byte, byte, word){ "ld hl,2", "add hl,sp", "ld e,(hl)", "inc hl", "ld d,(hl)", "inc hl", "inc hl", "ld a,(hl)", "inc hl", "inc hl", "ld h,(hl)", "ld l,a", "dec h", "dec l", "call __scr_char_position", "ld b,2", "__get_image_1:", "push bc", "push hl", "ld b,8", "__get_image_2:", "push bc", "push hl", "ld bc,4", "ldir", "pop hl", "ld bc,2048", "add hl,bc", "pop bc", "djnz __get_image_2", "pop hl", "ld bc,80", "add hl,bc", "pop bc", "djnz __get_image_1", "ret"}function byte put_image(byte, byte, word){ "ld hl,2", "add hl,sp", "ld e,(hl)", "inc hl", "ld d,(hl)", "inc hl", "inc hl", "ld a,(hl)", "inc hl", "inc hl", "ld h,(hl)", "ld l,a", "dec h", "dec l", "call __scr_char_position", "ex de,hl", "ld b,2", "__put_image_1:", "push bc", "push de", "ld b,8", "__put_image_2:", "push bc", "push de", "ld bc,4", "ldir", "ex de,hl", "pop hl", "ld bc,2048", "add hl,bc", "ex de,hl", "pop bc", "djnz __put_image_2", "ex de,hl", "pop hl", "ld bc,80", "add hl,bc", "ex de,hl", "pop bc", "djnz __put_image_1", "ret"}