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 - natchos

Pages: 1 ... 4 5 [6] 7
76
General / Re: 2d tile system using 2d std::vectors.
« on: June 07, 2012, 08:29:52 pm »
Yerr, nope. That won't work.

Got a goddamn long error message.

\main.cpp(624) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::_Vb_reference<_Sizet,_Difft,_MycontTy>' (or there is no acceptable conversion)
1>        with
1>        [
1>            _Sizet=unsigned int,
1>            _Difft=__w64 int,
1>            _MycontTy=std::vector<bool,std::allocator<bool>>
1>        ]
1>        c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(1144): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(1146): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(1148): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(1150): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream(155): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
(it continues for about another page or two)

Anyhow, wouldn't I still ned the FileStream.ignore(2,' '); to make the function skip the spaces?

77
General / Re: 2d tile system using 2d std::vectors.
« on: June 07, 2012, 07:47:03 pm »
So I am back here, I am posting about an issue which is not the same, but is related to it.

The problem is that I am trying to read a .txt file of ints and bools to construct a level and tilemap from it. The place where I am running into problems is where I try to map a 16*48 grid of 0s and 1s to a tilemap of bools, meant to tell the engine what tiles should be collisible. Here is the function:

Level LoadLevelFromTxt(Level& LevRef)
{
        int length,height,bg;
        int stream = 1;
        bool maptrg = true;
        std::ifstream FileStream("Levels.txt");
        if (FileStream.is_open())
        {
                if( FileStream.good())
                {
                        FileStream >> length;
                        FileStream >> height;
                        FileStream >> bg;
                        LevRef.TileMap.resize(height);
                        for(int q = 0; q < height; q++)
                        {
                                LevRef.TileMap[q].resize(length);
                        }
                        for(int i = 0; i < height; i++)
                        {
                                for(int c = 0; c < length; c++)
                                {
                                        stream = FileStream.get();
                                        FileStream.ignore(2,' ');
                                        if(stream == 0)maptrg = false;
                                        else if(stream == 1)maptrg = true;
                                        LevRef.TileMap[i][c] = maptrg;
                                }
                        }
                }
                FileStream.close();
        }
        Level TheLocalLevel(length,height,(LevelType)bg);
        return TheLocalLevel;
}

Here is the Dec of the Level construct.

struct Level
{
        int Length;
        int Height;
        LevelType Background;
        LevelType AltBackground;
        std::vector< std::vector <bool> > TileMap;
        Level::Level(int nLength,int nHeight,LevelType nBackground)
        {
                Length = nLength;
                Height = nHeight;
                Background = nBackground;
                AltBackground;
        }
        Level::Level()
        {};
};

Here is the txt

48
16
0
1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

The issue I am running into is that the maptrg never changes. The TileMaps elements always evaluates to maptrgs initial state.

As usual, respond with tips or if there is a better way to do this, feel free to tell me all 'bout it!

78
General / Re: 2d tile system using 2d std::vectors.
« on: June 01, 2012, 11:29:45 am »
Just replying to post my solution if someone else runs into this problem.

void rCreateBackground(Level& theLevel, std::vector<std::vector<sf::Sprite> >& BackgroundVector, sf::Image& bgtile)
{
        BackgroundVector.resize(theLevel.Height);
        for (int i = 0; i < theLevel.Height; i++)
        {
                BackgroundVector[i].resize(theLevel.Length);
        }
       
        for (int j = 0; j < theLevel.Height; j++)
        {
                for (int c = 0; c < theLevel.Length; c++)
                {
                        BackgroundVector[j][c].SetImage(bgtile);
                        BackgroundVector[j][c].SetPosition(c * bgtile.GetWidth(), j * bgtile.GetHeight());
                }
        }
}

Thank you Laurent, who takes the time to reply to my retarded questions :)

79
General / Re: 2d tile system using 2d std::vectors.
« on: May 25, 2012, 03:47:36 pm »
Huh yeah, that solved it. ^^ Now do you have any tips on how to iterate through the elements and set every sprite to the same image and/or modify the the position? I was thinking of a nested loop(similar to the init loop) would that work?

80
General / Re: 2d tile system using 2d std::vectors.
« on: May 25, 2012, 12:24:11 pm »
I removed the last line ^^ but then I get another error message namely:
1>c:\Program Files\Microsoft Visual Studio 9.0\VC\include\vector(528) : error C2440: 'type cast' : cannot convert from 'int' to 'sf::Sprite'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous
1>        c:\Program Files\Microsoft Visual Studio 9.0\VC\include\vector(514) : see reference to function template instantiation 'void std::vector<_Ty>::_Construct<_Iter>(_Iter,_Iter,std::_Int_iterator_tag)' being compiled
1>        with
1>        [
1>            _Ty=sf::Sprite,
1>            _Iter=int
1>        ]
1>        .\main.cpp(107) : see reference to function template instantiation 'std::vector<_Ty>::vector<int>(_Iter,_Iter)' being compiled
1>        with
1>        [
1>            _Ty=sf::Sprite,
1>            _Iter=int
1>        ]


