1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-23 21:07:17 +00:00

nilrider:: levellines

This commit is contained in:
Zeno Rogue 2022-05-09 10:02:21 +02:00
parent d4957fd56b
commit 17a18d7579
3 changed files with 59 additions and 17 deletions

View File

@ -8,15 +8,22 @@ void level::init_textures() {
int tY = isize(map_tiles);
int tX = isize(map_tiles[0]);
for(int stepped: {0, 1}) {
transmatrix T = gpushxto0(new_levellines_for);
auto& target = stepped ? unil_texture_stepped : unil_texture;
if(target) return;
for(int which: {0, 1, 2}) {
target = new texture::texture_data;
bool stepped = which == 1;
bool levels = which == 2;
auto& target = stepped ? unil_texture_stepped : levels ? unil_texture_levels : unil_texture;
if(target && !(levels && levellines_for != new_levellines_for)) continue;
bool regen = !target;
if(regen) target = new texture::texture_data;
auto& tex = *target;
if(regen) {
tex.twidth = tex.tx = tX * texture_density;
tex.theight = tex.ty = tY * texture_density;
tex.stretched = false;
@ -25,6 +32,7 @@ void level::init_textures() {
tex.base_x = 0;
tex.base_y = 0;
tex.whitetexture();
}
auto getpix = [&] (int x, int y) {
int px = x / pixel_per_block;
@ -44,6 +52,12 @@ void level::init_textures() {
if(!stepped) {
char c = getpix(x / subpixels, y / subpixels);
col = bcols[c];
if(levels && new_levellines_for[3]) {
hyperpoint h = T * mappt(x, y, texture_density);
ld z = h[2] - sym_to_heis_bonus(h);
if(z > 0) col = gradient(col, 0xFFFF0000, 0, z - floor(z), 4);
if(z < 0) col = gradient(col, 0xFF0000FF, 0, -z - floor(-z), 4);
}
}
else {
int mx = x % stepdiv;
@ -69,10 +83,12 @@ void level::init_textures() {
}
tex.get_texture_pixel(x, y) = col;
tex.get_texture_pixel(x, y) |= 0xFF000000;
if(!levels)
tex.get_texture_pixel(x, y) ^= hrand(0x1000000) & 0xF0F0F;
}
tex.loadTextureGL();
}
levellines_for = new_levellines_for;
}
void level::init_shapes() {
@ -330,6 +346,8 @@ void level::init() {
scale = abs(maxx - minx) / isize(map_tiles[0]);
println(hlog, "SCALE IS ", this->scale);
levellines_for = new_levellines_for = C0;
if(1) {
int tY = isize(map_tiles);
int tX = isize(map_tiles[0]);

View File

@ -116,10 +116,19 @@ struct level {
/** the texture data used for the ground in the stepped mode */
texture::texture_data *unil_texture_stepped;
/** the texture data used for the ground with level lines */
texture::texture_data *unil_texture_levels;
/** the texture used for the ground */
basic_textureinfo uniltinf;
/** the texture used for the ground */
/** currently used point for levellines -- levellines[3]==0 means none */
hyperpoint levellines_for;
/** requested point for levellines (texture redrawn in init_textures) */
hyperpoint new_levellines_for;
/** the texture used for the castles */
basic_textureinfo castle_tinf;
/** the texture used for the ground in the stepped mode*/

View File

@ -74,7 +74,7 @@ ld closest_t;
char planmode = 'p';
vector<pair<char, string> > buttons = {
{'p', "pan"}, {'a', "add"}, {'m', "move"}, {'i', "insert"}, {'d', "delete"}
{'p', "pan"}, {'a', "add"}, {'m', "move"}, {'i', "insert"}, {'d', "delete"}, {'l', "levels"}
};
bool recompute_plan_transform = true;
@ -126,7 +126,7 @@ void level::draw_planning_screen() {
/* draw the map */
auto& p = queuepolyat(T, shPlanFloor, 0xFFFFFFFF, PPR::FLOOR);
p.tinf = &uniltinf;
uniltinf.texture_id = unil_texture->textureid;
uniltinf.texture_id = unil_texture_levels->textureid;
auto draw_sq = [&] (hyperpoint h, color_t col, PPR prio) {
curvepoint(hpxy(h[0]+box, h[1]+box));
@ -143,6 +143,9 @@ void level::draw_planning_screen() {
queuecurve(T, col, 0, prio);
};
if(levellines_for[3])
draw_sq(levellines_for, 0xFFC0FFFF, PPR::ITEM);
/* draw the plan */
for(auto& pp: plan) {
draw_sq(pp.at - pp.vel, 0xFF8080FF, PPR::ITEM);
@ -210,7 +213,10 @@ bool level::handle_planning(int sym, int uni) {
plan_transform.T = atscreenpos(mousex, mousey, 1) * inverse(atscreenpos(mousex, mousey, 1.2)) * plan_transform.T;
return true;
}
for(auto& b: buttons) if(uni == b.first) { planmode = uni; return true; }
for(auto& b: buttons) if(uni == b.first) {
if(uni == 'l' && planmode == 'l') new_levellines_for[3] = 0;
planmode = uni; return true;
}
auto clean_history_to = [&] (int i) {
while(history.size() > 1 && history.back().t > i) history.pop_back();
};
@ -291,6 +297,15 @@ bool level::handle_planning(int sym, int uni) {
}
return false;
}
case 'l': {
if(uni == '-') {
new_levellines_for = mousept;
new_levellines_for[2] = surface(new_levellines_for);
holdmouse = true;
return true;
}
return false;
}
default:
return false;
}