Attached is my project in it's entirety.
So far, I've only written to the main.cpp, I haven't bothered splitting up my functions and creating headers and implementation files yet, not until I have the base of the program done... bad habit of mine.
But here's the code thus far:
#include<SFML\Graphics.hpp>
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<sstream>
using namespace std;
using namespace sf;
#define ScreenWidth 800
#define ScreenHeight 600
#define BLOCKSIZE 40
int currentMapX;
int currentMapY;
vector <vector <int> > MapVector;
vector <Texture> textureVector;
class Tilemap : public Drawable, public Transformable
{
private:
virtual void draw(RenderTarget& target, RenderStates states)
{
states.transform *= getTransform(); // sf::Transformable::getTransform()
target.draw(member, states);
}
Sprite member; // can be a container of tiles or whatever
};
void LoadMap(const char *filename)
{
ifstream openfile(filename);
vector <int> tempVector;
string line;
if(openfile.is_open())
{
while(!openfile.eof())
{
getline(openfile, line);
string tempLine = line.erase(line.find_last_not_of(" ") + 1);
int space = tempLine.find_first_of(" ");
if(space == 0)
tempLine = tempLine.erase(0, space + 1);
stringstream str(tempLine);
while(!str.eof())
{
string value;
getline(str, value, ' ');
if(value.length() > 0)
tempVector.push_back(atoi(value.c_str()));
}
MapVector.push_back(tempVector);
tempVector.clear();
}
}
cout<<"[------- MAP -------]\n";
//------Ouput Map---------
int mapY=0;
int mapXtemp=0;
int mapX=0;
for (int r=0; r < MapVector.size(); r++)
{
mapY++;
for (int c=0; c < MapVector[r].size(); c++)
{
cout << MapVector[r][c] << " ";
mapXtemp++;
}
if(mapXtemp > mapX)
{
mapX=mapXtemp;
}
mapXtemp=0;
cout << endl;
}
currentMapX = mapX;
currentMapY = mapY;
cout<<endl<<mapY<<"x"<<mapX<<endl;
}
void LoadTextures(const char *filename)
{
cout << "#####################\n";
string line;
Texture inText;
ifstream openfile(filename);
if(openfile.is_open())
{
while(!openfile.eof())
{
getline(openfile, line);
string tempLine = line.erase(line.find_last_not_of(" ") +1);
cout<<"Loaded : ["<<tempLine<<"]"<<endl;
if(tempLine.length() > 0)
{
if(!inText.loadFromFile(tempLine))
{
cout << "Could not load" << line << endl;
}
textureVector.push_back(inText);
}
}
}
cout << "#####################\n";
}
void DrawMap(RenderWindow &Window)
{
RectangleShape mapCont;
mapCont.setFillColor(Color::Green);
mapCont.setSize(Vector2f((currentMapX)*BLOCKSIZE,(currentMapY)*BLOCKSIZE));
mapCont.setPosition(20,40);
mapCont.setRotation(45);
mapCont.setPosition(mapCont.getPosition().x, mapCont.getPosition().y * 2);
View v = Window.getDefaultView();
v.setSize(v.getSize().x, v.getSize().y * 2);
v.setCenter(v.getSize() *.5f);
Window.setView(v);
Window.draw(mapCont);
Window.setView(Window.getDefaultView());
//Window.setView(v);
Sprite tileSprite;
for(int i = 0; i < MapVector.size(); i++)
{
for(int j = 0; j < MapVector[i].size(); j++)
{
tileSprite.setTexture(textureVector[MapVector[i][j]]);
tileSprite.setPosition((j * BLOCKSIZE)+40,(i * BLOCKSIZE)+40);
//tileSprite.setRotation(45);
Window.draw(tileSprite);
}
}
Window.setView(Window.getDefaultView());
}
int main()
{
RenderWindow Window(VideoMode(ScreenWidth,ScreenHeight,32), "isometric engine", Style::Close);
LoadTextures("Textures.txt");
LoadMap("Map1.txt");
Font Font;
if (!Font.loadFromFile("font.ttf"))
return 1;
Text Text("Seth Gandy | iso v0.01", Font);
//Text.setStyle(Text::Style::Bold);
Text.setCharacterSize(25U);
Text.setPosition(510,565);
while(Window.isOpen())
{
Event Event;
while(Window.pollEvent(Event))
{
if(Event.type == Event::Closed || Event.key.code == Keyboard::Escape)
Window.close();
}
Window.clear(Color(0, 125, 255));
DrawMap(Window);
Window.draw(Text);
Window.display();
}
return 0;
}
[attachment deleted by admin]