mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-10-31 19:36:16 +00:00
nilrider:: refactored mapchar and get_xy
This commit is contained in:
parent
2bd079003a
commit
dcf0d8af9c
@ -244,6 +244,23 @@ void level::init() {
|
||||
init_plan();
|
||||
}
|
||||
|
||||
xy_float level::get_xy_f(hyperpoint h) {
|
||||
int tY = isize(map_tiles);
|
||||
int tX = isize(map_tiles[0]);
|
||||
ld rtx = ilerp(minx, maxx, h[0]) * tX;
|
||||
ld rty = ilerp(miny, maxy, h[1]) * tY;
|
||||
return {rtx, rty};
|
||||
}
|
||||
|
||||
char level::mapchar(xy_int p) {
|
||||
auto x = p.first;
|
||||
auto y = p.second;
|
||||
int tY = isize(map_tiles);
|
||||
int tX = isize(map_tiles[0]);
|
||||
if(x < 0 || y < 0 || x >= tX || y >= tY) return '!';
|
||||
return map_tiles[y][x];
|
||||
}
|
||||
|
||||
/* convert ASCII map coordinates to Heisenberg coordinates */
|
||||
hyperpoint level::mappt(ld x, ld y, int s) {
|
||||
int tY = isize(map_tiles);
|
||||
|
@ -59,6 +59,10 @@ struct plan_replay {
|
||||
plan_t plan;
|
||||
};
|
||||
|
||||
using xy_float = pair<ld, ld>;
|
||||
using xy_int = pair<int, int>;
|
||||
inline xy_float pfloor(xy_int p) { return {floor(p.first), floor(p.second)}; }
|
||||
|
||||
struct level {
|
||||
string name;
|
||||
char hotkey;
|
||||
@ -123,6 +127,12 @@ struct level {
|
||||
void compute_plan_transform();
|
||||
bool handle_planning(int sym, int uni);
|
||||
void solve();
|
||||
|
||||
xy_float get_xy_f(hyperpoint h);
|
||||
xy_int get_xy_i(hyperpoint h) { return pfloor(get_xy_f(h)); }
|
||||
char mapchar(xy_int p);
|
||||
char mapchar(xy_float p) { return mapchar(pfloor(p)); }
|
||||
char mapchar(hyperpoint h) { return mapchar(pfloor(get_xy_f(h))); }
|
||||
};
|
||||
|
||||
/** ticks per second */
|
||||
|
@ -47,8 +47,6 @@ void level::solve() {
|
||||
|
||||
get_id(0, 0);
|
||||
transmatrix Rstart = gpushxto0(vertices[0].where);
|
||||
int tY = isize(map_tiles);
|
||||
int tX = isize(map_tiles[0]);
|
||||
|
||||
for(int id=0; id<isize(vertices); id++) {
|
||||
auto& v = vertices[id];
|
||||
@ -58,13 +56,9 @@ void level::solve() {
|
||||
auto y0 = v.y;
|
||||
auto point0 = v.where;
|
||||
|
||||
ld rtx0 = ilerp(minx, maxx, point0[0]) * tX;
|
||||
ld rty0 = ilerp(miny, maxy, point0[1]) * tY;
|
||||
xy_float f0 = get_xy_f(point0);
|
||||
|
||||
int tx = floor(rtx0);
|
||||
int ty = floor(rty0);
|
||||
|
||||
char ch = map_tiles[ty][tx];
|
||||
char ch = mapchar(f0);
|
||||
v.goal = ch == '*';
|
||||
v.zval = (Rstart * point0)[2];
|
||||
|
||||
@ -78,18 +72,16 @@ void level::solve() {
|
||||
hyperpoint point1 = getpt(x1, y1);
|
||||
e.zval1 = (Rstart * point1)[2];
|
||||
|
||||
ld rtx1 = ilerp(minx, maxx, point1[0]) * tX;
|
||||
ld rty1 = ilerp(miny, maxy, point1[1]) * tY;
|
||||
xy_float f1 = get_xy_f(point1);
|
||||
|
||||
int txmin = floor(min(rtx0, rtx1) - 1e-3);
|
||||
int txmax = floor(max(rtx0, rtx1) + 1e-3);
|
||||
int tymin = floor(min(rty0, rty1) - 1e-3);
|
||||
int tymax = floor(max(rty0, rty1) + 1e-3);
|
||||
if(txmin < 0 || tymin < 0 || txmax >= tX || tymax >= tY) continue;
|
||||
int txmin = floor(min(f0.first, f1.first) - 1e-3);
|
||||
int txmax = floor(max(f0.first, f1.first) + 1e-3);
|
||||
int tymin = floor(min(f0.second, f1.second) - 1e-3);
|
||||
int tymax = floor(max(f0.second, f1.second) + 1e-3);
|
||||
bool bad = false;
|
||||
for(int tyi=tymin; tyi<=tymax; tyi++)
|
||||
for(int txi=txmin; txi<=txmax; txi++)
|
||||
if(among(map_tiles[tyi][txi], '!', 'r')) bad = true;
|
||||
if(among(mapchar(xy_int{txi, tyi}), '!', 'r')) bad = true;
|
||||
if(bad) continue;
|
||||
|
||||
hyperpoint rpoint = gpushxto0(point1) * point0;
|
||||
|
@ -71,19 +71,13 @@ void timestamp::draw_unilcycle(const shiftmatrix& V) {
|
||||
bool tick_debug = false;
|
||||
|
||||
bool timestamp::collect(level *lev) {
|
||||
int tY = isize(lev->map_tiles);
|
||||
int tX = isize(lev->map_tiles[0]);
|
||||
// println(hlog, where, tie(lev->minx, lev->miny), tie(lev->maxx, lev->maxy));
|
||||
int x = floor(ilerp(lev->minx, lev->maxx, where[0]) * tX);
|
||||
int y = floor(ilerp(lev->miny, lev->maxy, where[1]) * tY);
|
||||
if(x < 0 || y < 0 || x >= tX || y >= tY)
|
||||
return false;
|
||||
char ch = lev->map_tiles[y][x];
|
||||
auto xy = lev->get_xy_i(where);
|
||||
char ch = lev->mapchar(xy);
|
||||
if(ch == 'r' || ch == '!') return false;
|
||||
if(ch == '*') {
|
||||
for(int i=0; i<isize(lev->triangles); i++) {
|
||||
auto& t = lev->triangles[i];
|
||||
if(t.x == x && t.y == y) collected_triangles |= (1<<i);
|
||||
if(t.x == xy.first && t.y == xy.second) collected_triangles |= (1<<i);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user