Ok i noticed something a little akward when doing sprite collision. I have the following piece of code:
//Char Sprite
dbCreateAnimatedSprite(1,"gfx/sq.PNG",4,1,1);
int x,y;
x = 100;
y = 300;
dbSprite(1,x,y,1);
dbSetSpritePriority(1,1);
//Enemy Sprite
dbCreateAnimatedSprite(2,"gfx/sq2.PNG",4,1,2);
int x2,y2;
x2 = 500;
y2 = 300;
dbSprite(2,x2,y2,2);
dbSetSpritePriority(2,1);
.........................
if(dbSpriteCollision(1,2) & dbSpaceKey())
{
if(dbSpriteX(2) >= dbSpriteX(1))
{
x2 += 4;
}
if(dbSpriteX(2) <= dbSpriteX(1))
{
x2 -= 4;
}
//dbSizeSprite(201,dbSpriteScaleX(201)-1,36);
}
if(dbSpriteCollision(1,2) & dbControlKey())
{
if(dbSpriteX(1) <= dbSpriteX(2))
{
x += 4;
}
if(dbSpriteX(1) >= dbSpriteX(2))
{
x -= 4;
}
}
Now i move those psrites using W A S D and the arrows, but that code only works when my second sprites moves into the first one. Yes i changed sprite colision from 2,1 to 1,2 but it is the same thing.
What i wanted to do is check if space key is pressed and if those 2 sprites colided. If so then i want to move the second sprite 4 pixels back. If control was pressed then the first sprite should move 4 pixels back. Any ideas how to solve this problem?