24 декабря 2023 г. Архивач восстановлен после серьёзной аварии. К сожалению, значительная часть сохранённых изображений и видео была потеряна.
Подробности случившегося. Мы призываем всех неравнодушных
помочь нам с восстановлением утраченного контента!
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Map.h"
using namespace sf;
class castle { //крепость
private:
float x, y;
public:
float w, h; //высота и ширина
int health; //количество здоровья
String file;
Image image;
Texture texture;
Sprite sprite;
castle(String FILE, float X, float Y, float W, float H) {
health = 100;
file = FILE;
w = W; h = H;
image.loadFromFile("images/"+FILE);
texture.loadFromImage(image);
sprite.setTexture(texture);
x = X; y = Y;
sprite.setTextureRect(IntRect(0, 0, w, h));
sprite.setPosition(x, y);
}
};
int main()
{
RenderWindow window(sf::VideoMode(480, 640), "TD_GAME"); //окно игры
Image map_image; //карта
map_image.loadFromFile("images/map.png");
Texture map;
map.loadFromImage(map_image);
Sprite s_map;
s_map.setTexture(map);
castle cast("hero.png", 350, 600, 96.0, 96.0);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) window.close();
}
window.clear();
for (int i = 0; i < heightMap; i++)
for (int j = 0; j < widthMap; j++) {
if (tileMap[j] == ' ') s_map.setTextureRect(IntRect(0, 0, 32, 32));
else if (tileMap[j] == '0') s_map.setTextureRect(IntRect(64, 0, 32, 32));
s_map.setPosition(j 32, i 32);
window.draw(s_map);
}
window.display();
}
return 0;
}
Map.h:
#include <SFML/Graphics.hpp>
const int heightMap = 20;//размер карты высота
const int widthMap = 15; //размер карты ширина
char* tileMap[widthMap][heightMap] =
{
"000000000000000",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
"000000000000000"
};
Предполагаю, что ошибка в создании карты
Памагити