From ef3844bf2128fa82f20c5995d1fca66fadba2ce3 Mon Sep 17 00:00:00 2001 From: scratko Date: Wed, 17 Apr 2024 17:00:48 +0300 Subject: Added colors Changed the number of pacman's lives. Fixed clear_or_revert_symbol(). Target hit display. Changed ghost initialization. Clearing ghost positions is moved to the function. Added flag in struct ghost_type (reached_pacman). Changed catching stage. Now eating an energizer resets the counter. --- pacman.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 13 deletions(-) (limited to 'pacman.c') diff --git a/pacman.c b/pacman.c index 1468765..ce2fd5d 100644 --- a/pacman.c +++ b/pacman.c @@ -2,6 +2,7 @@ #include "ghosts.h" #include "pac.h" #include "queue.h" +#include "color_palette.h" #include #include #include @@ -9,12 +10,12 @@ enum { timeout_duration = 0, - sleep_duration = 190000, + sleep_duration = 120000, key_escape = 27, max_get_out_stage = 6, chase_move_limit = 70, scatter_move_limit = 35, - frightened_move_limit = 30, + frightened_move_limit = 50, phase_limit = 4, prison_limit = 30, max_score = 243 @@ -361,13 +362,14 @@ static void catching_stage(game_space field, if(mode_params->current_mode == frightened) catch_ghost(field, current_ghost); else { + current_ghost->reached_pacman = 1; catch_pac(pac); - if(pac->lives) - initialize_ghosts(red_ghost, pink_ghost, blue_ghost, - orange_ghost); - initialize_modes(mode_params); - usleep(sleep_duration); return; +#if 0 + initialize_ghosts(red_ghost, pink_ghost, blue_ghost, + orange_ghost); + return; +#endif } } if(current_ghost->capture_info.status) @@ -375,9 +377,19 @@ static void catching_stage(game_space field, } } +static int ghost_caught_pacman(struct ghost_type red_ghost, + struct ghost_type pink_ghost, + struct ghost_type blue_ghost, + struct ghost_type orange_ghost) +{ + return red_ghost.reached_pacman || pink_ghost.reached_pacman || + blue_ghost.reached_pacman || orange_ghost.reached_pacman; +} + static void final_stage(struct game_params_type *game_options, int win) { int key; + reset_attr(); if(win) { move(17, 10); printw("YOU WIN"); @@ -415,6 +427,7 @@ int main() srand(time(NULL)); initscr(); start_color(); + set_pairs(); cbreak(); noecho(); curs_set(0); @@ -438,6 +451,8 @@ int main() mode_params.current_mode = frightened; mode_params.reverse_direction = 1; pac.is_energizer_eaten = 0; + /* if frightened mode is activated already */ + mode_params.frightened_count = 0; } /* * ghosts @@ -469,17 +484,23 @@ int main() /* * displaying characters and score */ + display_score(pac.score); display_ghosts_on_field(&red_ghost, &pink_ghost, &blue_ghost, &orange_ghost); - display_character(pac.position.y, pac.position.x, pac_char); - display_score(pac.score); - + if(ghost_caught_pacman(red_ghost, pink_ghost, blue_ghost, + orange_ghost)) { + display_hit(pac.position, &red_ghost, &pink_ghost, &blue_ghost, + &orange_ghost); + usleep(sleep_duration*5); + } else + display_character(pac.position.y, pac.position.x, pac_char); usleep(sleep_duration); prison_leaving_stage(field, &red_ghost, &pink_ghost, &blue_ghost, &orange_ghost); #ifdef DEBUG move(0, 50); + reset_attr(); if(mode_params.current_mode == chase) printw("CHASE %d ", mode_params.chase_count); else if(mode_params.current_mode == scatter) @@ -487,11 +508,20 @@ int main() else if(mode_params.current_mode == frightened) printw("FRIGHTENED %d ", mode_params.frightened_count); move(1, 50); - printw("LIVES: %d", pac.lives); + printw("LIVES: %d ", pac.lives); + move(2, 50); + printw("%d %d ", orange_ghost.position.x, orange_ghost.position.y); + move(3, 50); + printw("%d %d ", pac.position.x, pac.position.y); refresh(); #endif - if(!pac.lives || pac.score == max_score ) { - final_stage(&game_options, !pac.lives ? 0 : 1); + if(pac.lives < 0 || pac.score == max_score ) { +#if 0 + if(pac.lives < 0) + display_ghosts_on_field(&red_ghost, &pink_ghost, &blue_ghost, + &orange_ghost); +#endif + final_stage(&game_options, pac.lives < 0 ? 0 : 1); if(game_options.exit) break; else { @@ -502,6 +532,22 @@ int main() &orange_ghost); usleep(sleep_duration); } + continue; + } + if(ghost_caught_pacman(red_ghost, pink_ghost, blue_ghost, + orange_ghost)) { + erase_hit(pac.position); + clear_ghost_positions(field, &eaten_coins, &red_ghost, &pink_ghost, + &blue_ghost, &orange_ghost); + pac.position.x = pac_x; + pac.position.y = pac_y; + initialize_ghosts(&red_ghost, &pink_ghost, &blue_ghost, + &orange_ghost); + initialize_modes(&mode_params); + display_ghosts_on_field(&red_ghost, &pink_ghost, &blue_ghost, + &orange_ghost); + display_character(pac.position.y, pac.position.x, pac_char); + usleep(sleep_duration); } } clear_field_and_queue(field, &eaten_coins); -- cgit v1.2.3