Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Levels  (Read 1147 times)

0 Members and 1 Guest are viewing this topic.

spoty76

  • Newbie
  • *
  • Posts: 21
    • View Profile
Levels
« on: September 16, 2017, 02:50:57 pm »
Hello, I'm using tiled map editor and tinyxml, the main level is loaded in firstly in int main as lvl.LoadFromFile("mainmap.tmx");
I want somehow to load another map (like another level), when I touch the object for instance, but if I do like that:\ in class player
if (obj[i].name == "poison")
                                {
                                        if (a == false)
                                        {
                                                a = true;
                                        }
                                }
And after window poll event:
if (p.a == true)
                {
                        lvl.LoadFromFile("mainmap2.tmx");
                        p.a = false;
                }
The second map loads, but the first one doesn't disappear,
I need somehow to realize something that can delete the first map, or load even new main.cpp file or whatever, but I need to make levels.

I'm using a specific level code for tiled map editor:
#ifndef LEVEL_H
#define LEVEL_H

#include <string>
#include <vector>
#include <map>
#include <SFML/Graphics.hpp>
#include <iostream>
#include "tinyxml\tinyxml.h"

struct Object
{
        int GetPropertyInt(std::string name);//&#1085;&#1086;&#1084;&#1077;&#1088; &#1089;&#1074;&#1086;&#1081;&#1089;&#1090;&#1074;&#1072; &#1086;&#1073;&#1098;&#1077;&#1082;&#1090;&#1072; &#1074; &#1085;&#1072;&#1096;&#1077;&#1084; &#1089;&#1087;&#1080;&#1089;&#1082;&#1077;
        float GetPropertyFloat(std::string name);
        std::string GetPropertyString(std::string name);

        std::string name;//&#1086;&#1073;&#1098;&#1103;&#1074;&#1080;&#1083;&#1080; &#1087;&#1077;&#1088;&#1077;&#1084;&#1077;&#1085;&#1085;&#1091;&#1102; name &#1090;&#1080;&#1087;&#1072; string
        std::string type;//&#1072; &#1079;&#1076;&#1077;&#1089;&#1100; &#1087;&#1077;&#1088;&#1077;&#1084;&#1077;&#1085;&#1085;&#1091;&#1102; type &#1090;&#1080;&#1087;&#1072; string
        sf::Rect<float> rect;//&#1090;&#1080;&#1087; Rect &#1089; &#1085;&#1077;&#1094;&#1077;&#1083;&#1099;&#1084;&#1080; &#1079;&#1085;&#1072;&#1095;&#1077;&#1085;&#1080;&#1103;&#1084;&#1080;
        std::map<std::string, std::string> properties;//&#1089;&#1086;&#1079;&#1076;&#1072;&#1105;&#1084; &#1072;&#1089;&#1089;&#1086;&#1094;&#1080;&#1072;&#1090;&#1080;&#1085;&#1099;&#1081; &#1084;&#1072;&#1089;&#1089;&#1080;&#1074;. &#1082;&#1083;&#1102;&#1095; - &#1089;&#1090;&#1088;&#1086;&#1082;&#1086;&#1074;&#1099;&#1081; &#1090;&#1080;&#1087;, &#1079;&#1085;&#1072;&#1095;&#1077;&#1085;&#1080;&#1077; - &#1089;&#1090;&#1088;&#1086;&#1082;&#1086;&#1074;&#1099;&#1081;

        sf::Sprite sprite;//&#1086;&#1073;&#1098;&#1103;&#1074;&#1080;&#1083;&#1080; &#1089;&#1087;&#1088;&#1072;&#1081;&#1090;
};

struct Layer//&#1089;&#1083;&#1086;&#1080;
{
        int opacity;//&#1085;&#1077;&#1087;&#1088;&#1086;&#1079;&#1088;&#1072;&#1095;&#1085;&#1086;&#1089;&#1090;&#1100; &#1089;&#1083;&#1086;&#1103;
        std::vector<sf::Sprite> tiles;//&#1079;&#1072;&#1082;&#1080;&#1076;&#1099;&#1074;&#1072;&#1077;&#1084; &#1074; &#1074;&#1077;&#1082;&#1090;&#1086;&#1088; &#1090;&#1072;&#1081;&#1083;&#1099;
};

