X-Git-Url: https://plomlompom.com/repos/index.html?a=blobdiff_plain;ds=sidebyside;f=roguelike.c;h=4e369bc75875e165758d2223cb416281683c50e2;hb=b34c99f3322baff9eefdc567691101c9fd39dc45;hp=396f1f6afa8fabcc3309d1503cf09a500e90f5bb;hpb=705543203cfdd050e05c710d6daa1ff642668aa9;p=plomrogue
diff --git a/roguelike.c b/roguelike.c
index 396f1f6..4e369bc 100644
--- a/roguelike.c
+++ b/roguelike.c
@@ -10,6 +10,7 @@ struct World {
int turn;
char * log;
struct Map * map;
+ struct Monster * monster;
struct Player * player; };
struct KeyBinding {
@@ -32,6 +33,10 @@ struct Player {
int y;
int x; };
+struct Monster {
+ int y;
+ int x; };
+
void draw_with_linebreaks (struct Win *, char *, int);
void draw_text_from_bottom (struct Win *, char *);
void draw_log (struct Win *);
@@ -116,6 +121,7 @@ void draw_map (struct Win * win) {
struct World * world = (struct World *) win->data;
struct Map * map = world->map;
struct Player * player = world->player;
+ struct Monster * monster = world->monster;
char * cells = map->cells;
int width_map_av = map->width - map->offset_x;
int height_map_av = map->height - map->offset_y;
@@ -126,6 +132,8 @@ void draw_map (struct Win * win) {
if (y < height_map_av && x < width_map_av) {
if (z == (map->width * player->y) + player->x)
mvwaddch(win->curses, y, x, '@');
+ else if (z == (map->width * monster->y) + monster->x)
+ mvwaddch(win->curses, y, x, 'M');
else
mvwaddch(win->curses, y, x, cells[z]);
z++; } } } }
@@ -326,7 +334,8 @@ char is_passable (struct World * world, int x, int y) {
// Check if coordinate on (or beyond) map is accessible to movement.
char passable = 0;
if (0 <= x && x < world->map->width && 0 <= y && y < world->map->height)
- if ('.' == world->map->cells[y * world->map->width + x])
+ if ( '.' == world->map->cells[y * world->map->width + x]
+ && (y != world->monster->y || x != world->monster->x))
passable = 1;
return passable; }
@@ -377,9 +386,13 @@ int main () {
struct Map map = init_map();
world.map = ↦
struct Player player;
- player.y = 10;
- player.x = 10;
+ player.y = 16;
+ player.x = 16;
world.player = &player;
+ struct Monster monster;
+ monster.y = 16;
+ monster.x = 80;
+ world.monster = &monster;
WINDOW * screen = initscr();
noecho();