The function itself will be used to loop through a 2d vector of sf::sprites with the size [theLevel.length][theLevel.height]
Each sprite will have the image corresponding to the backgroundtype (which is an enum part of theLevel),
and a x,y position corresponding to it's position in [length] * sprite width and its position in y in [height] * sprite height.

81
General / 2d tile system using 2d std::vectors.
« on: May 25, 2012, 11:35:56 am »
Hello everyone, I'm back and once again I need help from the wise persons on this forum. More specifically I need help with getting my 2d tiling system working.

I've been trying to use a 2d vector, but this stuff is fiendishly hard. I'm currently loading info from a txt file which i then put into a struct called Level which contains the type, length and height of the level. Then I try to put this info into a 2d vector, which I will then use to render.

Right now I'm am running into problem when resizing, and assigning values to the different elements of the vectors. The reason I am using a vector is that in the future I will most likely need to add more complicated backgrounds (as opposed to right now where I assume that every tile will use the same image).

Here is the code that I think is relevant.

Vector Dec
std::vector< std::vector <sf::Sprite> > BackGround(4, std::vector<sf::Sprite>(4,0));
std::vector< std::vector <sf::Sprite> >& BGPTR = BackGround;

Level LoadLevelFromTxt()
{
        int length,height,bg;
        std::ifstream FileStream("Levels.txt");
        if (FileStream.is_open())
        {
                if( FileStream.good())
                {
                        FileStream >> length;
                        FileStream >> height;
                        FileStream >> bg;
                }
                FileStream.close();
        }
        Level TheLocalLevel(length,height,(LevelType)bg);
        return TheLocalLevel;
}

void CreateBackground(Level& theLevel, std::vector<std::vector<sf::Sprite> >& BackgroundVector)
{
        BackgroundVector.resize(theLevel.Height);
        for (int i = 0; i < theLevel.Height; i++)
        {
                BackgroundVector[i].resize(theLevel.Length);
        }
        std::vector<std::vector<sf::Sprite> >::iterator iter;
        std::vector<std::vector<sf::Sprite> >::iterator itertwo;
        iter = BackgroundVector.begin();
        itertwo = BackgroundVector.at(0);
}

Currently I'm getting this error when compiling:
1>.\main.cpp(644) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)
1>        with
1>        [
1>            _Ty=sf::Sprite
1>        ]
1>        c:\Program Files\Microsoft Visual Studio 9.0\VC\include\vector(405): could be 'std::_Vector_iterator<_Ty,_Alloc> &std::_Vector_iterator<_Ty,_Alloc>::operator =(const std::_Vector_iterator<_Ty,_Alloc> &)'
1>        with
1>        [
1>            _Ty=std::vector<sf::Sprite>,
1>            _Alloc=std::allocator<std::vector<sf::Sprite>>
1>        ]
1>        while trying to match the argument list '(std::_Vector_iterator<_Ty,_Alloc>, std::vector<_Ty>)'
1>        with
1>        [
1>            _Ty=std::vector<sf::Sprite>,
1>            _Alloc=std::allocator<std::vector<sf::Sprite>>
1>        ]
1>        and
1>        [
1>            _Ty=sf::Sprite
1>        ]

If someone could help me, I would be extremly grateful!

82
General / Re: Linking, relative paths and sharing projects.
« on: May 05, 2012, 10:28:09 pm »
That is very true, now that you mention it. ^^ Tyvm for the help! And I will try to read some articles about headers, linking and libs.

83
General / Re: Linking, relative paths and sharing projects.
« on: May 04, 2012, 10:02:39 pm »
In my SFML tutorial, I set it up so SFML is included and set up to link using relative paths, so you can just download the zip, open the solution and be off to the races.

If you check out part 1, you can see an example ( with screenshots ) of setting up a project to be relative pathed.  The settings are for C++ and the Linker.  The example is in Visual Studio 2010, but 2008 is close enough you should be fine.

Yea, but would that work if I just want to send the binaries to someone?

84
General / Re: Linking, relative paths and sharing projects.
« on: May 04, 2012, 10:01:44 pm »
Before reading this I would like to state that I have no idea what DLLs do, or how they do it.
With that said.

Can you do that?
I mean since I in the code link directly using
#include "Graphics.hpp"
#include "System.hpp"
Wont it just return a file not found error?

85
General / Re: Linking, relative paths and sharing projects.
« on: May 04, 2012, 11:09:52 am »
Sorry, should include that. I just want to send the binaries, and I'm using Visual C++ 2008 Express

86
General / Linking, relative paths and sharing projects.
« on: May 04, 2012, 10:37:42 am »
So I've worked on a project and I want to send a release version to a friend so that he can see what I have done. However I don't really get how I would be able to link to SFML. I've heard of relative paths but there are no good guides about it on the internet that I could find.

The project is located in C:\Users\Olle\Desktop\C++\PAR SFML\New Game\New Game
and the sfml I want to link to is in C:\Users\Olle\Desktop\C++\PAR SFML\New Game
If I was to transfer the release folder to another computer and include a SFML-1.6\SFML in the same folder so that it would C:\Users\Something\New Game as a parent folder with two folders (SFML-1.6 and Release folders). How would I link to the SFML?