class Level//&#1075;&#1083;&#1072;&#1074;&#1085;&#1099;&#1081; &#1082;&#1083;&#1072;&#1089;&#1089; - &#1091;&#1088;&#1086;&#1074;&#1077;&#1085;&#1100;
{
public:
        bool LoadFromFile(std::string filename);//&#1074;&#1086;&#1079;&#1074;&#1088;&#1072;&#1097;&#1072;&#1077;&#1090; false &#1077;&#1089;&#1083;&#1080; &#1085;&#1077; &#1087;&#1086;&#1083;&#1091;&#1095;&#1080;&#1083;&#1086;&#1089;&#1100; &#1079;&#1072;&#1075;&#1088;&#1091;&#1079;&#1080;&#1090;&#1100;
        Object GetObject(std::string name);
        std::vector<Object> GetObjects(std::string name);//&#1074;&#1099;&#1076;&#1072;&#1077;&#1084; &#1086;&#1073;&#1098;&#1077;&#1082;&#1090; &#1074; &#1085;&#1072;&#1096; &#1091;&#1088;&#1086;&#1074;&#1077;&#1085;&#1100;
        std::vector<Object> GetAllObjects();//&#1074;&#1099;&#1076;&#1072;&#1077;&#1084; &#1074;&#1089;&#1077; &#1086;&#1073;&#1098;&#1077;&#1082;&#1090;&#1099; &#1074; &#1085;&#1072;&#1096; &#1091;&#1088;&#1086;&#1074;&#1077;&#1085;&#1100;
        void Draw(sf::RenderWindow &window);//&#1088;&#1080;&#1089;&#1091;&#1077;&#1084; &#1074; &#1086;&#1082;&#1085;&#1086;
        sf::Vector2i GetTileSize();//&#1087;&#1086;&#1083;&#1091;&#1095;&#1072;&#1077;&#1084; &#1088;&#1072;&#1079;&#1084;&#1077;&#1088; &#1090;&#1072;&#1081;&#1083;&#1072;

private:
        int width, height, tileWidth, tileHeight;//&#1074; tmx &#1092;&#1072;&#1081;&#1083;&#1077; width height &#1074; &#1085;&#1072;&#1095;&#1072;&#1083;&#1077;,&#1079;&#1072;&#1090;&#1077;&#1084; &#1088;&#1072;&#1079;&#1084;&#1077;&#1088; &#1090;&#1072;&#1081;&#1083;&#1072;
        int firstTileID;//&#1087;&#1086;&#1083;&#1091;&#1095;&#1072;&#1077;&#1084; &#1072;&#1081;&#1076;&#1080; &#1087;&#1077;&#1088;&#1074;&#1086;&#1075;&#1086; &#1090;&#1072;&#1081;&#1083;&#1072;
        sf::Rect<float> drawingBounds;//&#1088;&#1072;&#1079;&#1084;&#1077;&#1088; &#1095;&#1072;&#1089;&#1090;&#1080; &#1082;&#1072;&#1088;&#1090;&#1099; &#1082;&#1086;&#1090;&#1086;&#1088;&#1091;&#1102; &#1088;&#1080;&#1089;&#1091;&#1077;&#1084;
        sf::Texture tilesetImage;//&#1090;&#1077;&#1082;&#1089;&#1090;&#1091;&#1088;&#1072; &#1082;&#1072;&#1088;&#1090;&#1099;
        std::vector<Object> objects;//&#1084;&#1072;&#1089;&#1089;&#1080;&#1074; &#1090;&#1080;&#1087;&#1072; &#1054;&#1073;&#1098;&#1077;&#1082;&#1090;&#1099;, &#1082;&#1086;&#1090;&#1086;&#1088;&#1099;&#1081; &#1084;&#1099; &#1089;&#1086;&#1079;&#1076;&#1072;&#1083;&#1080;
        std::vector<Layer> layers;
};

