back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/field.c
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-04-18 20:05:03 +0300
committerscratko <m@scratko.xyz>2024-04-18 20:05:03 +0300
commit29afbdf8e26f741ac1d090f2e7704093253f17fc (patch)
tree453dff441936bf712aaa72d27b62f5ca5d0f1bbf /field.c
parentef3844bf2128fa82f20c5995d1fca66fadba2ce3 (diff)
downloadpacman-29afbdf8e26f741ac1d090f2e7704093253f17fc.tar.gz
pacman-29afbdf8e26f741ac1d090f2e7704093253f17fc.tar.bz2
pacman-29afbdf8e26f741ac1d090f2e7704093253f17fc.zip
Release version
Diffstat (limited to 'field.c')
-rw-r--r--field.c94
1 files changed, 71 insertions, 23 deletions
diff --git a/field.c b/field.c
index f0190e9..fd31606 100644
--- a/field.c
+++ b/field.c
@@ -5,6 +5,8 @@
#include <stdlib.h>
#include "color_palette.h"
+enum { frightened_limit = 50 };
+
static const char field_sample[field_height][field_width] = {
{"////////////////////////////"},
{"/1....2.....1//1.....2....1/"},
@@ -35,7 +37,7 @@ static const char field_sample[field_height][field_width] = {
{"/.//////////.//.//////////./"},
{"/1..........2..2..........1/"},
{"////////////////////////////"},
- {" C C Score: "}
+ {" C C Score: /243"}
};
static void copy_field(game_space field)
@@ -55,10 +57,10 @@ game_space get_new_field()
return field;
}
-void clear_field(game_space field)
+void clear_field(game_space *field)
{
- free(field);
- field = NULL;
+ free(*field);
+ *field = NULL;
}
static int field_has_coin(int x, int y)
@@ -107,6 +109,11 @@ void print_field(game_space field)
for(j = 0; j < field_width; ++j) {
symbol = field[i][j];
move(i, j);
+ if(i == field_height-1) {
+ symbol != ' ' ? paint_stats() : reset_attr();
+ addch(symbol);
+ continue;
+ }
if(is_coin_symbol(symbol, j, i) && field_has_coin(j, i)) {
paint_field_element(coin);
symbol == energizer ? addch('*') : addch('.');
@@ -123,11 +130,6 @@ void print_field(game_space field)
paint_field_element(block);
addch(' ');
break;
-#if 0
- case energizer:
- addch('*');
- break;
-#endif
case door:
paint_field_element(door);
addch(' ');
@@ -146,41 +148,79 @@ void print_field(game_space field)
}
}
-void display_character(int y, int x, enum select_character symbol)
+static int is_countdown(int timer, int prison_status)
+{
+ return (timer <= frightened_limit && timer > frightened_limit-10) &&
+ !prison_status;
+}
+
+void display_character(int y, int x, int symbol, int prison_status)
{
move(y, x);
- if(symbol == pac_char)
+ if((enum select_character) symbol == pac_char) {
paint_pac();
- addch(symbol);
+ addch(symbol);
+ refresh();
+ return;
+ }
+ if((enum select_character) symbol != ghost_char)
+ is_countdown(symbol, prison_status) ?
+ printw("%d", frightened_limit - symbol) : addch(ghost_char);
+ else
+ addch(ghost_char);
refresh();
}
void display_ghosts_on_field(struct ghost_type *red_ghost,
struct ghost_type *pink_ghost,
struct ghost_type *blue_ghost,
- struct ghost_type *orange_ghost)
+ struct ghost_type *orange_ghost,
+ int frightened_counter)
{
- 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);
+ paint_ghost(red_ghost->color, frightened_counter,
+ red_ghost->prison_params.active);
+ display_character(red_ghost->position.y, red_ghost->position.x,
+ frightened_counter ? frightened_counter : ghost_char,
+ red_ghost->prison_params.active);
+
+ paint_ghost(pink_ghost->color, frightened_counter,
+ pink_ghost->prison_params.active);
display_character(pink_ghost->position.y, pink_ghost->position.x,
- ghost_char);
- paint_ghost(blue_ghost->color, blue_ghost->frightened_status);
+ frightened_counter ? frightened_counter : ghost_char,
+ pink_ghost->prison_params.active);
+
+ paint_ghost(blue_ghost->color, frightened_counter,
+ blue_ghost->prison_params.active);
display_character(blue_ghost->position.y, blue_ghost->position.x,
- ghost_char);
- paint_ghost(orange_ghost->color, orange_ghost->frightened_status);
+ frightened_counter ? frightened_counter : ghost_char,
+ blue_ghost->prison_params.active);
+
+ paint_ghost(orange_ghost->color, frightened_counter,
+ orange_ghost->prison_params.active);
display_character(orange_ghost->position.y, orange_ghost->position.x,
- ghost_char);
+ frightened_counter ? frightened_counter : ghost_char,
+ orange_ghost->prison_params.active);
}
void display_score(int value)
{
- move(field_height-1, 25);
+ move(field_height-1, 21);
paint_stats();
printw("%d", value);
refresh();
}
+void display_ready()
+{
+ move(17, 11);
+ /*
+ * the same color as pacman
+ */
+ paint_pac();
+ printw("READY!");
+ refresh();
+}
+
void clear_or_revert_symbol(const game_space field, struct coordinates position,
enum select_character character,
const struct queue *eaten_coins)
@@ -193,7 +233,7 @@ void clear_or_revert_symbol(const game_space field, struct coordinates position,
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)) {
+ if(symbol == energizer) {
paint_field_element(coin);
addch('*');
} else {
@@ -295,6 +335,14 @@ void clear_energizer(game_space field, struct coordinates point)
field[y][x] = ' ';
}
+void clear_ready()
+{
+ move(17, 11);
+ reset_attr();
+ printw(" ");
+ refresh();
+}
+
int is_equal_points(struct coordinates first_point, struct coordinates
second_point)
{