X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Flevel.c;h=d74d52f3cdcedccb7aead388328ccb57b2790b64;hb=7aad8db2edab014c0f750de76bc24bdab63aef2a;hp=b62c73767c2458f44d7e1d4d4c304ff07a82b752;hpb=21d9c58231cf7e1bdd95574e579c9c99a4cd1e9c;p=gbajam22 diff --git a/src/level.c b/src/level.c index b62c737..d74d52f 100644 --- a/src/level.c +++ b/src/level.c @@ -7,7 +7,7 @@ struct level *init_level(const char *descstr) { const char *str, *line; - int i, j, ncols = 0, nrows = 0; + int i, j, x, ncols = 0, nrows = 0; struct level *lvl; struct cell *cell; @@ -41,6 +41,13 @@ struct level *init_level(const char *descstr) lvl->mobs = 0; lvl->items = 0; + lvl->xshift = 0; + x = ncols - 1; + while(x) { + x >>= 1; + lvl->xshift++; + } + str = descstr; cell = lvl->cells; @@ -52,6 +59,12 @@ struct level *init_level(const char *descstr) cell->type = CELL_SOLID; } else { cell->type = CELL_WALK; + switch(*str) { + case 's': + lvl->orgx = j; + lvl->orgy = i; + break; + } } cell++; while(*++str == '\n') str++; @@ -79,6 +92,12 @@ void free_level(struct level *lvl) } } +struct cell *level_cell(struct level *lvl, int cx, int cy) +{ + return lvl->cells + (cy << lvl->xshift) + cx; +} + +/* generated with tools/vistab */ struct {int dx, dy;} visoffs[8][32] = { /* dir 0 */ {{-4,-4}, {4,-4}, {-3,-4}, {3,-4}, {-2,-4}, {2,-4}, {-3,-3}, {3,-3}, {-1,-4}, @@ -125,10 +144,9 @@ void upd_vis(struct level *lvl, struct player *p) lvl->numvis = 0; idx = -1; - theta = p->theta + X_2PI / 16; + theta = X_2PI - p->theta + X_2PI / 16; if(theta >= X_2PI) theta -= X_2PI; - dir = 7 - (theta << 3) / X_2PI; /* p->theta is always [0, 2pi) */ - dbg_drawstr(0, 0, "dir: %d", dir); + dir = (theta << 3) / X_2PI; /* p->theta is always [0, 2pi) */ if(dir < 0 || dir >= 8) { panic(get_pc(), "dir: %d\ntheta: %d.%d (%d)\n", dir, p->theta >> 16, p->theta & 0xffff, p->theta); @@ -138,7 +156,9 @@ void upd_vis(struct level *lvl, struct player *p) x = p->cx + visoffs[dir][idx].dx; y = p->cy + visoffs[dir][idx].dy; cptr = lvl->cells + y * lvl->width + x; - lvl->vis[lvl->numvis++] = cptr; + if(cptr->type != CELL_SOLID) { + lvl->vis[lvl->numvis++] = cptr; + } } while(visoffs[dir][idx].dx | visoffs[dir][idx].dy); }