///////////////////////////////////////


int Object::GetPropertyInt(std::string name)//&#1074;&#1086;&#1079;&#1074;&#1088;&#1072;&#1097;&#1072;&#1077;&#1084; &#1085;&#1086;&#1084;&#1077;&#1088; &#1089;&#1074;&#1086;&#1081;&#1089;&#1090;&#1074;&#1072; &#1074; &#1085;&#1072;&#1096;&#1077;&#1084; &#1089;&#1087;&#1080;&#1089;&#1082;&#1077;
{
        return atoi(properties[name].c_str());
}

float Object::GetPropertyFloat(std::string name)
{
        return strtod(properties[name].c_str(), NULL);
}

std::string Object::GetPropertyString(std::string name)//&#1087;&#1086;&#1083;&#1091;&#1095;&#1080;&#1090;&#1100; &#1080;&#1084;&#1103; &#1074; &#1074;&#1080;&#1076;&#1077; &#1089;&#1090;&#1088;&#1086;&#1082;&#1080;.&#1074;&#1088;&#1086;&#1076;&#1077; &#1087;&#1086;&#1085;&#1103;&#1090;&#1085;&#1086;
{
        return properties[name];
}

bool Level::LoadFromFile(std::string filename)//&#1076;&#1074;&#1086;&#1077;&#1090;&#1086;&#1095;&#1080;&#1103;-&#1086;&#1073;&#1088;&#1072;&#1097;&#1077;&#1085;&#1080;&#1077; &#1082; &#1084;&#1077;&#1090;&#1086;&#1076;&#1072;&#1084; &#1082;&#1083;&#1072;&#1089;&#1089;&#1072; &#1074;&#1085;&#1077; &#1082;&#1083;&#1072;&#1089;&#1089;&#1072;
{
        TiXmlDocument levelFile(filename.c_str());//&#1079;&#1072;&#1075;&#1088;&#1091;&#1078;&#1072;&#1077;&#1084; &#1092;&#1072;&#1081;&#1083; &#1074; TiXmlDocument

                                                                                          // &#1079;&#1072;&#1075;&#1088;&#1091;&#1078;&#1072;&#1077;&#1084; XML-&#1082;&#1072;&#1088;&#1090;&#1091;
        if (!levelFile.LoadFile())//&#1077;&#1089;&#1083;&#1080; &#1085;&#1077; &#1091;&#1076;&#1072;&#1083;&#1086;&#1089;&#1100; &#1079;&#1072;&#1075;&#1088;&#1091;&#1079;&#1080;&#1090;&#1100; &#1082;&#1072;&#1088;&#1090;&#1091;
        {
                std::cout << "Loading level \"" << filename << "\" failed." << std::endl;//&#1074;&#1099;&#1076;&#1072;&#1077;&#1084; &#1086;&#1096;&#1080;&#1073;&#1082;&#1091;
                return false;
        }

        // &#1088;&#1072;&#1073;&#1086;&#1090;&#1072;&#1077;&#1084; &#1089; &#1082;&#1086;&#1085;&#1090;&#1077;&#1081;&#1085;&#1077;&#1088;&#1086;&#1084; map
        TiXmlElement *map;
        map = levelFile.FirstChildElement("map");

        // &#1087;&#1088;&#1080;&#1084;&#1077;&#1088; &#1082;&#1072;&#1088;&#1090;&#1099;: <map version="1.0" orientation="orthogonal"
        // width="10" height="10" tilewidth="34" tileheight="34">
        width = atoi(map->Attribute("width"));//&#1080;&#1079;&#1074;&#1083;&#1077;&#1082;&#1072;&#1077;&#1084; &#1080;&#1079; &#1085;&#1072;&#1096;&#1077;&#1081; &#1082;&#1072;&#1088;&#1090;&#1099; &#1077;&#1077; &#1089;&#1074;&#1086;&#1081;&#1089;&#1090;&#1074;&#1072;
        height = atoi(map->Attribute("height"));//&#1090;&#1077; &#1089;&#1074;&#1086;&#1081;&#1089;&#1090;&#1074;&#1072;, &#1082;&#1086;&#1090;&#1086;&#1088;&#1099;&#1077; &#1079;&#1072;&#1076;&#1072;&#1074;&#1072;&#1083;&#1080; &#1087;&#1088;&#1080; &#1088;&#1072;&#1073;&#1086;&#1090;&#1077; &#1074;
        tileWidth = atoi(map->Attribute("tilewidth"));//&#1090;&#1072;&#1081;&#1083;&#1084;&#1072;&#1087; &#1088;&#1077;&#1076;&#1072;&#1082;&#1090;&#1086;&#1088;&#1077;
        tileHeight = atoi(map->Attribute("tileheight"));

        // &#1041;&#1077;&#1088;&#1077;&#1084; &#1086;&#1087;&#1080;&#1089;&#1072;&#1085;&#1080;&#1077; &#1090;&#1072;&#1081;&#1083;&#1089;&#1077;&#1090;&#1072; &#1080; &#1080;&#1076;&#1077;&#1085;&#1090;&#1080;&#1092;&#1080;&#1082;&#1072;&#1090;&#1086;&#1088; &#1087;&#1077;&#1088;&#1074;&#1086;&#1075;&#1086; &#1090;&#1072;&#1081;&#1083;&#1072;
        TiXmlElement *tilesetElement;
        tilesetElement = map->FirstChildElement("tileset");
        firstTileID = atoi(tilesetElement->Attribute("firstgid"));

        // source - &#1087;&#1091;&#1090;&#1100; &#1076;&#1086; &#1082;&#1072;&#1088;&#1090;&#1080;&#1085;&#1082;&#1080; &#1074; &#1082;&#1086;&#1085;&#1090;&#1077;&#1081;&#1085;&#1077;&#1088;&#1077; image
        TiXmlElement *image;
        image = tilesetElement->FirstChildElement("image");
        std::string imagepath = image->Attribute("source");

        // &#1087;&#1099;&#1090;&#1072;&#1077;&#1084;&#1089;&#1103; &#1079;&#1072;&#1075;&#1088;&#1091;&#1079;&#1080;&#1090;&#1100; &#1090;&#1072;&#1081;&#1083;&#1089;&#1077;&#1090;
        sf::Image img;

        if (!img.loadFromFile(imagepath))
        {
                std::cout << "Failed to load tile sheet." << std::endl;//&#1077;&#1089;&#1083;&#1080; &#1085;&#1077; &#1091;&#1076;&#1072;&#1083;&#1086;&#1089;&#1100; &#1079;&#1072;&#1075;&#1088;&#1091;&#1079;&#1080;&#1090;&#1100; &#1090;&#1072;&#1081;&#1083;&#1089;&#1077;&#1090;-&#1074;&#1099;&#1074;&#1086;&#1076;&#1080;&#1084; &#1086;&#1096;&#1080;&#1073;&#1082;&#1091; &#1074; &#1082;&#1086;&#1085;&#1089;&#1086;&#1083;&#1100;
                return false;
        }


        img.createMaskFromColor(sf::Color(255, 255, 255));//&#1076;&#1083;&#1103; &#1084;&#1072;&#1089;&#1082;&#1080; &#1094;&#1074;&#1077;&#1090;&#1072;.&#1089;&#1077;&#1081;&#1095;&#1072;&#1089; &#1085;&#1077;&#1090; &#1084;&#1072;&#1089;&#1082;&#1080;
        tilesetImage.loadFromImage(img);
        tilesetImage.setSmooth(false);//&#1089;&#1075;&#1083;&#1072;&#1078;&#1080;&#1074;&#1072;&#1085;&#1080;&#1077;

                                                                  // &#1087;&#1086;&#1083;&#1091;&#1095;&#1072;&#1077;&#1084; &#1082;&#1086;&#1083;&#1080;&#1095;&#1077;&#1089;&#1090;&#1074;&#1086; &#1089;&#1090;&#1086;&#1083;&#1073;&#1094;&#1086;&#1074; &#1080; &#1089;&#1090;&#1088;&#1086;&#1082; &#1090;&#1072;&#1081;&#1083;&#1089;&#1077;&#1090;&#1072;
        int columns = tilesetImage.getSize().x / tileWidth;
        int rows = tilesetImage.getSize().y / tileHeight;

        // &#1074;&#1077;&#1082;&#1090;&#1086;&#1088; &#1080;&#1079; &#1087;&#1088;&#1103;&#1084;&#1086;&#1091;&#1075;&#1086;&#1083;&#1100;&#1085;&#1080;&#1082;&#1086;&#1074; &#1080;&#1079;&#1086;&#1073;&#1088;&#1072;&#1078;&#1077;&#1085;&#1080;&#1081; (TextureRect)
        std::vector<sf::Rect<int>> subRects;

        for (int y = 0; y < rows; y++)
                for (int x = 0; x < columns; x++)
                {
                        sf::Rect<int> rect;

                        rect.top = y * tileHeight;
                        rect.height = tileHeight;
                        rect.left = x * tileWidth;
                        rect.width = tileWidth;

                        subRects.push_back(rect);
                }

        // &#1088;&#1072;&#1073;&#1086;&#1090;&#1072; &#1089;&#1086; &#1089;&#1083;&#1086;&#1103;&#1084;&#1080;
        TiXmlElement *layerElement;
        layerElement = map->FirstChildElement("layer");
        while (layerElement)
        {
                Layer layer;

                // &#1077;&#1089;&#1083;&#1080; &#1087;&#1088;&#1080;&#1089;&#1091;&#1090;&#1089;&#1090;&#1074;&#1091;&#1077;&#1090; opacity, &#1090;&#1086; &#1079;&#1072;&#1076;&#1072;&#1077;&#1084; &#1087;&#1088;&#1086;&#1079;&#1088;&#1072;&#1095;&#1085;&#1086;&#1089;&#1090;&#1100; &#1089;&#1083;&#1086;&#1103;, &#1080;&#1085;&#1072;&#1095;&#1077; &#1086;&#1085; &#1087;&#1086;&#1083;&#1085;&#1086;&#1089;&#1090;&#1100;&#1102; &#1085;&#1077;&#1087;&#1088;&#1086;&#1079;&#1088;&#1072;&#1095;&#1077;&#1085;
                if (layerElement->Attribute("opacity") != NULL)
                {
                        float opacity = strtod(layerElement->Attribute("opacity"), NULL);
                        layer.opacity = 255 * opacity;
                }
                else
                {
                        layer.opacity = 255;
                }

                //  &#1082;&#1086;&#1085;&#1090;&#1077;&#1081;&#1085;&#1077;&#1088; <data>
                TiXmlElement *layerDataElement;
                layerDataElement = layerElement->FirstChildElement("data");

                if (layerDataElement == NULL)
                {
                        std::cout << "Bad map. No layer information found." << std::endl;
                }

                //  &#1082;&#1086;&#1085;&#1090;&#1077;&#1081;&#1085;&#1077;&#1088; <tile> - &#1086;&#1087;&#1080;&#1089;&#1072;&#1085;&#1080;&#1077; &#1090;&#1072;&#1081;&#1083;&#1086;&#1074; &#1082;&#1072;&#1078;&#1076;&#1086;&#1075;&#1086; &#1089;&#1083;&#1086;&#1103;
                TiXmlElement *tileElement;
                tileElement = layerDataElement->FirstChildElement("tile");

                if (tileElement == NULL)
                {
                        std::cout << "Bad map. No tile information found." << std::endl;
                        return false;
                }

                int x = 0;
                int y = 0;

                while (tileElement)
                {
                        int tileGID = atoi(tileElement->Attribute("gid"));
                        int subRectToUse = tileGID - firstTileID;

                        // &#1059;&#1089;&#1090;&#1072;&#1085;&#1072;&#1074;&#1083;&#1080;&#1074;&#1072;&#1077;&#1084; TextureRect &#1082;&#1072;&#1078;&#1076;&#1086;&#1075;&#1086; &#1090;&#1072;&#1081;&#1083;&#1072;
                        if (subRectToUse >= 0)
                        {
                                sf::Sprite sprite;
                                sprite.setTexture(tilesetImage);
                                sprite.setTextureRect(subRects[subRectToUse]);
                                sprite.setPosition(x * tileWidth, y * tileHeight);
                                sprite.setColor(sf::Color(255, 255, 255, layer.opacity));

                                layer.tiles.push_back(sprite);//&#1079;&#1072;&#1082;&#1080;&#1076;&#1099;&#1074;&#1072;&#1077;&#1084; &#1074; &#1089;&#1083;&#1086;&#1081; &#1089;&#1087;&#1088;&#1072;&#1081;&#1090;&#1099; &#1090;&#1072;&#1081;&#1083;&#1086;&#1074;
                        }

                        tileElement = tileElement->NextSiblingElement("tile");

                        x++;
                        if (x >= width)
                        {
                                x = 0;
                                y++;
                                if (y >= height)
                                        y = 0;
                        }
                }

                layers.push_back(layer);

                layerElement = layerElement->NextSiblingElement("layer");
        }

        // &#1088;&#1072;&#1073;&#1086;&#1090;&#1072; &#1089; &#1086;&#1073;&#1098;&#1077;&#1082;&#1090;&#1072;&#1084;&#1080;
        TiXmlElement *objectGroupElement;

        // &#1077;&#1089;&#1083;&#1080; &#1077;&#1089;&#1090;&#1100; &#1089;&#1083;&#1086;&#1080; &#1086;&#1073;&#1098;&#1077;&#1082;&#1090;&#1086;&#1074;
        if (map->FirstChildElement("objectgroup") != NULL)
        {
                objectGroupElement = map->FirstChildElement("objectgroup");
                while (objectGroupElement)
                {
                        //  &#1082;&#1086;&#1085;&#1090;&#1077;&#1081;&#1085;&#1077;&#1088; <object>
                        TiXmlElement *objectElement;
                        objectElement = objectGroupElement->FirstChildElement("object");

                        while (objectElement)
                        {
                                // &#1087;&#1086;&#1083;&#1091;&#1095;&#1072;&#1077;&#1084; &#1074;&#1089;&#1077; &#1076;&#1072;&#1085;&#1085;&#1099;&#1077; - &#1090;&#1080;&#1087;, &#1080;&#1084;&#1103;, &#1087;&#1086;&#1079;&#1080;&#1094;&#1080;&#1103;, &#1080; &#1090;&#1076;
                                std::string objectType;
                                if (objectElement->Attribute("type") != NULL)
                                {
                                        objectType = objectElement->Attribute("type");
                                }
                                std::string objectName;
                                if (objectElement->Attribute("name") != NULL)
                                {
                                        objectName = objectElement->Attribute("name");
                                }
                                int x = atoi(objectElement->Attribute("x"));
                                int y = atoi(objectElement->Attribute("y"));

                                int width, height;

                                sf::Sprite sprite;
                                sprite.setTexture(tilesetImage);
                                sprite.setTextureRect(sf::Rect<int>(0, 0, 0, 0));
                                sprite.setPosition(x, y);

                                if (objectElement->Attribute("width") != NULL)
                                {
                                        width = atoi(objectElement->Attribute("width"));
                                        height = atoi(objectElement->Attribute("height"));
                                }
                                else
                                {
                                        width = subRects[atoi(objectElement->Attribute("gid")) - firstTileID].width;
                                        height = subRects[atoi(objectElement->Attribute("gid")) - firstTileID].height;
                                        sprite.setTextureRect(subRects[atoi(objectElement->Attribute("gid")) - firstTileID]);
                                }

                                // &#1101;&#1082;&#1079;&#1077;&#1084;&#1087;&#1083;&#1103;&#1088; &#1086;&#1073;&#1098;&#1077;&#1082;&#1090;&#1072;
                                Object object;
                                object.name = objectName;
                                object.type = objectType;
                                object.sprite = sprite;

                                sf::Rect <float> objectRect;
                                objectRect.top = y;
                                objectRect.left = x;
                                objectRect.height = height;
                                objectRect.width = width;
                                object.rect = objectRect;

                                // "&#1087;&#1077;&#1088;&#1077;&#1084;&#1077;&#1085;&#1085;&#1099;&#1077;" &#1086;&#1073;&#1098;&#1077;&#1082;&#1090;&#1072;
                                TiXmlElement *properties;
                                properties = objectElement->FirstChildElement("properties");
                                if (properties != NULL)
                                {
                                        TiXmlElement *prop;
                                        prop = properties->FirstChildElement("property");
                                        if (prop != NULL)
                                        {
                                                while (prop)
                                                {
                                                        std::string propertyName = prop->Attribute("name");
                                                        std::string propertyValue = prop->Attribute("value");

                                                        object.properties[propertyName] = propertyValue;

                                                        prop = prop->NextSiblingElement("property");
                                                }
                                        }
                                }


                                objects.push_back(object);

                                objectElement = objectElement->NextSiblingElement("object");
                        }
                        objectGroupElement = objectGroupElement->NextSiblingElement("objectgroup");
                }
        }
        else
        {
                std::cout << "No object layers found..." << std::endl;
        }

        return true;
}

