If you are making a side-scroller, you could make custom pixil collisions from each sprite. To do this, you would want to make a structure to hold the info:
struct COLLISIONSPRITE{
int Sprite,Image;//if you use the same index for each, only one is needed
byte SpriteWidth;
byte Height[256];//I assume you will have a max of 256x256 for sprite size
void InitSprite(char *FileName);
}*CollisionSprite;//you can make it a pointer or an array, whatever you like
COLLISIONSPRITE::InitSprite(char *FileName){
Sprite=FindFreeSprite();//the "FindFree" stuff will be covered later
Image=FindFreeImage();
dbLoadImage(FileName,Image);
dbSprite(Sprite,0,0,Image);//BTW you must use the original image size for the sprite....
dbHideSprite(Sprite);//this is important because you will have to "dbPasteSprite" to make this work correctly
//determine the collisions. We will use a memblock to do this
dbMakeMemblockFromImage(1,Image);
int sW=dbSpriteWidth(Sprite);
int sH=dbSpriteHeight(Sprite);
for (int W=0;W<sW;W++){
for (int H=0;H<sH;H++){
int pos=12+(H*sw+W)*4;
DWORD C=dbMemblockDword(1,pos);
if (C!=dbRGB(0,0,0)){//this color is whatever your transparent color is....
Height[W]=H-sH;//this is the height at that point
H=sH;//to break out of the height loop
}
}
}
dbDeleteMemblock(1);//you must delete the memblock or the next call will fail
}
As promissed, here is the "findfree" stuff:
int FindFreeImage(void){
int IN=0;
for (IN=1;IN<10000;IN++) if (dbImageExist(IN)==0) break;
return IN;
}
The same process is used to find a free sprite or object or whatever....
I assume you already have a method for making the map..... If not, just make an array for the "ground sprites" (I assume you need to collide with the ground). When moving along the ground, check to see where you are in your array of ground sprites and test the height of your character with respect to the ground height.
Here is the process I would use:
Make all your ground sprites the same width. This is the easiest mathematical approach. Place them sequentually from left to right, butting each one up to the previous one (this is not completely necessary because you could have gaps to fall through if you want). Because you are pasting sprites, you can use the same sprite as many times as you want without duplicating it in memory-- you loose one key funtionallity though: sprite collision. This won't be a problem, because you aren't using it anyway. As I said, you would put them in sequence, but you don't have to have them at the same Y value. This could be used to make slopes and walls.
This bit of info should spark some thought. If you need more detail, I will be happy to give you more.
The fastest code is the code never written.