maplayer::maplayer(node source) { node tilesrc = nx::nodes["Map"]["Tile"][source["info"]["tS"] + ".img"]; node objsrc = nx::nodes["Map"]["Obj"]; for (node layernode = source.begin(); layernode != source.end(); layernode++) { if (layernode.name() == "obj") { for (node objnode = layernode.begin(); objnode != layernode.end(); ++objnode) { vector2d position = vector2d(objnode["x"], objnode["y"]); node bmpnode = objsrc[objnode["oS"] + ".img"][objnode["l0"]][objnode["l1"]][objnode["l2"]]; int z = objnode["z"]; objs[z].push_back(sprite(animation(bmpnode), position, true, objnode.resolve("f").get_bool())); } } else if (layernode.name() == "tile") { for (node tilenode = layernode.begin(); tilenode != layernode.end(); ++tilenode) { node bmpnode = tilesrc[tilenode["u"]][to_string(tilenode["no"].get_integer())]; tile toadd; toadd.pos = vector2d(tilenode["x"], tilenode["y"]); toadd.txt = texture(bmpnode); int z = bmpnode["z"].istype(integernode) ? bmpnode["z"] : tilenode["zM"]; tiles[z].push_back(toadd); } } } }
charset::charset(node src) { for (node sub = src.begin(); sub != src.end(); sub++) { char c = sub.name()[0]; if (c == '\\') c = '/'; characters[c] = texture(sub); } }
Charset::Charset(node src, CharsetAlignment alg) { for (node sub = src.begin(); sub != src.end(); ++sub) { if (sub.data_type() == node::type::bitmap) { int8_t c = sub.name()[0]; if (c == '\\') { c = '/'; } chars.add(c, new Texture(sub)); } } alignment = alg; }
mapbackgrounds::mapbackgrounds(node bgnodes, vector2d mapwalls, vector2d mapborders) { node back = nx::nodes["Back"]["Back"]; for (node backnode = bgnodes.begin(); backnode != bgnodes.end(); ++backnode) { if (!backnode["bS"].get_string().empty()) { if (backnode["front"].get_bool()) { foregrounds.push_back(background(backnode, back, mapwalls, mapborders)); } else { backgrounds.push_back(background(backnode, back, mapwalls, mapborders)); } } } }
footholdtree::footholdtree(node source) { for (node basef = source.begin(); basef != source.end(); ++basef) { for (node midf = basef.begin(); midf != basef.end(); ++midf) { map<short, short> platform; for (node lastf = midf.begin(); lastf != midf.end(); ++lastf) { short id = static_cast<short>(stoi(lastf.name())); footholds[id] = struct foothold(); footholds[id].id = id; footholds[id].prev = static_cast<short>(lastf["prev"]); footholds[id].next = static_cast<short>(lastf["next"]); footholds[id].horizontal = vector2d(static_cast<int>(lastf["x1"]), static_cast<int>(lastf["x2"])); footholds[id].vertical = vector2d(static_cast<int>(lastf["y1"]), static_cast<int>(lastf["y2"])); if (footholds[id].prev == 0) { edgesl.push_back(id); } else if (footholds[id].next == 0) { edgesr.push_back(id); } /*if (footholds[id].isfloor()) { short y = footholds[id].vertical.x(); for (short i = footholds[id].horizontal.x(); i <= footholds[id].horizontal.y(); i++) { platform[i] = y; } } else { vector2d slope = footholds[id].vertical; short distance = footholds[id].horizontal.y() - footholds[id].horizontal.x(); if (slope.x() > slope.y()) { float step = static_cast<float>((slope.x() - slope.y())) / distance; for (short i = footholds[id].horizontal.x(); i <= footholds[id].horizontal.y(); i++) { platform[i] = slope.x() - static_cast<int>(i * step); } } else { float step = static_cast<float>((slope.y() - slope.x())) / distance; for (short i = footholds[id].horizontal.x(); i <= footholds[id].horizontal.y(); i++) { platform[i] = slope.x() + static_cast<int>(i * step); } } }*/ } platforms.push_back(platform); } } lowestg = -65536; for (vector<map<short, short>>::iterator pfit = platforms.begin(); pfit != platforms.end(); ++pfit) { for (map<short, short>::iterator yit = pfit->begin(); yit != pfit->end(); ++yit) { if (yit->second > lowestg) { lowestg = yit->second; } } } }
Footholdtree::Footholdtree(node src) { for (node basef = src.begin(); basef != src.end(); ++basef) { int8_t layer = static_cast<int8_t>(stoi(basef.name())); for (node midf = basef.begin(); midf != basef.end(); ++midf) { for (node lastf = midf.begin(); lastf != midf.end(); ++lastf) { uint16_t id = stoi(lastf.name()); footholds[id] = Foothold(id, layer, lastf); if (footholds[id].getprev() == 0) { edgesl.push_back(id); } else if (footholds[id].getnext() == 0) { edgesr.push_back(id); } } } } int32_t leftw = 65536; for (vector<uint16_t>::iterator fhit = edgesl.begin(); fhit != edgesl.end(); ++fhit) { int32_t lit = footholds[*fhit].getl(); if (lit < leftw) { leftw = lit; } } int32_t rightw = -65536; for (vector<uint16_t>::iterator fhit = edgesr.begin(); fhit != edgesr.end(); ++fhit) { int32_t rit = footholds[*fhit].getr(); if (rit > rightw) { rightw = rit; } } walls = vector2d<int32_t>(leftw + 25, rightw - 25); int32_t botb = -65536; for (map<uint16_t, Foothold>::iterator fhit = footholds.begin(); fhit != footholds.end(); ++fhit) { int32_t btit = fhit->second.getb(); if (btit > botb) { botb = btit; } } int32_t topb = 65536; for (map<uint16_t, Foothold>::iterator fhit = footholds.begin(); fhit != footholds.end(); ++fhit) { int32_t tpit = fhit->second.gett(); if (tpit < topb) { topb = tpit; } } borders = vector2d<int32_t>(topb - 400, botb + 400); }