Original Post
I'm writing a class to encapsulate a tile set for a hex-based game. I'm having some trouble parsing the one tile set .png file into individual tiles. This is my function thus far This is my .png file I am using ( It's very basic, and extremely small )
This is a blown up version
It seems that it doesn't work at all.
public void load( String filename )
{
this.filename = filename;
File file = new File( filename );
BufferedImage whole_set = null;
try
{
whole_set = ImageIO.read( file );
}
catch ( Exception e )
{
e.printStackTrace();
System.exit( 1 );
}
final int CORNER = 0xFFFFFF00; // yellow
final int ANCHOR_X = 0xFFFF00FF;// magenta
final int ANCHOR_Y = 0xFF00FF00; // green
int start_x[] = new int[ 256 ];
int start_y[] = new int[ 256 ];
int end_y[] = new int[ 256 ];
int end_x[] = new int[ 256 ];
int anchor_x[] = new int[ 256 ];
int anchor_y[] = new int[ 256 ];
int x_counter = 0;
int y_counter = 0;
int a_x_counter = 0;
int a_y_counter = 0;
if ( whole_set.getRGB( 0,0 ) == CORNER && whole_set.getRGB( 1,0 ) == ANCHOR_X
&& whole_set.getRGB( 2,0 ) == ANCHOR_Y )
{
for ( int y = 1; y < whole_set.getHeight(); y++ )
for ( int x = 1; x < whole_set.getWidth(); x++ )
{
if ( whole_set.getRGB( x, y ) == CORNER )
{
if ( start_x[ x_counter ] == 0 )
{
start_x[ x_counter ] = x;
}
else
{
end_x[ x_counter ] = x;
start_x[ ++x_counter ] = x;
}
if ( start_y[ y_counter ] == 0 )
{
start_y[ y_counter ] = y;
}
else
{
end_y[ y_counter ] = y;
start_y[ ++y_counter ] = y;
}
}// end if
else if ( whole_set.getRGB( x, y ) == ANCHOR_X )
{
if ( anchor_x[ a_x_counter ] == 0 )
{
anchor_x[ a_x_counter++ ] = x;
}
}
else if ( whole_set.getRGB( x, y ) == ANCHOR_Y )
{
if ( anchor_y[ a_y_counter ] == 0 )
{
anchor_y[ a_y_counter++ ] = y;
}
}// end else
}// end for
if ( ( ( x_counter != y_counter ) || ( a_x_counter != a_y_counter ) ) || x_counter == 0 )
System.err.println( "it's fucked");
for ( int i = 0; i < x_counter; i++ )
{
int width = 0;
int height = 0;
if ( end_x[ i ] != 0 )
width = end_x[ i ] - start_x[ i ];
else
width = whole_set.getWidth() - start_x[ i ];
if ( end_y[ i ] != 0 )
height = end_y[ i ] - start_y[ i ];
else
height = whole_set.getHeight() - start_y[ i ];
BufferedImage sub = whole_set.getSubimage( start_x[ i ], start_y[ i ], width, height );
}
System.err.println( "it's not fucked");
}// end if
}// end load()
This is a blown up version
It seems that it doesn't work at all.