home
·
contact
·
privacy
projects
/
plomrogue
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7055432
)
Added monster. Doesn't do much; only blocks the way so far.
author
Christian Heller
<c.heller@plomlompom.de>
Thu, 16 May 2013 00:49:18 +0000
(
02:49
+0200)
committer
Christian Heller
<c.heller@plomlompom.de>
Thu, 16 May 2013 00:49:18 +0000
(
02:49
+0200)
roguelike.c
patch
|
blob
|
history
diff --git
a/roguelike.c
b/roguelike.c
index 396f1f6afa8fabcc3309d1503cf09a500e90f5bb..4e369bc75875e165758d2223cb416281683c50e2 100644
(file)
--- a/
roguelike.c
+++ b/
roguelike.c
@@
-10,6
+10,7
@@
struct World {
int turn;
char * log;
struct Map * map;
int turn;
char * log;
struct Map * map;
+ struct Monster * monster;
struct Player * player; };
struct KeyBinding {
struct Player * player; };
struct KeyBinding {
@@
-32,6
+33,10
@@
struct Player {
int y;
int x; };
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 *);
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 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;
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, '@');
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++; } } } }
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)
// 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; }
passable = 1;
return passable; }
@@
-377,9
+386,13
@@
int main () {
struct Map map = init_map();
world.map = ↦
struct Player player;
struct Map map = init_map();
world.map = ↦
struct Player player;
- player.y = 1
0
;
- player.x = 1
0
;
+ player.y = 1
6
;
+ player.x = 1
6
;
world.player = &player;
world.player = &player;
+ struct Monster monster;
+ monster.y = 16;
+ monster.x = 80;
+ world.monster = &monster;
WINDOW * screen = initscr();
noecho();
WINDOW * screen = initscr();
noecho();