namespace nilrider { void level::init() { if(initialized) return; initialized = true; unil_texture = new texture::texture_data; auto& tex = *unil_texture; real_minx = HUGE_VAL; real_miny = HUGE_VAL; real_maxx = -HUGE_VAL; real_maxy = -HUGE_VAL; if(flags & nrlPolar) scale = 1; else scale = abs(maxx - minx) / isize(map_tiles[0]); println(hlog, "SCALE IS ", this->scale); int tY = isize(map_tiles); int tX = isize(map_tiles[0]); tex.twidth = tex.tx = tX * 64; tex.theight = tex.ty = tY * 64; tex.stretched = false; tex.strx = tex.tx; tex.stry = tex.ty; tex.base_x = 0; tex.base_y = 0; tex.whitetexture(); println(hlog, "tX=", tX, " tY=", tY, " tex=", tex.tx, "x", tex.ty); for(int y=0; y bar + M_PI) h[0] -= 2 * M_PI; } 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); int tX = isize(map_tiles[0]); x /= s; y /= s; hyperpoint h; h[0] = lerp(minx, maxx, x / tX); h[1] = lerp(miny, maxy, y / tY); if(flags & nrlPolar) tie(h[0], h[1]) = make_pair(h[1] * sin(h[0]), h[1] * cos(h[0])); h[2] = surface(h); h[3] = 1; return h; }; /* plan.emplace_back(start.where, hpxy(0, 1)); plan.emplace_back(mappt(4.5, 10.5), hpxy(1, 1)); plan.emplace_back(mappt(0.01, 3, 1), hpxy(0, -2)); plan.emplace_back(mappt(2, 3.99, 1), hpxy(4, 0)); plan.emplace_back(mappt(42, 3.99, 1), hpxy(4, 0)); */ void level::init_plan() { plan.emplace_back(start.where, hpxy(0, -1)); plan.emplace_back(mappt(6.8, 10.2, 1), hpxy(1.5, -1.5)); plan.emplace_back(mappt(10.5, 10.5, 1), hpxy(1.5, 1.5)); plan.emplace_back(mappt(10.5, 4.5, 1), hpxy(-1.5, 1.5)); plan.emplace_back(mappt(4.5, 4.5, 1), hpxy(-1.5, 1.5)); plan.emplace_back(mappt(4.5, 2, 1), hpxy(1.5, 0.5)); plan.emplace_back(mappt(10.5, 2, 1), hpxy(1.5, -0.5)); plan.emplace_back(mappt(10.5, 4.5, 1), hpxy(-2, 0)); plan.emplace_back(mappt(6.5, 6.5, 1), hpxy(-1.5, -1.5)); plan.emplace_back(mappt(4.5, 10.5, 1), hpxy(1.5, -1.5)); plan.emplace_back(mappt(10.5, 9.5, 1), hpxy(1.5, 1.5)); /* plan.emplace_back(mappt(0.01, 3, 1), hpxy(0, -2)); plan.emplace_back(mappt(2, 3.99, 1), hpxy(4, 0)); plan.emplace_back(mappt(42, 3.99, 1), hpxy(4, 0)); */ current = start; timer = 0; } ld level::safe_alt(hyperpoint h, ld mul, ld mulx) { ld maxv = 0; for(int x: {-1, 0, 1}) for(int y: {-1, 0, 1}) { hyperpoint c = sym_to_heis(point31(x*.5*scale*mulx, y*.5*scale*mulx, 0)); hyperpoint j = rgpushxto0(h) * c; maxv = max(maxv, mul * (surface(j) - j[2])); } return maxv; } void level::draw_level(const shiftmatrix& V) { int id = 0; for(auto& t: triangles) { bool gotit = current.collected_triangles & Flag(id); id++; if(!gotit) { for(int i=0; i<6; i++) { auto &poly = queuepoly(V * rgpushxto0(t.where) * cpush(2, abs(0.2 * sin(timer * 5))), shMini[i], t.colors[i]); poly.tinf = &floor_texture_vertices[cgi.shFloor.id]; ensure_vertex_number(*poly.tinf, poly.cnt); } } } if(true) { auto& poly = queuepoly(V, shCastle, 0xC02020FF); poly.tinf = &castle_tinf; castle_tinf.texture_id = castle_texture->textureid; } for(auto st: statues) queuepoly(V * st.T, *st.shape, st.color); queuepoly(V, shField, 0xFFFF00FF); auto& poly = queuepoly(V, shFloor, 0xFFFFFFFF); // 0xFFFFFFFF); poly.tinf = &uniltinf; uniltinf.texture_id = unil_texture->textureid; } }