Map Creation Size Error
Hye ! So, I'm working at inventing my own tile map creation and I got a
problem on size. The max for it (which I not set) is <700x700 . Anything
higher makes it crash . Firstly I thought it's something i got wrong when
making the "presentation version" which outputs the result on screen ->
ScreenShot , but now I just finished making it more compact and tried
using 800x800 and it still has the 7 limit , but I have no idea why !
Since the code isn't that big I'll just throw it all here , please don't
yell at me . And if you have some tips I don't mind taking them !
#include <iostream>
#include <string.h>
#include <fstream>
#include <ctime>
#include <cstdlib>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#define _WIN32_WINNT 0x0501
#include <windows.h>
using namespace std;
int main()
{
sf::Vector2i Size;
int Points,rands,PointsCheck=1,x,y,RandX,RandY,CurrentNumber=1;
srand(time(0));
bool Done=false,Expanded,Border;
ofstream Out("txt.txt");
/***/
cout << "Size X-Y = "; cin >> Size.x >> Size.y;cout << endl;
cout << "MAX Points - " << (Size.x*Size.y)/10 << endl;
cout << "Number of POINTS = ";cin >> Points ;cout << endl;
/***/
int PixelMap[Size.x+1][Size.y+1];
/***/
for (x=1;x<=Size.x;x++) for (y=1;y<=Size.y;y++) PixelMap[x][y]=0;
/***/
while(PointsCheck<=Points)
{
rands=1+(rand()%10);
RandX=1+(rand()%(Size.x));RandY=1+(rand()%(Size.y));
if (rands==1 && PointsCheck<=Points && PixelMap[RandX][RandY]==0)
{PixelMap[RandX][RandY]=CurrentNumber;CurrentNumber+=2;PointsCheck++;}
}
/***/
while(Done==false)
{
Done=true;
for(x=1;x<=Size.x;x++)
for(y=1;y<=Size.y;y++)
if(PixelMap[x][y]%2!=0 && PixelMap[x][y]!=-1)
{
if (y!=0 && y!=Size.y && x!=0 && x!=Size.x && PixelMap[x+1][y]==0)
PixelMap[x+1][y]=PixelMap[x][y]+1;
if (y!=0 && y!=Size.y && x!=0 && x!=Size.x && PixelMap[x-1][y]==0)
PixelMap[x-1][y]=PixelMap[x][y]+1;
if (y!=0 && y!=Size.y && x!=0 && x!=Size.x && PixelMap[x][y+1]==0)
PixelMap[x][y+1]=PixelMap[x][y]+1;
if (y!=0 && y!=Size.y && x!=0 && x!=Size.x && PixelMap[x][y-1]==0)
PixelMap[x][y-1]=PixelMap[x][y]+1;
}
for(x=1;x<=Size.x;x++)
for(y=1;y<=Size.y;y++)
if(PixelMap[x][y]!=0 && PixelMap[x][y]%2==0)
{PixelMap[x][y]--;Done=false;}
for(x=1;x<=Size.x;x++)
for(y=1;y<=Size.y;y++)
if(PixelMap[x][y]%2!=0 && PixelMap[x][y]!=-1)
{
Expanded=false;Border=false;
if (PixelMap[x+1][y]==0) Expanded=true;
else if (PixelMap[x-1][y]==0) Expanded=true;
else if (PixelMap[x][y+1]==0) Expanded=true;
else if (PixelMap[x][y-1]==0) Expanded=true;
if (Expanded==false && PixelMap[x+1][y]%2!=0 &&
PixelMap[x+1][y]!=PixelMap[x][y] && PixelMap[x+1][y]!=-1)
Border=true;
else if (Expanded==false && PixelMap[x-1][y]%2!=0 &&
PixelMap[x-1][y]!=PixelMap[x][y] && PixelMap[x-1][y]!=-1)
Border=true;
else if (Expanded==false && PixelMap[x][y+1]%2!=0 &&
PixelMap[x][y+1]!=PixelMap[x][y] && PixelMap[x][y+1]!=-1)
Border=true;
else if (Expanded==false && PixelMap[x][y-1]%2!=0 &&
PixelMap[x][y-1]!=PixelMap[x][y] && PixelMap[x][y-1]!=-1)
Border=true;
if (Expanded==false && Border==true) PixelMap[x][y]=-1;
}
}
for(x=1;x<=Size.x;x++){
for(y=1;y<=Size.y;y++)
{Out << PixelMap[x][y] << " ";}Out << endl;}
//ShowWindow (GetConsoleWindow(), SW_HIDE);
}
No comments:
Post a Comment