1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#include <SFML/Graphics.hpp>
#include <iostream>
#include <list>
#include <vector>
using namespace std;
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Tile Editor");
sf::Event event;
sf::Mouse mouse;
sf::Clock clock;
sf::Time time;
sf::View scrollScreen;
list<sf::Sprite> setTile;
list<sf::Sprite>::iterator iter;
vector<sf::Sprite> spr_Vector;
int GridSize;
window.setFramerateLimit(60);
scrollScreen.reset(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
sf::Texture blankGridTexture;
sf::Sprite blankGridSprite;
if(!blankGridTexture.loadFromFile("Resources/Tiles/Grid.png"))
{
}
blankGridSprite.setTexture(blankGridTexture);
blankGridSprite.setOrigin(16, 16);
GridSize = 10;
//Input grid into vector
for(int i = 0; i < GridSize; i++)
{
spr_Vector.push_back(blankGridSprite);
}
while(window.isOpen())
{
while(window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
{
window.close();
}break;
case sf::Event::Resized:
{
sf::FloatRect viewArea(0, 0, event.size.width, event.size.height);
window.setView(sf::View(viewArea));
scrollScreen.reset(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
}break;
}
}
window.clear(sf::Color::White);
time = clock.getElapsedTime();
sf::Vector2i pixel_pos = sf::Mouse::getPosition(window);
sf::Vector2f coord_pos = window.mapPixelToCoords(pixel_pos);
cout << "Row: " << rint(coord_pos.x / 32) << ",";
cout << "Column: " << rint(coord_pos.y / 32) << endl;
scrollScreen.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));
//Load Grass
sf::Texture tileTexture;
sf::Sprite tileSprite;
if(!tileTexture.loadFromFile("Resources/Tiles/Grass.png"))
{
}
tileSprite.setTexture(tileTexture);
tileSprite.setOrigin(16, 16);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
scrollScreen.move(-10, 0);
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
scrollScreen.move(10, 0);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{
scrollScreen.move(0, -10);
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{
scrollScreen.move(0, 10);
}
//Output to map
for(int i = 0; i < spr_Vector.size(); i++)
{
for(int j = 0; j < spr_Vector.size(); j++)
{
blankGridSprite.setPosition(j * 32, i * 32);
//blankGridSprite.setTextureRect(sf::IntRect(j * 32, i * 32, 32, 32));
window.draw(blankGridSprite);
}
}
/*
if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
cout << "Clicked" << endl;
//Get Position of the mouse then divide by 32 and round down to integer, then times it by 32 to set grid.
tileSprite.setPosition(rint(coord_pos.x / 32) * 32, rint(coord_pos.y / 32) * 32);
setTile.push_back(tileSprite);
}
*/
if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
//tileSprite.setPosition(rint(coord_pos.x / 32) * 32, rint(coord_pos.y / 32) * 32);
//setTile.push_back(tileSprite);
//tileGrid[4][2].setPosition();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::L))
{
}
iter = setTile.begin();
while(iter != setTile.end())
{
window.draw(*iter);
iter++;
}
cout << setTile.size() << endl;
cout << time.asSeconds() << endl;
window.setView(scrollScreen);
clock.restart();
window.display();
}
return 0;
}
|