I've made this program and it runs and compiles fine, but it I change anything and re-compile and run it, my antivirus either stops my exe for trying to delete itself, or it stops Id.exe. Does anyone have any idea why this is happening? As I have no idea what is causing this, I'll give my full code, it isn't that long. As I'm using RAII I thought it might be to do with that and there are some people who are amazing at it on here, but I don't know and it might be to do with my sfml code.
main.cpp:
#include <SFML/Graphics.hpp>
#include "block.hpp"
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
window.setFramerateLimit(60);
sf::Image tileImage;
std::shared_ptr<sf::Texture> bodyTexture;
std::array<std::shared_ptr<sf::Texture>,24> pistonTextures;
std::array<std::shared_ptr<sf::Texture>,24> leftConnectorTextures;
std::array<std::shared_ptr<sf::Texture>,24> rightConnectorTextures;
tileImage.loadFromFile("tilesheet.png");
bodyTexture.reset(new sf::Texture);
for(int i (0); i < 24; i = i + 1)
{
pistonTextures[i].reset(new sf::Texture);
leftConnectorTextures[i].reset(new sf::Texture);
rightConnectorTextures[i].reset(new sf::Texture);
}
bodyTexture->loadFromImage(tileImage,sf::IntRect(0,0,32,32));
for(int i (0); i < 24; i = i + 1)
{
pistonTextures[i]->loadFromImage(tileImage,sf::IntRect(66+(9*i),0,8,26));
leftConnectorTextures[i]->loadFromImage(tileImage,sf::IntRect(66+(9*i),27,8,12));
rightConnectorTextures[i]->loadFromImage(tileImage,sf::IntRect(66+(9*i),40,8,12));
}
block Block(bodyTexture,pistonTextures,leftConnectorTextures,rightConnectorTextures,0,0);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
Block.draw(window);
window.display();
}
return 0;
}
block.hpp:
#ifndef BLOCK_HPP_INCLUDED
#define BLOCK_HPP_INCLUDED
#include <array>
#include <memory>
class block{
private:
std::shared_ptr<sf::Texture> bodyTexture;
std::array<std::shared_ptr<sf::Texture>,24> pistonTextures;
std::array<std::shared_ptr<sf::Texture>,24> leftConnectorTextures;
std::array<std::shared_ptr<sf::Texture>,24> rightConnectorTextures;
std::array<sf::Sprite,16> sprites;
int xpos, ypos, pistonFrame, leftConnectorFrame, rightConnectorFrame;
static const int pistonLimit = 24;
static const int leftConnectorLimit = 24;
static const int rightConnectorLimit = 24;
bool changePiston, changeLeftCon, changeRightCon, upLinked, downLinked, leftLinked, rightLinked;
public:
block(std::shared_ptr<sf::Texture> BodyTexture,std::array<std::shared_ptr<sf::Texture>,24> PistonTextures,std::array<std::shared_ptr<sf::Texture>,24> LeftConnectorTextures,std::array<std::shared_ptr<sf::Texture>,24> RightConnectorTextures,int xPos, int yPos);
void draw(sf::RenderWindow & window);
};
#endif // BLOCK_HPP_INCLUDED
block.cpp:
#include <SFML/Graphics.hpp>
#include "block.hpp"
block::block(std::shared_ptr<sf::Texture> BodyTexture,std::array<std::shared_ptr<sf::Texture>,24> PistonTextures,std::array<std::shared_ptr<sf::Texture>,24> LeftConnectorTextures,std::array<std::shared_ptr<sf::Texture>,24> RightConnectorTextures,int xPos, int yPos)
{
xpos = xPos;
ypos = yPos;
pistonFrame =
leftConnectorFrame =
rightConnectorFrame =
changePiston =
changeLeftCon =
changeRightCon =
upLinked =
downLinked =
rightLinked =
leftLinked =
0;
bodyTexture = BodyTexture;
for(int i (0); i < 24; i = i + 1)
{
pistonTextures[i] = PistonTextures[i];
rightConnectorTextures[i] = RightConnectorTextures[i];
leftConnectorTextures[i] = LeftConnectorTextures[i];
}
for(int i (0); i < 16; i = i + 4)
{
sprites[i].setTexture(*bodyTexture);
sprites[i+1].setTexture(*(pistonTextures[0]));
sprites[i+2].setTexture(*(leftConnectorTextures[0]));
sprites[i+3].setTexture(*(rightConnectorTextures[0]));
}
for(int i (0); i < 16; i = i + 4)
{
sprites[0].setPosition(xpos,ypos);
sprites[i+1].setPosition(xpos+28,ypos);
sprites[i+2].setPosition(xpos+14,ypos);
sprites[i+3].setPosition(xpos,ypos+22);
sprites[i].setRotation(90*(i/4));
sprites[i+1].setRotation(90*(i/4));
sprites[i+2].setRotation(90*(i/4));
sprites[i+3].setRotation(270 + (90*(i/4)));
}
sprites[4].setPosition(xpos+64,ypos);
sprites[5].setPosition(xpos+64,ypos+28);
sprites[6].setPosition(xpos+64,ypos+14);
sprites[7].setPosition(xpos+42,ypos);
sprites[8].setPosition(xpos+64,ypos+64);
sprites[9].setPosition(xpos+36,ypos+64);
sprites[10].setPosition(xpos+50,ypos+64);
sprites[11].setPosition(xpos+64,ypos+42);
sprites[12].setPosition(xpos,ypos+64);
sprites[13].setPosition(xpos,ypos+36);
sprites[14].setPosition(xpos,ypos+50);
sprites[15].setPosition(xpos+22,ypos+64);
}
void block::draw(sf::RenderWindow & window)
{
window.draw(sprites[0]);
window.draw(sprites[4]);
window.draw(sprites[8]);
window.draw(sprites[12]);
window.draw(sprites[1]);
window.draw(sprites[5]);
window.draw(sprites[9]);
window.draw(sprites[13]);
window.draw(sprites[2]);
window.draw(sprites[6]);
window.draw(sprites[10]);
window.draw(sprites[14]);
window.draw(sprites[3]);
window.draw(sprites[7]);
window.draw(sprites[11]);
window.draw(sprites[15]);
}