Ok, I made a little array based method for creating 2D maps for my game. I got it to work pretty good. But the method for drawing the sprite in the correct spot is rather... lengthy.
I was wondering if anyone could figure out a way to shorten this up at all. A 2x2 map is taking almost a hundred lines just to draw the tiles. Look in the case statements, thats where its long.
char* cna_Map1[5];
void CreateLayer1()
{
int charNum = 0;
int stringNum = 0;
int ID = 1;
cna_Map1[0] = "01";
cna_Map1[1] = "10";
dbSetSpritePriority( 1, 1 );
dbSetSpritePriority( 2, 1 );
dbSetSpritePriority( 3, 1 );
for ( stringNum = 0; stringNum < 2; stringNum++ )
{
for ( charNum = 0; charNum < 2; charNum++ )
{
switch ( cna_Map1[ stringNum ][ charNum ] )
{
case '0':
{
if ( stringNum == 0 && charNum == 0 )
dbSprite( ID, 0, 0, 1 );
ID = ID + 1;
if ( stringNum == 0 && charNum == 1 )
dbSprite( ID, 32, 0, 1 );
ID = ID + 1;
if ( stringNum == 1 && charNum == 0 )
dbSprite( ID, 0, 32, 1 );
ID = ID + 1;
if ( stringNum == 1 && charNum == 1 )
dbSprite( ID, 32, 32, 1 );
ID = ID + 1;
}
break;
case '1':
{
if ( stringNum == 0 && charNum == 0 )
{
dbSprite( ID, 0, 0, 2 );
ID = ID + 1;
}
else if ( stringNum == 0 && charNum == 1 )
{
dbSprite( ID, 32, 0, 2 );
ID = ID + 1;
}
else if ( stringNum == 1 && charNum == 0 )
{
dbSprite( ID, 0, 32, 2 );
ID = ID + 1;
}
else if ( stringNum == 1 && charNum == 2 )
{
dbSprite( ID, 32, 32, 2 );
ID = ID + 1;
}
}
break;
case '2':
{
if ( stringNum == 1 && charNum == 1 )
{
dbSprite( ID, 0, 0, 3 );
ID = ID + 1;
}
else if ( stringNum == 1 && charNum == 2 )
{
dbSprite( ID, 32, 0, 3 );
ID = ID + 1;
}
else if ( stringNum == 2 && charNum == 1 )
{
dbSprite( ID, 0, 32, 3 );
ID = ID + 1;
}
else if ( stringNum == 2 && charNum == 2 )
{
dbSprite( ID, 32, 32, 3 );
ID = ID + 1;
}
}
break;
}
}
}
}
Sorry if my code is rather sloppy and noobish haha. CC is welcome as always.