diff --git a/Makefile b/Makefile index 56e5162..6604afa 100644 --- a/Makefile +++ b/Makefile @@ -13,11 +13,11 @@ compile: png2udg ./build/topvertiright.png -a > ./build/topvertiright.asm png2udg ./build/ghostpill.png -a > ./build/ghostpill.asm png2sp1sprite ./build/prota_sprites.png -b -i sprite_protar -f 16 -s rodata_user > ./build/prota.asm + png2sp1sprite ./build/prota_dead.png -b -i sprite_protar_dead -f 16 -s rodata_user > ./build/prota_dead.asm png2sp1sprite ./build/red_ghost.png -b -i red_ghost -f 16 -s rodata_user > ./build/red_ghost.asm ls *.bin - zcc +zx -v -startup=31 -DWFRAMES=3 -clib=sdcc_iy -Cz--screen=screen.scr -SO3 --max-allocs-per-node10000 @zproject.lst -pragma-include:zpragma.inc -o msnampac -create-app - #zcc +zx -v -m -startup=31 -clib=sdcc_iy -SO3 --max-allocs-per-node10000 @zproject.lst -pragma-include:zpragma.inc -o alley + zcc +zx -v -startup=31 -DWFRAMES=3 -clib=sdcc_iy -Cz--screen=intro.scr -SO3 --max-allocs-per-node10000 @zproject.lst -pragma-include:zpragma.inc -o msnampac -create-app #zcc +zx -v -m -startup=31 -clib=sdcc_iy -SO3 --max-allocs-per-node10000 @zproject.lst -pragma-include:zpragma.inc -o alley #appmake +zx -b screen.scr --org 16384 --noloader --blockname screen -o screen.tap #appmake +zx -b alley_CODE.bin --org 24500 --noloader --blockname code -o code.tap #appmake +zx -b alley_BANK_6.bin --org 49152 --noloader --blockname bank6 -o bank6.tap diff --git a/build/binaries.lst b/build/binaries.lst index fb65c95..861998b 100644 --- a/build/binaries.lst +++ b/build/binaries.lst @@ -1,4 +1,5 @@ prota +prota_dead horizontal vertical corner_left diff --git a/build/prota_dead.asm b/build/prota_dead.asm new file mode 100644 index 0000000..dd9ad26 --- /dev/null +++ b/build/prota_dead.asm @@ -0,0 +1,296 @@ +SECTION rodata_user + +; Original: 64, 24 (=8 x 3 chars) +; Blocks: 2 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + +PUBLIC _sprite_protar_dead1 +._sprite_protar_dead1 + + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000110 + defb @00111111 + defb @01111111 + defb @01111111 + defb @11111111 + defb @11110000 + defb @11110000 + defb @11100000 + defb @11000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + +._sprite_protar_dead1_f2 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000001 + defb @00000001 + defb @00000001 + defb @00000001 + defb @00000011 + defb @00000011 + defb @00000011 + defb @00000011 + defb @00000011 + defb @00001111 + defb @00000010 + defb @00000010 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + +._sprite_protar_dead1_f3 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000001 + defb @00000001 + defb @00000001 + defb @00000001 + defb @00000001 + defb @00000001 + defb @00000001 + defb @00000001 + defb @00000001 + defb @00000001 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + +._sprite_protar_dead1_f4 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00001000 + defb @00000101 + defb @00000101 + defb @01100000 + defb @00010000 + defb @00000000 + defb @11100000 + defb @00000000 + defb @00010000 + defb @00100101 + defb @01000101 + defb @00001000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + +PUBLIC _sprite_protar_dead2 +._sprite_protar_dead2 + + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @11000000 + defb @11100000 + defb @11100000 + defb @11110000 + defb @11110000 + defb @11110000 + defb @01110000 + defb @00111000 + defb @00001000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + +._sprite_protar_dead2_f2 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @11000000 + defb @11000000 + defb @11000000 + defb @11000000 + defb @11100000 + defb @11100000 + defb @11100000 + defb @11100000 + defb @11100000 + defb @11111000 + defb @00100000 + defb @00100000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + +._sprite_protar_dead2_f3 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @10000000 + defb @10000000 + defb @10000000 + defb @10000000 + defb @10000000 + defb @10000000 + defb @10000000 + defb @10000000 + defb @10000000 + defb @10000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + +._sprite_protar_dead2_f4 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @11000000 + defb @00010000 + defb @00010000 + defb @00100000 + defb @00000000 + defb @00011000 + defb @00000000 + defb @00100000 + defb @00010000 + defb @00000000 + defb @00000000 + defb @11000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + defb @00000000 + diff --git a/build/prota_dead.png b/build/prota_dead.png new file mode 100644 index 0000000..5f1a52a Binary files /dev/null and b/build/prota_dead.png differ diff --git a/globals.h b/globals.h index 02d315f..2f5f41b 100644 --- a/globals.h +++ b/globals.h @@ -33,6 +33,7 @@ #define DIR_LEFT 3 #define DIR_RIGHT 4 #define NONE 250 +#define ELUDE 25 #define JAILED 20 #define JAILED_EXITING 1 #define ACTIVE 0 @@ -46,6 +47,7 @@ extern struct sp1_Rect full_screen; // globals are supposed to generate less code and with 128k of memory it's important struct sprite { struct sp1_ss* sp; + struct sp1_ss* alt; uint8_t x; uint8_t y; uint8_t offset; @@ -61,6 +63,10 @@ struct sprite { // it comes from built binaries: extern uint8_t sprite_protar1[]; extern uint8_t sprite_protar2[]; + +extern uint8_t sprite_protar_dead1[]; +extern uint8_t sprite_protar_dead2[]; + // red ghost extern uint8_t red_ghost1[]; extern uint8_t red_ghost2[]; diff --git a/build/intro.scr b/intro.scr similarity index 100% rename from build/intro.scr rename to intro.scr diff --git a/logic.c b/logic.c index a3e6ac6..f3e4338 100644 --- a/logic.c +++ b/logic.c @@ -26,6 +26,7 @@ void check_keys() void loose_a_live() { + uint8_t i, j; repaint_lives = 1; --lives; set_eaten(&ghost_magenta); @@ -33,6 +34,24 @@ void loose_a_live() { set_eaten(&ghost_cyan); set_eaten(&ghost_yellow); + for(i = 0; i != 4; ++i) { + sp1_MoveSprAbs(ghosts[i]->sp, &full_screen, (void*) ghosts[i]->offset, ghosts[i]->default_y, ghosts[i]->default_x, 0, 0); + } + + // prota dead animation, first hide the sprite from the screen + sp1_MoveSprAbs(pacman.sp, &full_screen, (void*) pacman.offset, pacman.y, 32, 0, 0); + // 1, 33, 65, 97 + for(j = 1; j < 129; j += 32) { + sp1_MoveSprAbs(pacman.alt, &full_screen, (void*) j, pacman.y, pacman.x, 0, 0); + sp1_UpdateNow(); + for(i = 0; i != 5; ++i) { + wait(); + } + } + + sp1_MoveSprAbs(pacman.alt, &full_screen, (void*) col, pacman.y, 32, 0, 0); + sp1_UpdateNow(); + pacman.y = 21; pacman.x = 14; pacman.dx = 0; @@ -43,14 +62,6 @@ uint8_t allow_next(uint8_t next) { return next == 9 || next == 16 || next == 11 || next == 18; } - -void iteratecolours(void * func) { - sp1_IterateSprChar(ghost_red.sp, func); - sp1_IterateSprChar(ghost_cyan.sp, func); - sp1_IterateSprChar(ghost_magenta.sp, func); - sp1_IterateSprChar(ghost_yellow.sp, func); -} - void set_eaten(struct sprite * for_who) { for_who->x = for_who->default_x; for_who->y = for_who->default_y; @@ -81,11 +92,9 @@ uint8_t goto_xy(struct sprite * for_who, uint8_t x, uint8_t y) { } struct sprite * has_collision() { - for(idx = 0; idx != 4; ++idx) { - if(pacman.x == ghosts[idx]->x && pacman.y == ghosts[idx]->y) { - // eat - return ghosts[idx]; - } + if(abs(pacman.x - ghosts[idx]->x) < 2 && abs(pacman.y - ghosts[idx]->y) < 2) { + // eat + return ghosts[idx]; } return NULL; } @@ -155,7 +164,14 @@ void move_one_ghost(uint8_t t1, uint8_t t2, uint8_t t3, uint8_t t4) { then_go(DIR_UP); return; } - if(pill_eaten != NONE) { + if(ghosts[idx]->active == ELUDE) { + // check collission before move + collided_sprite = has_collision(); + if(collided_sprite != NULL) { + // eat + set_eaten(collided_sprite); + } + if(pacman.x < ghosts[idx]->x && could_go(DIR_RIGHT)) { then_go(DIR_RIGHT); } else if(pacman.x > ghosts[idx]->x && could_go(DIR_LEFT)) { @@ -168,7 +184,23 @@ void move_one_ghost(uint8_t t1, uint8_t t2, uint8_t t3, uint8_t t4) { ghosts[idx]->x += ghosts[idx]->dx; ghosts[idx]->y += ghosts[idx]->dy; } - } else { + + // make ghost flicker if elude mode and almost finishing pill eaten + if(pill_eaten < 40 && ghosts[idx]->active == ACTIVE) { + if((frame & 1) == 0) { + sp1_IterateSprChar(ghosts[idx]->sp, initialiseColourBlue); + } else { + sp1_IterateSprChar(ghosts[idx]->sp, initialiseColourWhite); + } + } + + } else { // ACTIVE + collided_sprite = has_collision(); + if(collided_sprite != NULL) { + loose_a_live(); + return; + } + if(pacman.x > ghosts[idx]->x && could_go(DIR_RIGHT)) { then_go(DIR_RIGHT); } else if(pacman.x < ghosts[idx]->x && could_go(DIR_LEFT)) { @@ -182,6 +214,7 @@ void move_one_ghost(uint8_t t1, uint8_t t2, uint8_t t3, uint8_t t4) { ghosts[idx]->y += ghosts[idx]->dy; } } + } void move_ghosts() { @@ -232,12 +265,15 @@ void check_fsm() { } else if(current == 11) { points += 50; // energizers - are worth 50 points each pill_eaten = 125; - iteratecolours(initialiseColourBlue); + for(idx = 0; idx != 4; ++idx) { + if(ghosts[idx]->active == ACTIVE) { + ghosts[idx]->active = ELUDE; + sp1_IterateSprChar(ghosts[idx]->sp, initialiseColourBlue); + } + } } } - - // side change if(pacman.y == 12) { if(pacman.x < 2 && pacman.dx == -1) { @@ -278,43 +314,28 @@ void check_fsm() { if(points > 300 || (points > 10 && idx != 1)) { ghosts[idx]->active = goto_xy(ghosts[idx], 15, 12); } - } else if(ghosts[idx]->active == ACTIVE) { + } else if(ghosts[idx]->active == ACTIVE || ghosts[idx]->active == ELUDE) { move_ghosts(); - } else { + } else if(ghosts[idx]->active <= JAILED) { --ghosts[idx]->active; } } // while has eaten pill if(pill_eaten != NONE) { --pill_eaten; - // initialiseColourWhite, initialiseColourBlue - if(pill_eaten < 40) { - if((frame & 1) == 0) { - iteratecolours(initialiseColourBlue); - } else { - iteratecolours(initialiseColourWhite); - } - } - collided_sprite = has_collision(); - if(collided_sprite != NULL) { - // eat - set_eaten(collided_sprite); - } } if(pill_eaten == 0) { pill_eaten = NONE; + for(idx = 0; idx != 4; ++idx) { + if(ghosts[idx]->active == ELUDE) { + ghosts[idx]->active = ACTIVE; + } + } sp1_IterateSprChar(ghost_red.sp, initialiseColourGhostRed); sp1_IterateSprChar(ghost_cyan.sp, initialiseColourGhostCyan); sp1_IterateSprChar(ghost_magenta.sp, initialiseColourGhostMagenta); sp1_IterateSprChar(ghost_yellow.sp, initialiseColourYellow); } - - if(pill_eaten == NONE) { - collided_sprite = has_collision(); - if(collided_sprite != NULL) { - loose_a_live(); - } - } } diff --git a/msnampac.c b/msnampac.c index cce17c9..9185968 100644 --- a/msnampac.c +++ b/msnampac.c @@ -126,6 +126,7 @@ int main() sp1_TileEntry('n', topvertiright); pacman.sp = add_sprite(); + pacman.alt = add_dead_prota_sprite(); pacman.offset = 1; pacman.currentoffset = 1; diff --git a/sprites.c b/sprites.c index fa0c563..07dcb9d 100644 --- a/sprites.c +++ b/sprites.c @@ -67,6 +67,18 @@ struct sp1_ss * add_sprite() { return sp; } +struct sp1_ss * add_dead_prota_sprite() { + struct sp1_ss * sp; + sp = sp1_CreateSpr(SP1_DRAW_XOR1LB, SP1_TYPE_1BYTE, 3, (int)sprite_protar_dead1, 1); + sp1_AddColSpr(sp, SP1_DRAW_XOR1, SP1_TYPE_1BYTE, (int)sprite_protar_dead2, 1); + + sp1_AddColSpr(sp, SP1_DRAW_XOR1RB, SP1_TYPE_1BYTE, 0, 0); + + sp1_IterateSprChar(sp, initialiseColourYellow); + + return sp; +} + struct sp1_ss * add_ghost_sprite() { struct sp1_ss * sp; sp = sp1_CreateSpr(SP1_DRAW_LOAD1LB, SP1_TYPE_1BYTE, 3, (int)red_ghost1, 1); diff --git a/sprites.h b/sprites.h index 0563c9e..a136c87 100644 --- a/sprites.h +++ b/sprites.h @@ -9,6 +9,7 @@ extern struct sp1_ss * add_sprite(); +extern struct sp1_ss * add_dead_prota_sprite(); extern struct sp1_ss * add_ghost_sprite(); extern struct sp1_ss * add_ghost_red_sprite(); extern struct sp1_ss * add_ghost_cyan_sprite();