Skip to content

Commit

Permalink
fix not seen ghosts
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmolina committed Dec 23, 2019
1 parent 217a63e commit 7cfcf94
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 47 deletions.
3 changes: 2 additions & 1 deletion globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ uint8_t frame = 0;
uint8_t lives = 0;
uint8_t level = 0;
uint8_t repaint_lives = 1;
uint8_t speed = 0;
uint8_t reached_level = 0;
uint8_t slowticker = 0;
uint8_t showing_points = NONE;
uint8_t idx;
uint16_t matrixrow;
Expand Down
3 changes: 2 additions & 1 deletion globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ extern uint8_t col;
extern uint8_t current;
extern uint16_t points;
extern uint8_t remaining_points;
extern uint8_t speed;
extern uint8_t reached_level;
extern uint8_t slowticker;
extern uint8_t frame;
extern uint8_t showing_points;

Expand Down
2 changes: 1 addition & 1 deletion int.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ unsigned char pick;
void
wait(void)
{
while (abs(tick - timer) < speed) {
while (abs(tick - timer) < SPEED) {
intrinsic_halt();
in = (joy)(&joy_keys);
}
Expand Down
2 changes: 2 additions & 0 deletions int.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEAL
#define WFRAMES 2
#endif

#define SPEED 6

#define clock(x) (tick)

extern unsigned char tick;
Expand Down
110 changes: 69 additions & 41 deletions logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void nampac_go_home() {
pacman.x = 13;
pacman.offset = RIGHTC1;
pacman.direction = NONE;
sp1_MoveSprAbs(pacman.sp, &full_screen, (void*) pacman.offset, 2, 2, 0, 0);
sp1_MoveSprAbs(pacman.sp, &full_screen, (void*) pacman.offset, pacman.y, pacman.x, 0, 0);
}

Expand Down Expand Up @@ -229,6 +230,10 @@ void init_ghost(struct spritep * for_who) {
for_who->direction = NONE;
for_who->last_dir = NONE;
reset_colors(for_who);

// ensure repaint: sp1 tricky
sp1_MoveSprAbs(for_who->sp, &full_screen, (void*) for_who->offset, 2, 2, 0, 0);
sp1_MoveSprAbs(for_who->sp, &full_screen, (void*) for_who->offset, for_who->y, for_who->x, 0, 0);
}


Expand Down Expand Up @@ -467,32 +472,18 @@ void move_one_ghost() {
}

} else if(ghosts[idx]->active == SCATTER) {
// cyan: x=32 x y=24
// red: x = 32, y=0
// magenta: x= 0, y = 0
// yellow: x= 0, y= 24
/*if(idx == GCYAN) {

if(idx == GCYAN) {
then_go(ghost_gotoIA(32, 24));
} else if (idx == GRED) {
then_go(ghost_gotoIA(32, 0));
} else if (idx == GMAGENTA) {
then_go(ghost_gotoIA(0, 0));
} else if (idx == GYELLOW) {
then_go(ghost_gotoIA(0, 24));
}*/
}

/*if(ghosts[idx]->direction == NONE) {
if(could_go(DIR_UP)) {
then_go(DIR_UP);
} else if(could_go(DIR_DOWN)) {
then_go(DIR_DOWN);
} else if(could_go(DIR_LEFT)) {
then_go(DIR_LEFT);
} else if(could_go(DIR_RIGHT)) {
then_go(DIR_RIGHT);
}
}*/
}


