I have been tinkering with this application I am working on for about 2 hours now and I have got to admit my head is about to explode. I can not pin point where my problem is, but I am almost certain my array or loops have something to do with it.
My map editor does a simple task, it waits for a mouse click and then plots a Tile according to your mouse position on a grid by 32x32 tile sets. Everything runs well and good till i get down to the bottom of the map and it starts to do some crazy things. It seems to wrap the value around and plot the tile at the top of the map instead.
I have NO idea where this problem starts, so here is my entire application if anyone is willing to give it a quick glance.
#include "DarkGDK.h"
#define Q 32
int MouseClick();
int Paint();
int X;
int Y;
int Tile[19][12];
int ID = 10;
int tX = 19;
int tY = 12;
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 40 );
dbDisableEscapeKey ( );
dbSetDisplayMode ( 800, 600, 32 );
dbDrawSpritesFirst();
dbLoadImage ( "backdrop.bmp", 1 );
dbLoadImage ( "Path_Dirt.bmp", 2 );
dbLoadImage ( "Path_Grass.bmp", 3 );
dbSprite ( 1, 0, 0, 1 );
dbSprite ( 2, 0, 420, 2 );
dbSprite ( 3, 0, 452, 3 );
// Set Tiles to 0 for Blank.
for ( int i = 0; i < tX; i++ )
{
for ( int o = 0; o < tY; o++ )
{
Tile[i][o] = 0;
}
}
while ( LoopGDK ( ) )
{
char* myt1 = dbStr(dbMouseX());
char* myt2 = dbStr(dbMouseY());
dbInk ( dbRGB(10, 255, 200), 0 );
dbText ( 32, 420, "Left Click" );
dbText ( 32, 452, "Right Click" );
dbText ( 32, 500, myt1 );
dbText ( 96, 500, myt2 );
MouseClick ( );
Paint ( );
if ( dbEscapeKey ( ) )
break;
dbSync ( );
}
for ( int i = 0; i < 30; i++ )
dbDeleteSprite ( i );
dbDeleteImage ( 1 );
return;
}
int Paint()
{
// Paint!
for ( int i = 0; i < tX; i++ )
{
for ( int o = 0; o < tY; o++ )
{
if ( Tile[i][o] == 1 )
dbPasteSprite( 2, i * Q, o * Q);
if ( Tile[i][o] == 2 )
dbPasteSprite( 3, i * Q, o * Q);
}
}
return 0;
}
int MouseClick()
{
// 1 = Dirt, 2 = Grass
if ( dbMouseClick() == 1 )
{
if ( dbMouseX() <= 608 && dbMouseX() >= 0
&& dbMouseY() <= 408 && dbMouseY() >= 0 )
{
X = dbMouseX() / 32;
Y = dbMouseY() / 32;
Tile[X][Y] = 1;
}
}
if ( dbMouseClick() == 2 )
{
if ( dbMouseX() <= 608 && dbMouseX() >= 0
&& dbMouseY() <= 408 && dbMouseY() >= 0 )
{
X = dbMouseX() / 32;
Y = dbMouseY() / 32;
Tile[X][Y] = 2;
}
}
return 0;
}
101 Lines, Hope you take the time to find my problem!
There are no special libraries other than dark GDK. I run it in VC++ 2008. If you want to copy past to see what I mean it may help you to help me!
Thanks in advanced for trying to help.