Object Level::GetObject(std::string name)
{
        // &#1090;&#1086;&#1083;&#1100;&#1082;&#1086; &#1087;&#1077;&#1088;&#1074;&#1099;&#1081; &#1086;&#1073;&#1098;&#1077;&#1082;&#1090; &#1089; &#1079;&#1072;&#1076;&#1072;&#1085;&#1085;&#1099;&#1084; &#1080;&#1084;&#1077;&#1085;&#1077;&#1084;
        for (int i = 0; i < objects.size(); i++)
                if (objects[i].name == name)
                        return objects[i];
}

std::vector<Object> Level::GetObjects(std::string name)
{
        // &#1074;&#1089;&#1077; &#1086;&#1073;&#1098;&#1077;&#1082;&#1090;&#1099; &#1089; &#1079;&#1072;&#1076;&#1072;&#1085;&#1085;&#1099;&#1084; &#1080;&#1084;&#1077;&#1085;&#1077;&#1084;
        std::vector<Object> vec;
        for (int i = 0; i < objects.size(); i++)
                if (objects[i].name == name)
                        vec.push_back(objects[i]);

        return vec;
}


std::vector<Object> Level::GetAllObjects()
{
        return objects;
};


sf::Vector2i Level::GetTileSize()
{
        return sf::Vector2i(tileWidth, tileHeight);
}

void Level::Draw(sf::RenderWindow &window)
{
        // &#1088;&#1080;&#1089;&#1091;&#1077;&#1084; &#1074;&#1089;&#1077; &#1090;&#1072;&#1081;&#1083;&#1099; (&#1086;&#1073;&#1098;&#1077;&#1082;&#1090;&#1099; &#1085;&#1077; &#1088;&#1080;&#1089;&#1091;&#1077;&#1084;!)
        for (int layer = 0; layer < layers.size(); layer++)
                for (int tile = 0; tile < layers[layer].tiles.size(); tile++)
                        window.draw(layers[layer].tiles[tile]);
}

#endif

spoty76

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Levels
« Reply #1 on: September 17, 2017, 07:06:19 pm »
SOLVED