diff options
Diffstat (limited to 'field.c')
-rw-r--r-- | field.c | 112 |
1 files changed, 81 insertions, 31 deletions
@@ -3,6 +3,7 @@ #include "queue.h" #include <ncurses.h> #include <stdlib.h> +#include "color_palette.h" static const char field_sample[field_height][field_width] = { {"////////////////////////////"}, @@ -34,7 +35,7 @@ static const char field_sample[field_height][field_width] = { {"/.//////////.//.//////////./"}, {"/1..........2..2..........1/"}, {"////////////////////////////"}, - {" C C C Score: "} + {" C C Score: "} }; static void copy_field(game_space field) @@ -107,6 +108,7 @@ void print_field(game_space field) symbol = field[i][j]; move(i, j); if(is_coin_symbol(symbol, j, i) && field_has_coin(j, i)) { + paint_field_element(coin); symbol == energizer ? addch('*') : addch('.'); continue; } @@ -114,23 +116,31 @@ void print_field(game_space field) case one_path: case two_paths: case yellow_block: + reset_attr(); addch(' '); break; case block: - addch('/'); + paint_field_element(block); + addch(' '); break; +#if 0 case energizer: addch('*'); break; +#endif case door: - addch('#'); + paint_field_element(door); + addch(' '); break; case ' ': + reset_attr(); addch(' '); break; } - if(i == field_height-1) + if(i == field_height-1) { + symbol != ' ' ? paint_stats() : reset_attr(); addch(symbol); + } refresh(); } } @@ -139,6 +149,8 @@ void print_field(game_space field) void display_character(int y, int x, enum select_character symbol) { move(y, x); + if(symbol == pac_char) + paint_pac(); addch(symbol); refresh(); } @@ -148,11 +160,15 @@ void display_ghosts_on_field(struct ghost_type *red_ghost, struct ghost_type *blue_ghost, struct ghost_type *orange_ghost) { + paint_ghost(red_ghost->color, red_ghost->frightened_status); display_character(red_ghost->position.y, red_ghost->position.x, ghost_char); + paint_ghost(pink_ghost->color, pink_ghost->frightened_status); display_character(pink_ghost->position.y, pink_ghost->position.x, ghost_char); + paint_ghost(blue_ghost->color, blue_ghost->frightened_status); display_character(blue_ghost->position.y, blue_ghost->position.x, ghost_char); + paint_ghost(orange_ghost->color, orange_ghost->frightened_status); display_character(orange_ghost->position.y, orange_ghost->position.x, ghost_char); } @@ -160,13 +176,14 @@ void display_ghosts_on_field(struct ghost_type *red_ghost, void display_score(int value) { move(field_height-1, 25); + paint_stats(); printw("%d", value); refresh(); } void clear_or_revert_symbol(const game_space field, struct coordinates position, enum select_character character, - struct queue *eaten_coins) + const struct queue *eaten_coins) { int x, y; x = position.x; @@ -174,40 +191,44 @@ void clear_or_revert_symbol(const game_space field, struct coordinates position, int symbol = field[y][x]; move(y, x); if(character == ghost_char) { + if(is_coin_symbol(symbol, x, y) && field_has_coin(x, y) && + !queue_consists_point(eaten_coins, position)) { + if(symbol == energizer && field_has_energizer(field, x, y)) { + paint_field_element(coin); + addch('*'); + } else { + paint_field_element(coin); + addch('.'); + } + refresh(); + return; + } switch(symbol) { case one_path: case two_paths: case three_paths: - if(field_has_coin(x, y)) - queue_consists_point(eaten_coins, position) ? - addch(' ') : addch('.'); - else - addch(' '); - break; case yellow_block: - if(yellow_block_contains_coin(x, y)) - queue_consists_point(eaten_coins, position) ? - addch(' ') : addch('.'); - else - addch(' '); + reset_attr(); + addch(' '); + break; + case coin: + reset_attr(); + addch(' '); break; case door: + paint_field_element(door); addch('#'); break; - case energizer: - field_has_energizer(field, x, y) ? addch('*') : addch(' '); - break; - case coin: - queue_consists_point(eaten_coins, position) ? - addch(' ') : addch('.'); - break; case ' ': + reset_attr(); addch(' '); break; } } - else if(character == pac_char) + else if(character == pac_char) { + reset_attr(); addch(' '); + } refresh(); } @@ -288,25 +309,54 @@ int is_equal_points(struct coordinates first_point, struct coordinates void erase_life(int value) { enum { - two_lives_left = 2, one_life_left = 1, no_lives_left = 0, gap = 2, - three_lives_x = 5 + two_lives_x = 3 }; int x, y; y = field_height - 1; switch(value) { - case two_lives_left: - x = three_lives_x; - break; case one_life_left: - x = three_lives_x - gap; + x = two_lives_x; break; case no_lives_left: - x = three_lives_x - gap * 2; + x = two_lives_x - gap; } move(y, x); + reset_attr(); + addch(' '); + refresh(); +} + +void display_hit(struct coordinates pac_position, + const struct ghost_type *red_ghost, + const struct ghost_type *pink_ghost, + const struct ghost_type *blue_ghost, + const struct ghost_type *orange_ghost) +{ + struct coordinates ghost_position; + if(red_ghost->reached_pacman) + ghost_position = red_ghost->position; + else if(pink_ghost->reached_pacman) + ghost_position = pink_ghost->position; + else if(blue_ghost->reached_pacman) + ghost_position = blue_ghost->position; + else + ghost_position = orange_ghost->position; + reset_attr(); + move(ghost_position.y, ghost_position.x); + addch(' '); + paint_hit(); + move(pac_position.y, pac_position.x); + addch('X'); + refresh(); +} + +void erase_hit(struct coordinates point) +{ + move(point.y, point.x); + reset_attr(); addch(' '); refresh(); } |