If there is anyone who can help me, alternatively provide me with a better way to organise/put together my project please do.

Sorry if the question is unclear.

87
General / Re: Determing top/bottom and side collision
« on: April 25, 2012, 10:08:29 pm »
Ah ok, well I will check around on the internet about this mysterious "tunneling" then ^^. Thank you for the information.

Cool, if you run into any weird problems with this function feel free to send me a pm :)

88
General / Re: Determing top/bottom and side collision
« on: April 25, 2012, 09:40:41 pm »
After about a week of tweaking the function I finally found something which works in 99.9% of all collisions. The only time that this code doesnt work is at veeeeeeery high speeds. Anyhow here is the code. If anyone would like to use it feel free to do so.

bool ADVBoxCollision(sf::gEntity& player, sf::gEntity& sprite2, bool& pTop, bool& pSide)
{
        bool Firsttotheleft = false;
        bool Firsttotheright = false;
        bool Firstabove = false;
        bool Firstbelow = false;
        sf::FloatRect FirstRect = sf::FloatRect(player.GetPosition().x - (player.GetSize().x/2), player.GetPosition().y - (player.GetSize().y/2),player.GetPosition().x + (player.GetSize().x/2),player.GetPosition().y+(player.GetSize().y/2));
        sf::FloatRect SecondRect = sf::FloatRect(sprite2.GetPosition().x - (sprite2.GetSize().x/2), sprite2.GetPosition().y - (sprite2.GetSize().y/2),sprite2.GetPosition().x + (sprite2.GetSize().x/2),sprite2.GetPosition().y+(sprite2.GetSize().y/2));
        //ToS stands for Top or side. It tells whether the sprite collided with the top/bottom part or the side part. 0 = top/bottom, 1 = sides
if(BoxCollision(FirstRect, SecondRect))
        {
                if((FirstRect.Left - 20) <= (SecondRect.Left - FirstRect.GetWidth()))
                        Firsttotheleft = true;
                if((FirstRect.Right + 20) >= (SecondRect.Right + FirstRect.GetWidth()))
                        Firsttotheright = true;
                if((FirstRect.Top - 20) <= (SecondRect.Top - FirstRect.GetHeight()))
                        Firstabove = true;
                if((FirstRect.Bottom + 20) >= (SecondRect.Bottom + FirstRect.GetHeight()))
                        Firstbelow = true;
                if(Firstbelow || Firstabove)
                        pTop = true;
                if(Firsttotheright || Firsttotheleft)
                        pSide = true;
                return BoxCollision(FirstRect, SecondRect);
        }
        else return false;
}
bool ADVBoxCollision(sf::FloatRect FirstRect, sf::FloatRect SecondRect, bool& pTop, bool& pSide)
{
        bool Firsttotheleft = false;
        bool Firsttotheright = false;
        bool Firstabove = false;
        bool Firstbelow = false;
        this->RECT1 = FirstRect;
        this->RECT2 = SecondRect;
        //ToS stands for Top or side. It tells whether the sprite collided with the top/bottom part or the side part. 0 = top/bottom, 1 = sides
        if(BoxCollision(FirstRect, SecondRect))
        {
                if((FirstRect.Left - 20) <= (SecondRect.Left - FirstRect.GetWidth()))
                        Firsttotheleft = true;
                if((FirstRect.Right + 20) >= (SecondRect.Right + FirstRect.GetWidth()))
                        Firsttotheright = true;
                if((FirstRect.Top - 20) <= (SecondRect.Top - FirstRect.GetHeight()))
                        Firstabove = true;
                if((FirstRect.Bottom + 20) >= (SecondRect.Bottom + FirstRect.GetHeight()))
                        Firstbelow = true;
                if(Firstbelow || Firstabove)
                        pTop = true;
                if(Firsttotheright || Firsttotheleft)
                        pSide = true;
                return BoxCollision(FirstRect, SecondRect);
        }
        else return false;
}

(the RECT1 and RECT2 are members of the physics manager which I've created, so ignore/delete those calls if you feel like it)

Anyhow, tyvm for the help I got and for the tip to use references instead of pointers.

89
General / Re: Determing top/bottom and side collision
« on: April 19, 2012, 09:39:25 am »
So, if anyone happens to through their eye over here I'll just keeping detailing what I'm doing.

I decided to reset the bool at the start of every frame, instead pf at every collision. Furthermore I'm making the sprites borders "bigger" by adding +4 or something like that in the if call, so that the intended switch opportunity is detected better.

90
General / Re: Determing top/bottom and side collision
« on: April 17, 2012, 10:07:51 am »
Ty for the help. I rewrote the program to use references instead, and I had to change some other functions, so I haven't been able/ found it neccesary to write again ^^

Also BoxCollision is a simple call to a function which checks if the two rects sent as parameters intersect.

The problem is I think, that if the rects collide then both the if statements evaluate to true.
What I would be looking for then would be something that would only evaluate to true if it was to the side or only evaluate to true if it was top.
Using a if/else if could work, buuuut I think that the first statement would always go to true. Anyhow I'll go back to coding and see if I find anything.

Pages: 1 ... 4 5 [6] 7