Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - SethGandy

Pages: [1]
1
Graphics / Re: Sprite Container/ Combiner?
« on: January 29, 2013, 03:55:38 am »
Hitting the books, putting the project off for a bit.
Been reading for the past 5 hours, to help wash away the feeling of shame and incompetence.

2
Graphics / Re: Sprite Container/ Combiner?
« on: January 28, 2013, 03:55:10 am »
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]

3
Graphics / Re: Sprite Container/ Combiner?
« on: January 28, 2013, 03:22:28 am »
When I try to create the new object it errors out 'Tilemap': cannot instantiate abstract class.
pure virtual function "sF::Drawable::draw" has no overrider.

Also I'm actually reading up on it, from C++ PROGRAMMING: PROGRAM DESIGN INCLUDING DATA STRUCTURES, 5TH EDITION. It's for class.

This whole isometric thing is just my own infatuation getting the best of me.

4
Graphics / Re: Sprite Container/ Combiner?
« on: January 28, 2013, 01:50:14 am »
Apologies, I'm confused as to how to implement this?
I'm pretty rusty on inheritance classes and virtuals.
I can't create a new class object such as Tilemap newOb; , so I'm kinda at a loss as how to use this lol  ???

5
Graphics / Sprite Container/ Combiner?
« on: January 27, 2013, 12:27:49 pm »
So I'm new to the wonderful world of SFML.
I'm making an isometric tile engine as my first project.
Problem I'm having is I want to combine all the tiles I draw into one object.
That way the map moves all as one piece once rendered.
How would I go about making this said "container"?

My current map rendering system looks like this:
Code: [Select]
// image already loaded in to textureVector[x], mapVector[x][y] is the map in zeros and ones
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 / 2)-(i * BLOCKSIZE /2)+40, (j * BLOCKSIZE / 4)+(i * BLOCKSIZE /4)+40);
tileSprite.setRotation(45);
Window.draw(tileSprite);
}
}

Pages: [1]
anything