if(ghosts[idx]->direction != NONE) { // not found already a collision
if (ghosts[idx]->active == FRIGHTENED && (((frame + idx) & 1) == 0)) {
Expand All @@ -508,22 +499,71 @@ void move_ghosts() {
// &ghost_red, &ghost_cyan, &ghost_magenta, &ghost_yellow

switch(idx) {
case GCYAN: // Cyan
// hasta que Pac-Man captura al menos 30 pildoras
case GCYAN:
move_one_ghost();
break;
case GRED: // Rojo: Intenta estár detras de Pac-Man en modo "Acoso"
case GRED:
move_one_ghost();
break;

case GMAGENTA:
// su comportamiento siempre es llegar hacia el punto donde Pac-Man
move_one_ghost();
break;

case GYELLOW:
// "a su bola"
move_one_ghost();
}

// switches to scatter or chase, except blinky that depends on number of remaining points
if (idx == GRED ) {
if(reached_level == 0 && remaining_points < 20) {
return;
} else if(reached_level == 1 && remaining_points < 30) {
return;
} else if(reached_level >= 2 && reached_level <= 5 && remaining_points < 40) {
return;
} else if(reached_level >= 6 && reached_level <= 8 && remaining_points < 50) {
return;
} else if(reached_level >= 9 && reached_level <= 11 && remaining_points < 60) {
return;
} else if(reached_level >= 12 && reached_level <= 14 && remaining_points < 80) {
return;
} else if(reached_level > 14 && remaining_points < 120) {
// blinky almost always chase after passing 14 times!
return;
}
}

if((ghosts[idx]->active == CHASE || ghosts[idx]->active == SCATTER)) {

if(idx == GCYAN && frame == 1) { // only advances if ghosts are actively moving and for one ghost
++slowticker;
}

if(slowticker == 8) {
// go scatter
ghosts[idx]->active = SCATTER;
} else if(slowticker == 30) {
ghosts[idx]->active = CHASE;

} else if(slowticker == 38) {
ghosts[idx]->active = SCATTER;
} else if(slowticker == 55) {
ghosts[idx]->active = CHASE;

} else if(slowticker == 63) {
ghosts[idx]->active = SCATTER;
} else if(slowticker == 85) {
ghosts[idx]->active = CHASE;

} else if((reached_level < 3 && slowticker == 91) || (reached_level > 3 && slowticker == 155) ) {
ghosts[idx]->active = SCATTER;
} else if(slowticker == 160 || slowticker == 96) {
ghosts[idx]->active = CHASE;
}
}


}


Expand All @@ -532,17 +572,16 @@ void next_level() {
bit_beepfx_di_fastcall(BEEPFX_SCORE);
zx_border(INK_BLACK);
++level;
// helps determining scatter mode changes and some others
slowticker = 0;
++reached_level;
++map_num;
if(map_num > 3) {
map_num = 1;
}

if(map_num == 1) {
remaining_points = MAP1_TOTAL_POINTS;
// only when returning to first map again, increase speed
if (speed > 1 && map_num > 3) {
--speed;
}
} else if(map_num == 2){
remaining_points = MAP2_TOTAL_POINTS;
} else if(map_num == 3){
Expand Down Expand Up @@ -603,9 +642,10 @@ void check_fsm() {
--remaining_points;
} else if(current == 11) {
points += 20; // energizers - are worth 20 points each
pill_eaten = 125;
pill_eaten = 90;
for(idx = 0; idx != 4; ++idx) {
if(ghosts[idx]->active == CHASE || ghosts[idx]->active == FRIGHTENED) {
if((ghosts[idx]->active == CHASE || ghosts[idx]->active == FRIGHTENED
|| ghosts[idx]->active == SCATTER) && level < 19) {
// "sacar pies en polvorosa"
if(ghosts[idx]->direction == DIR_LEFT) {
then_go(DIR_RIGHT);
Expand Down Expand Up @@ -729,18 +769,6 @@ void check_fsm() {
next_level();
}

if(in_key_pressed(IN_KEY_SCANCODE_1)) {
level = 1;
show_cherry();
} else if(in_key_pressed(IN_KEY_SCANCODE_2)) {
level = 2;
show_cherry();
}else if(in_key_pressed(IN_KEY_SCANCODE_3)) {
level = 3;
show_cherry();
}else if(in_key_pressed(IN_KEY_SCANCODE_4)) {
next_level();
}
}

void paint_lives() {
Expand Down
7 changes: 4 additions & 3 deletions msnampac.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ void all_lives_lost() {

srand(tick);

set_ghosts_default_coords();
nampac_go_home();

reset_map();

set_ghosts_default_coords();
all_ghosts_go_home();
show_billboard(READY);

Expand All @@ -119,7 +119,8 @@ void all_lives_lost() {


pick = 1;
speed = 6;
reached_level = 0;
slowticker = 0;
}


Expand Down Expand Up @@ -180,7 +181,7 @@ int main()

sp1_UpdateNow();

frame += 1;
++frame;

if(frame == 3) { // frame will go 0, 1, 2
frame = 0;
Expand Down

0 comments on commit 7cfcf94

Please sign in to comment.