Skip to main content
GameDev.net gamedev.net
🔒 Locked

A switch that doesn't switch!

Started by _Sigma Nov 4, 2004 at 3:30 PM 3 replies 550+ views
Original Post
_Sigma
_Sigma
I'm trying to blt a surface depending on a value in an array, but nothing gets blted. Can anyone let me know whats wrong? Because I can't figure it out for the life of me! ;)
[source = "cpp"]
//tile macros
#define ID_GRASS 1
#define ID_DIRT 2
#define ID_FLOWER 3
...
//generate random terrain data
       for(int k = 0;k<25;k++)
       {
               for(int i = 0; i<19;i++)
               {
                       tile.TileInformation[k] = 1;//Random_Range(1,3);  //fill our array with random values

               }

       }
...
for(int y = 0;y<25;y++)
       {
               for(int x = 0; x<19;x++)
               {
                       switch(tile.TileInformation[x][y])
                       {
                               case ID_GRASS:
                                       tile.Grass.dest_rect.left = y*32;
                                       tile.Grass.dest_rect.right = tile.Grass.dest_rect.left + 32;
                                       tile.Grass.dest_rect.top = x*32;
                                       tile.Grass.dest_rect.bottom = tile.Grass.dest_rect.top + 32;

                                       DDback->Blt(&tile.Grass.dest_rect,//destination rectangle(coords)
                                                       tile.Grass.DDTile, //our DD surface
                                                       &tile.Grass.src_rect,//source RECT
                                                       DDBLT_WAIT,NULL); //params

                                       break;

                               case ID_DIRT:
                                       tile.Dirt.dest_rect.left = y*32;
                                       tile.Dirt.dest_rect.right = tile.Dirt.dest_rect.left + 32;
                                       tile.Dirt.dest_rect.top = x*32;
                                       tile.Dirt.dest_rect.bottom = tile.Dirt.dest_rect.top + 32;

                                       DDback->Blt(&tile.Dirt.dest_rect,//destination rectangle(coords)
                                                       tile.Dirt.DDTile, //our DD surface
                                                       &tile.Dirt.src_rect,//source RECT
                                                       DDBLT_WAIT,NULL); //params

                                       break;

                               case ID_FLOWER:
                                       tile.Flower.dest_rect.left = y*32;
                                       tile.Flower.dest_rect.right = tile.Flower.dest_rect.left + 32;
                                       tile.Flower.dest_rect.top = x*32;
                                       tile.Flower.dest_rect.bottom = tile.Flower.dest_rect.top + 32;

                                       DDback->Blt(&tile.Flower.dest_rect,//destination rectangle(coords)
                                                       tile.Flower.DDTile, //our DD surface
                                                       &tile.Flower.src_rect,//source RECT
                                                       DDBLT_WAIT,NULL); //params

                                       break;

                       }
                       
               }
       }

Muhammad Haggag
Muhammad Haggag
The initialization loop - the first one - assumes the array is 25 rows, 19 columns. The second loop assumes it's 19 rows, 25 columns.

If the first loop is correct, the line:
switch(tile.TileInformation[x][y])
should be:
switch(tile.TileInformation[y][x])

i.e. swap y and x.

_Sigma
_Sigma
hmm...that didn't seem to work
This is how its setup. Am I doing the int loops right?

class Tile{public:        RECT src_rect, dest_rect; //source and dest rectangles        LPDIRECTDRAWSURFACE7 DDTile; // contains the surfaces which contain the BMP files};class TileSet{public:  int TileInformation[25][19];  //contains data such as invalid tiles  Tile Grass;  Tile Flower;  Tile Dirt;};
Alpha_ProgDes
Alpha_ProgDes
how is your flip function looking?
and what version of DirectDraw are you using?

other than that the only thing wrong was your second loop, as a Coder said.

an example from MSDN:
RECT     rcSource, rcDest;DDBLTFX  ddbltfx;   ZeroMemory(&ddbltfx, sizeof(ddbltfx));ddbltfx.dwSize = sizeof(ddbltfx);ddbltfx.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT; rcSource.top = 0; rcSource.left = 0;rcSource.bottom = 100; rcSource.right = 200; rcDest.top = 0; rcDest.left = 201;rcDest.bottom = 100; rcDest.right = 401; HRESULT hr = lpDDS->Blt(&rcDest,                        lpDDS,                        &rcSource,                        DDBLT_WAIT | DDBLT_DDFX,                        &ddbltfx);

from your example at least, it seems that you don't have src_rect setup. that could be why nothing shows.
Beginner in Game Development?  Read here. And read here.  
_Sigma
_Sigma
source gets setup at class creation. its always 0,0,31,31

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.