Click to See Complete Forum and Search --> : I am using WM_PAINT to draw a 2D array of ints into colors only draws 1 square - help


Icyculyr
March 4th, 2008, 12:35 AM
Ok, I am making a little 2D game for fun, I have squares of colors on my window for pathways such as grass, dirt, this is what I have:

(In my 2D iMap Array, the first 2 on the top line, is the one that gets drawn, but not the first two on the second line)

Variables:

#define COLOR_VOID RGB(0, 0, 0)
#define COLOR_WHITE RGB(255, 255, 255)
#define COLOR_DIRT RGB(162, 42, 42)
#define COLOR_GRASS RGB(151, 251, 151)
#define COLOR_PERSON RGB(255, 0, 0)
//VARIABLES
const int iTileX = 20;
const int iTileY = 20;
const int iTileViewX = 14;
const int iTileViewY = 14;
const int iTileHeight = 70;
const int iTileWidth = 70;
int iPlayerX = 0;
int iPlayerY = 0;
COLORREF iMapColors[3] = {COLOR_VOID, COLOR_DIRT, COLOR_GRASS};

int iMap[iTileX][iTileY] = {{0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};


And this is the actual code for painting it:

case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
int xInt = 0;
int yInt = 0;
int tmpInt = 0;
for (int i = 0; i < iTileX; i++)
{
for (int k = 0; k < iTileY; k++)
{
HBRUSH hbr = CreateSolidBrush(iMapColors[iMap[i][k]]);
RECT rect;
SetRect(&rect, iTileWidth*yInt, iTileHeight*xInt, (iTileWidth*yInt)+iTileWidth, (iTileHeight*xInt)+iTileHeight);
FillRect(hdc, &rect, hbr);
if (yInt+1 % iTileViewY == 0)
{
yInt = -1;
xInt += 1;
}
yInt += 1;
tmpInt += 1;
}
}
EndPaint(hWnd, &ps);
break;
}


Does anyone know the problem? it should draw more than one rectangle, it should draw 2...

Cheers

Icyculyr
March 4th, 2008, 01:42 AM
Fixed, I changed the SetRect line to SetRect(&rect, iTileWidth*k, iTileHeight*i, (iTileWidth*k)+iTileWidth, (iTileHeight*i)+iTileHeight);

and it worked..

Cheers