When going to the right or top side of the screen (left or up arrow keys. Something unexpected happens. I cannot describe it very well, but the right and down side work perfectly.
Try the attached zip file to see what i mean.
Here is the relevant code:
Creates the map:
void mxCreateMap(char mapName[], int mapWidth, int mapHeight)
{
int xTiles;
int yTiles;
myTiles.tileDepth=0;
pixelWidth=mapWidth*89;
pixelHeight=mapHeight*89;
for(yTiles=0;yTiles<mapHeight+1;yTiles++)
{
for (xTiles=0;xTiles<mapWidth+1;xTiles++)
{
if(yTiles>myTiles.tileDepth || myTiles.tileDepth==0)
mxLoadNextSet();
memMap[xTiles][yTiles]=mxReturnTile(xTiles, yTiles);
}
}
}
Determines what tile is placed (working)
int mxReturnTile(int xTiles, int yTiles)
{
int myRandom;
myRandom=rand() % 10000+1;
if (xTiles==0 && yTiles>=2)
return tileRock;
if (xTiles==(pixelWidth/89) && yTiles>=2)
return tileRock;
if (yTiles==(pixelHeight/89) && yTiles>=2)
return tileRock;
if (yTiles <2)
return tileSky;
else if (xTiles==0 && yTiles>=2)
return tileRock;
else if (xTiles==(pixelWidth/89)-1 && yTiles>=2)
return tileRock;
else if ((myRandom>=2) && (myRandom<=myTiles.maxDirt))
return tileDirt;
else if ((myRandom>myTiles.maxDirt) && (myRandom<=myTiles.maxBronze))
return tileBronze;
else if ((myRandom>myTiles.maxBronze) && (myRandom<=myTiles.maxSilver))
return tileSilver;
else
return tileGold;
}
Builds whats on the screen (not working as expected)
void mxBuildGrid(void)
{
int spriteCount=1;
for (int yTile=-1;yTile<(dbScreenHeight()/89)+3;yTile++)
{
for (int xTile=-1;xTile<(dbScreenWidth()/89)+3;xTile++)
{
if (xTile>=0 && yTile>=0)
dbSprite(spriteCount,(xTile*89)-xOffset,(yTile*89)-yOffset,memMap[xTile+xPos][yTile+yPos]);
else if (yTile<2)
dbSprite(spriteCount,(xTile*89)-xOffset,(yTile*89)-yOffset,tileSky);
else if (yTile>=2)
dbSprite(spriteCount,(xTile*89)-xOffset,(yTile*89)-yOffset,tileRock);
spriteCount++;
}
}
}
Processes Arrow keys :
void mxProcessRight(void)
{
if (xPos<=(pixelWidth-dbScreenWidth())/89)
xOffset+=3;
if (xPos ==((pixelWidth-dbScreenWidth())/89) && (xOffset>89))
xOffset=89;
if (xOffset>89)
{
xOffset=0;
if (xPos <(pixelWidth-dbScreenWidth())/89)
xPos++;
}
}
void mxProcessLeft(void)
{
if (xPos>=0)
xOffset-=3;
if (xOffset<0 && xPos==0)
xOffset=0;
if (xOffset<-89)
{
xOffset=0;
if (xPos>=0)
xPos--;
}
}
void mxProcessUp(void)
{
if (yPos>=0)
yOffset-=3;
if (yOffset<0 && yPos==0)
yOffset=0;
if (yOffset<-89)
{
yOffset=0;
if (yPos>0)
yPos--;
}
}
void mxProcessDown(void)
{
if (yPos<=(pixelHeight-dbScreenHeight())/89)
yOffset+=3;
if (yPos ==((pixelHeight-dbScreenHeight())/89) && (yOffset>89))
yOffset=89;
if (yOffset>89)
{
yOffset=0;
if (yPos <(pixelHeight-dbScreenHeight())/89)
yPos++;
}
}
Your help would be greatly appreciated as I have been working on this for sometime and am stuck : ) Thanks