Alright so i came up with my map system which appears to work fine. But there is one problem, the very last tile of my map also appears as the first tile of my map. I cant figure out why at all. Any ideas?
Hopefully i have included all relevant code. There is three total layers but i have only included one. The rest look exactly the same.
// Reset variables
a = 0;
b = 0;
// Read File
string line;
ifstream myfile (\"Maps/Map1.map\");
if (myfile.is_open())
{
while ( myfile.good() )
{
++a;
getline (myfile,line);
FileContents[a] = line;
// Split By Commas
stringstream ss(FileContents[a]);
while (ss >> value)
{
++b;
MapData[b] = value;
ss >> comma;
}
}
myfile.close();
a = 0;
b = 0;
}
else MessageBox(NULL,\"Map File Missing\",\"Error\",NULL);
// Load Ground Layer
while ( YTile < 600)
{
++a;
dbSetSpriteFrame(1,MapData[a]);
dbPasteSprite(1,XTile,YTile);
XTile = XTile + 32;
if (XTile == 800)
{
YTile = YTile + 32;
XTile = 0;
}
}
// Reset Values
YTile = 0;
XTile = 0;
b = 0;
Here is the map file
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,5
So basically that 5 at the end is appearing correctly but then also appearing on tile 1 replacing the 2 tile.
Here is all my code. Probably irrelevant but if it helps.
#include \"DarkGDK.h\"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbDisableEscapeKey ( );
dbRandomize ( dbTimer ( ) );
// Screen Res
dbSetDisplayMode(800,600,32);
// Set Transparency
dbSetImageColorKey ( 255, 0, 255 );
// Variables
int a = 0; int b = 0;
string FileContents[500];
int MapData[1500];
int value;
char comma;
int XTile = 0;
int YTile = 0;
byte speed = 200;
byte LastMove = 0;
int x = 1; int y = 1;
// Ground Tileset
dbCreateAnimatedSprite(1,\"Tiles.png\",8,568,1);
// Mask Tileset
dbCreateAnimatedSprite(2,\"Tiles.png\",8,568,2);
// Player Sprite
dbCreateAnimatedSprite(3,\"Player.png\",4,4,3);
dbHideSprite(3);
// Fringe Tileset
dbCreateAnimatedSprite(4,\"Tiles.png\",8,568,4);
dbSprite(1,0,0,1);
while ( LoopGDK ( ) )
{
// Reset variables
a = 0;
b = 0;
// Read File
string line;
ifstream myfile (\"Maps/Map1.map\");
if (myfile.is_open())
{
while ( myfile.good() )
{
++a;
getline (myfile,line);
FileContents[a] = line;
// Split By Commas
stringstream ss(FileContents[a]);
while (ss >> value)
{
++b;
MapData[b] = value;
ss >> comma;
}
}
myfile.close();
a = 0;
b = 0;
}
else MessageBox(NULL,\"Map File Missing\",\"Error\",NULL);
// Load Ground Layer
while ( YTile < 600)
{
++a;
dbSetSpriteFrame(1,MapData[a]);
dbPasteSprite(1,XTile,YTile);
XTile = XTile + 32;
if (XTile == 800)
{
YTile = YTile + 32;
XTile = 0;
}
}
// Reset Values
YTile = 0;
XTile = 0;
b = 0;
// Load Mask Layer
while ( YTile < 600)
{
++a;
if (MapData[a] > 0)
{
dbSetSpriteFrame(2,MapData[a]);
dbPasteSprite(2,XTile,YTile);
}
XTile = XTile + 32;
if (XTile == 800)
{
YTile = YTile + 32;
XTile = 0;
}
}
// Reset Values
YTile = 0;
XTile = 0;
b = 0;
// Update Player Position. Must be done here to so it behind fringe. Using Paste Sprite instead of dbSprite becouse of sketchy priority commands.
dbPasteSprite(3,x,y);
// Check to prevent players leaving screen
if (x > 768)
{
dbPasteSprite(3,768,y);
x = 768;
}
if (x < 0)
{
dbPasteSprite(3,0,y);
x = 0;
}
if (y < 0)
{
dbPasteSprite(3,x,0);
y = 0;
}
if (y > 568)
{
dbPasteSprite(3,x,568);
y = 568;
}
// Load Fringe Layer
while ( YTile < 600)
{
++a;
if (MapData[a] > 0)
{
dbSetSpriteFrame(4,MapData[a]);
dbPasteSprite(4,XTile,YTile);
}
XTile = XTile + 32;
if (XTile == 800)
{
YTile = YTile + 32;
XTile = 0;
}
}
// Reset Values
YTile = 0;
XTile = 0;
b = 0;
if (dbLeftKey() == 1 && dbUpKey() == 0 && dbDownKey() == 0)
{
if (LastMove != 1) {dbSetSpriteFrame(3,5);}
dbPlaySprite(3,5,8,speed);
x--;
LastMove = 1;
}
if (dbRightKey() == 1 && dbUpKey() == 0 && dbDownKey() == 0)
{
if (LastMove != 2) {dbSetSpriteFrame(3,9);}
dbPlaySprite(3,9,12,speed);
x++;
LastMove = 2;
}
if (dbUpKey() == 1 && dbLeftKey() == 0 && dbRightKey() == 0)
{
if (LastMove != 3) {dbSetSpriteFrame(3,13);}
dbPlaySprite(3,13,16 ,speed);
y--;
LastMove = 3;
}
if (dbDownKey() == 1 && dbLeftKey() == 0 && dbRightKey() == 0)
{
if (LastMove != 4) {dbSetSpriteFrame(3,1);}
dbPlaySprite(3,1,4,speed);
y++;
LastMove = 4;
}
if (dbLeftKey() == 1 && dbUpKey() == 1)
{
if (LastMove != 5) {dbSetSpriteFrame(3,5);}
dbPlaySprite(3,5,8 ,speed);
x--; y--;
LastMove = 5;
}
if (dbLeftKey() == 1 && dbDownKey() == 1)
{
if (LastMove != 6) {dbSetSpriteFrame(3,5);}
dbPlaySprite(3,5,8 ,speed);
x--; y++;
LastMove = 6;
}
if (dbRightKey() == 1 && dbUpKey() == 1)
{
if (LastMove != 7) {dbSetSpriteFrame(3,9);}
dbPlaySprite(3,9,12 ,speed);
x++; y--;
LastMove = 7;
}
if (dbRightKey() == 1 && dbDownKey() == 1)
{
if (LastMove != 8) {dbSetSpriteFrame(3,9);}
dbPlaySprite(3,9,12 ,speed);
x++; y++;
LastMove = 8;
}
// If Escape Exit
if ( dbEscapeKey ( ) )
break;
// Update Screen
dbSync ( );
}
// Exit
return;
}
Entire map file
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
2,2,3,4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