Untitled
unknown
plain_text
3 years ago
2.8 kB
8
Indexable
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
using namespace std;
using namespace sf;
struct mapS {
char type;
Sprite sprite;
};
struct Kletka {
};
int main() {
mapS** Map = new mapS* [34];
for (int i = 0; i < 5; i++) {
Map[i] = new mapS[60];
}
mapS** Pole = new mapS * [34];
for (int i = 0; i < 5; i++) {
Pole[i] = new mapS[60];
}
RenderWindow win(VideoMode(1920, 1080), "SFML works!", Style::Fullscreen);
Texture wall1; wall1.loadFromFile("D:/Resources/Fl1.png");
Sprite Wall1; Wall1.setTexture(wall1); Wall1.setScale(2, 2);
Texture void1; void1.loadFromFile("D:/Resources/void1.png");
Sprite Void1; Void1.setTexture(void1); Void1.setScale(2, 2);
Texture turret_base1; turret_base1.loadFromFile("D:/Resources/turret_base1.png");
Sprite Turret_base1; Turret_base1.setTexture(turret_base1); Turret_base1.setScale(2, 2);
Texture turret1; turret1.loadFromFile("D:/Resources/turret1.png");
Sprite Turret1; Turret1.setTexture(turret1); Turret1.setScale(2, 2);
for (int i = 0; i < 34; i++){
for (int j = 0; j < 60; j++){
if (i == 0 ||i == 33) {
Map[i][j].sprite = Wall1;
Map[i][j].type = 'W';
}
else if (j > 0 && j < 34 || j > 45 && j < 90) {
Map[i][j].sprite = Wall1;
Map[i][j].type = 'W';
}
else {
Map[i][j].sprite = Void1;
Map[i][j].type = 'V';
}
Map[i][j].sprite.setPosition(i * 32, j * 32);
}
}
while (win.isOpen()) {
int mx = Mouse::getPosition(win).x;
int my = Mouse::getPosition(win).y;
Event event;
while (win.pollEvent(event))
{
if (event.type == Event::Closed)
win.close();
else if (event.type == Event::KeyPressed) {
if (event.key.code == Keyboard::Escape) {
win.close();
}
}
else if (event.type == Event::MouseButtonPressed && Map[mx/32][my/32].type == 'V') {
Vector2f tmp;
tmp = Map[mx / 24][my / 24].sprite.getPosition();
Pole[mx / 24][my / 24].sprite = Turret1;
Pole[mx / 24][my / 24].sprite.setPosition(tmp);
Pole[mx / 24][my / 24].type = 'T';
}
}
win.clear();
for (int i = 0; i < 80; i++){
for (int j = 0; j < 50; j++) {
win.draw(Map[i][j].sprite);
win.draw(Pole[i][j].sprite);
}
}
win.display();
}
}
Editor is loading...