you want it to go to starting posisiton when it hits the other?:
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbSetDisplayMode(800, 600, 32);
dbSyncOn ( );
dbSyncRate ( 60 );
dbMaximiseWindow();
dbCreateAnimatedSprite(1, "archer.png", 2, 2, 1);
dbSprite(1, 0, 0, 1);
dbCreateAnimatedSprite(2, "imp.png", 2, 2, 2);
dbSprite(2, 800, 0, 2);
dbPlaySprite(2, 1, 4, 300);
dbLoadImage("arrow.png", 3);
dbSprite(3, dbSpriteX(1) + 30, 0, 3);
//Enemy's HP
int HP = 5;
// our main loop
while ( LoopGDK ( ) )
{
dbSprite(3, dbSpriteX(3)+5, 0, 3);
dbSprite(2, dbSpriteX(2)-1, 0, 2);
if(dbSpriteCollision(3, 2))
{
dbSprite(3, 0, 0, 3);
//Deduct HP if enemy was hit
HP--;
//dbPrint(dbStr(HP)); this will cause memory leak, use this instead:
char str[200];
sprintf_s ( str, 200, "%d", HP );
dbText ( X, Y, HP ); //or dbPrint, whatever
//If enemy has 0 HP it will disappear
if(HP == 0);
dbHideSprite(2); //you should do something else, not just hide it, because HP will keep decreasing
//and you probably dont want negative HP
}
// update the screen
dbSync ( );
}
return;
}