#include "debug.h"
#include "level.h"
#include "player.h"
+#include "xgl.h"
struct level *init_level(const char *descstr)
{
struct {int dx, dy;} visoffs[8][32] = {
/* dir 0 */
- {{-2,-4}, {2,-4}, {-1,-4}, {1,-4}, {0,-4}, {-1,-3}, {1,-3}, {0,-3}, {-1,-2},
- {1,-2}, {0,-2}, {0,-1}, {0,0}},
+ {{-4,-4}, {4,-4}, {-3,-4}, {3,-4}, {-2,-4}, {2,-4}, {-3,-3}, {3,-3}, {-1,-4},
+ {1,-4}, {0,-4}, {-2,-3}, {2,-3}, {-1,-3}, {1,-3}, {0,-3}, {-2,-2}, {2,-2},
+ {-1,-2}, {1,-2}, {0,-2}, {-1,-1}, {1,-1}, {0,-1}, {0,0}},
/* dir 1 */
- {{4,-4}, {3,-4}, {4,-3}, {2,-4}, {4,-2}, {3,-3}, {2,-3}, {3,-2}, {1,-3},
- {3,-1}, {2,-2}, {1,-2}, {2,-1}, {1,-1}, {0,0}},
+ {{4,-4}, {3,-4}, {4,-3}, {2,-4}, {4,-2}, {3,-3}, {1,-4}, {4,-1}, {0,-4},
+ {4,0}, {2,-3}, {3,-2}, {1,-3}, {3,-1}, {0,-3}, {3,0}, {2,-2}, {1,-2},
+ {2,-1}, {0,-2}, {2,0}, {1,-1}, {0,-1}, {1,0}, {0,0}},
/* dir 2 */
- {{4,-2}, {4,2}, {4,-1}, {4,1}, {4,0}, {3,-1}, {3,1}, {3,0}, {2,-1}, {2,1},
- {2,0}, {1,0}, {0,0}},
+ {{4,-4}, {4,4}, {4,-3}, {4,3}, {4,-2}, {4,2}, {3,-3}, {3,3}, {4,-1}, {4,1},
+ {4,0}, {3,-2}, {3,2}, {3,-1}, {3,1}, {3,0}, {2,-2}, {2,2}, {2,-1}, {2,1},
+ {2,0}, {1,-1}, {1,1}, {1,0}, {0,0}},
/* dir 3 */
- {{4,4}, {4,3}, {3,4}, {4,2}, {2,4}, {3,3}, {3,2}, {2,3}, {3,1}, {1,3},
- {2,2}, {2,1}, {1,2}, {1,1}, {0,0}},
+ {{4,4}, {4,3}, {3,4}, {4,2}, {2,4}, {3,3}, {4,1}, {1,4}, {4,0}, {0,4},
+ {3,2}, {2,3}, {3,1}, {1,3}, {3,0}, {0,3}, {2,2}, {2,1}, {1,2}, {2,0},
+ {0,2}, {1,1}, {1,0}, {0,1}, {0,0}},
/* dir 4 */
- {{-2,4}, {2,4}, {-1,4}, {1,4}, {0,4}, {-1,3}, {1,3}, {0,3}, {-1,2}, {1,2},
- {0,2}, {0,1}, {0,0}},
+ {{-4,4}, {4,4}, {-3,4}, {3,4}, {-2,4}, {2,4}, {-3,3}, {3,3}, {-1,4}, {1,4},
+ {0,4}, {-2,3}, {2,3}, {-1,3}, {1,3}, {0,3}, {-2,2}, {2,2}, {-1,2}, {1,2},
+ {0,2}, {-1,1}, {1,1}, {0,1}, {0,0}},
/* dir 5 */
- {{-4,4}, {-4,3}, {-3,4}, {-4,2}, {-2,4}, {-3,3}, {-3,2}, {-2,3}, {-3,1},
- {-1,3}, {-2,2}, {-2,1}, {-1,2}, {-1,1}, {0,0}},
+ {{-4,4}, {-4,3}, {-3,4}, {-4,2}, {-2,4}, {-3,3}, {-4,1}, {-1,4}, {-4,0},
+ {0,4}, {-3,2}, {-2,3}, {-3,1}, {-1,3}, {-3,0}, {0,3}, {-2,2}, {-2,1},
+ {-1,2}, {-2,0}, {0,2}, {-1,1}, {-1,0}, {0,1}, {0,0}},
/* dir 6 */
- {{-4,-2}, {-4,2}, {-4,-1}, {-4,1}, {-4,0}, {-3,-1}, {-3,1}, {-3,0}, {-2,-1},
- {-2,1}, {-2,0}, {-1,0}, {0,0}},
+ {{-4,-4}, {-4,4}, {-4,-3}, {-4,3}, {-4,-2}, {-4,2}, {-3,-3}, {-3,3}, {-4,-1},
+ {-4,1}, {-4,0}, {-3,-2}, {-3,2}, {-3,-1}, {-3,1}, {-3,0}, {-2,-2}, {-2,2},
+ {-2,-1}, {-2,1}, {-2,0}, {-1,-1}, {-1,1}, {-1,0}, {0,0}},
/* dir 7 */
- {{-4,-4}, {-3,-4}, {-4,-3}, {-2,-4}, {-4,-2}, {-3,-3}, {-2,-3}, {-3,-2},
- {-1,-3}, {-3,-1}, {-2,-2}, {-1,-2}, {-2,-1}, {-1,-1}, {0,0}}
+ {{-4,-4}, {-3,-4}, {-4,-3}, {-2,-4}, {-4,-2}, {-3,-3}, {-1,-4}, {-4,-1},
+ {0,-4}, {-4,0}, {-2,-3}, {-3,-2}, {-1,-3}, {-3,-1}, {0,-3}, {-3,0}, {-2,-2},
+ {-1,-2}, {-2,-1}, {0,-2}, {-2,0}, {-1,-1}, {0,-1}, {-1,0}, {0,0}}
};
void upd_vis(struct level *lvl, struct player *p)
int dir, idx;
int x, y;
struct cell *cptr;
+ int32_t theta;
pos_to_cell(lvl, p->x, p->y, &p->cx, &p->cy);
lvl->numvis = 0;
idx = -1;
- dir = 0; /* TODO use p->theta */
+ theta = 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);
+ if(dir < 0 || dir >= 8) {
+ panic(get_pc(), "dir: %d\ntheta: %d.%d (%d)\n", dir, p->theta >> 16,
+ p->theta & 0xffff, p->theta);
+ }
do {
idx++;
x = p->cx + visoffs[dir][idx].dx;