Исправь ошибки в моём коде: #include <SFML/Graphics.hpp> #include <SFML/Audio.hpp> using…
- User
Исправь ошибки в моём коде: #include <SFML/Graphics.hpp> #include <SFML/Audio.hpp>
using namespace sf;
float offsetX = 0, offsetY = 0;
const int H = 17; const int W = 150;
String TileMap[H] = {/MAP IS HERE/};
class TileMap { public: TileMap(const Texture& tileSet) { tile.setTexture(tileSet); }
void loadMap(const String* map) { for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (map[i][j] == 'P') { tile.setTextureRect(IntRect(143 - 16 * 3, 112, 16, 16)); } else if (map[i][j] == 'k') { tile.setTextureRect(IntRect(143, 112, 16, 16)); } else if (map[i][j] == 'c') { tile.setTextureRect(IntRect(143 - 16, 112, 16, 16)); } else if (map[i][j] == 't') { tile.setTextureRect(IntRect(0, 47, 32, 95 - 47)); } else if (map[i][j] == 'g') { tile.setTextureRect(IntRect(0, 16 * 9 - 5, 3 * 16, 16 * 2 + 5)); } else if (map[i][j] == 'G') { tile.setTextureRect(IntRect(145, 222, 222 - 145, 255 - 222)); } else if (map[i][j] == 'd') { tile.setTextureRect(IntRect(0, 106, 74, 127 - 106)); } else if (map[i][j] == 'w') { tile.setTextureRect(IntRect(99, 224, 140 - 99, 255 - 224)); } else if (map[i][j] == 'r') { tile.setTextureRect(IntRect(143 - 32, 112, 16, 16)); } else if (map[i][j] == ' ' || map[i][j] == '0') { continue; } tile.setPosition(j * 16 - offsetX, i * 16 - offsetY); window.draw(tile); } } }private: Sprite tile; };
class Character { public: Character(const Texture& image, float x, float y) : dx(0.1), dy(0.1), currentFrame(0), onGround(true), life(true) { sprite.setTexture(image); rect = FloatRect(x, y, 16, 16); }
void update(float time) { rect.left += dx * time; Collision(0); if (!onGround) dy = dy + 0.0005 * time; rect.top += dy * time; onGround = false; Collision(1); currentFrame += time * 0.005; if (currentFrame > 3) currentFrame -= 3; if (dx > 0) { sprite.setTextureRect(IntRect(112 + 31 * int(currentFrame), 144, 16, 16)); } else if (dx < 0) { sprite.setTextureRect(IntRect(112 + 31 * int(currentFrame) + 16, 144, -16, 16)); } sprite.setPosition(rect.left - offsetX, rect.top - offsetY); dx = 0; } void Collision(int num) { for (int i = rect.top / 16; i < (rect.top + rect.height) / 16; i++) { for (int j = rect.left / 16; j < (rect.left + rect.width) / 16; j++) { if ((TileMap[i][j] == 'P') || (TileMap[i][j] == 'k') || (TileMap[i][j] == '0') || (TileMap[i][j] == 'r') || (TileMap[i][j] == 't')) { if (dy > 0 && num == 1) { rect.top = i * 16 - rect.height; dy = 0; onGround = true; } if (dy < 0 && num == 1) { rect.top = i * 16 + 16; dy = 0; } if (dx > 0 && num == 0) { rect.left = j * 16 - rect.width; } if (dx < 0 && num == 0) { rect.left = j * 16 + 16; } } if (TileMap[i][j] == 'c') { // TileMap[i][j]=’ '; } } } } Sprite& getSprite() { return sprite; } - Assistant