In my text game when the character has the same x and y co-ordinate as the enemy I am trying to delete them however this does not seem to be working as they will just move again even though they both landed on the same co-ordinates on that turn.
1 2 3 4 5 6 7 8 9 10 11
void Variables::killMonster(){
//checks for collision, if collision = true assign the monster NULL and delete NULL. *Not working
for (int d=1;d<10;d++){
if (cList[d]!=NULL){
if (cList[0]->x == cList[d]->x && cList[0]->y == cList[d]->y){
cList[d]=NULL;
delete cList[d];
}
}
}
}
I'm guessing that cList is a list of character pointers. If you assign the value of cList at position d = to NULL, you won't be able to delete the thing at that point. You'll want to delete it first, then assign it to NULL.
Hi pogrady thanks for your post, I just tried it and your suggestion did not work it just provided the same results as having the delete after assigning null