I'm trying to create an NPC cat in the background that walks along specified coordinates and plays a short animation when it reaches them. I used the code from this post, and it works perfect for walking. Is there an easy way to add a non-blocking animation when each coordinate is reached? I would be very grateful for a code example. Thanks.
Here is my code:
Code: ags
Here is my code:
int xx[5];
int yy[5];
int Timer = 0;
function room_Load()
{
cCat.Walk(250, 120, eNoBlock, eWalkableAreas);
xx[0] = 250; // Start
yy[0] = 120;
xx[1] = 80; // POI 1
yy[1] = 140;
xx[2] = 120; // POI 2
yy[2] = 100;
xx[3] = 190; // POI 3
yy[3] = 30;
xx[4] = 220; // POI 4
yy[4] = 150;
}
function room_RepExec() {
if (Timer) { // if the character is waiting...
Timer--; // decrease our timer
if (!Timer) cCat.Walk(xx[0], yy[0], eNoBlock, eWalkableAreas);
return;
}
if (cCat.Moving) return;
if ((cCat.x == xx[0]) && (cCat.y == yy[0])) { // Start
int chance = Random(99) + 1; // 1-100
if (chance <= 25) cCat.Walk(xx[1], yy[1], eNoBlock, eWalkableAreas); // 25% chance of walking to POI 1-2-3-4
if (chance >= 26 && chance <= 50) cCat.Walk(xx[2], yy[2], eNoBlock, eWalkableAreas);
if (chance >= 51 && chance <= 75) cCat.Walk(xx[3], yy[3], eNoBlock, eWalkableAreas);
if (chance >= 76 && chance <= 100) cCat.Walk(xx[4], yy[4], eNoBlock, eWalkableAreas);
}
else if ((cCat.x == xx[1]) && (cCat.y == yy[1])) { // POI 1
int chance = Random(99) + 1; // 1-100
if (chance <= 33) cCat.Walk(xx[2], yy[2], eNoBlock, eWalkableAreas); // 33% chance of walking to POI 2-3-4
if (chance >= 34 && chance <= 66) cCat.Walk(xx[3], yy[3], eNoBlock, eWalkableAreas);
if (chance >= 67 && chance <= 100) cCat.Walk(xx[4], yy[4], eNoBlock, eWalkableAreas);
}
else if ((cCat.x == xx[2]) && (cCat.y == yy[2])) { // POI 2
int chance = Random(99) + 1; // 1-100
if (chance <= 33) cCat.Walk(xx[1], yy[1], eNoBlock, eWalkableAreas); // 33% chance of walking to POI 1-3-4
if (chance >= 34 && chance <= 66) cCat.Walk(xx[3], yy[3], eNoBlock, eWalkableAreas);
if (chance >= 67 && chance <= 100) cCat.Walk(xx[4], yy[4], eNoBlock, eWalkableAreas);
}
else if ((cCat.x == xx[3]) && (cCat.y == yy[3])) { // POI 3
int chance = Random(99) + 1; // 1-100
if (chance <= 33) cCat.Walk(xx[1], yy[1], eNoBlock, eWalkableAreas); // 33% chance of walking to POI 1-2-4
if (chance >= 34 && chance <= 66) cCat.Walk(xx[2], yy[2], eNoBlock, eWalkableAreas);
if (chance >= 67 && chance <= 100) cCat.Walk(xx[4], yy[4], eNoBlock, eWalkableAreas);
}
else if ((cCat.x == xx[4]) && (cCat.y == yy[4])) { // POI 4
int chance = Random(99) + 1; // 1-100
if (chance <= 33) cCat.Walk(xx[1], yy[1], eNoBlock, eWalkableAreas); // 33% chance of walking to POI 1-2-3
if (chance >= 34 && chance <= 66) cCat.Walk(xx[2], yy[2], eNoBlock, eWalkableAreas);
if (chance >= 67 && chance <= 100) cCat.Walk(xx[3], yy[3], eNoBlock, eWalkableAreas);
}
}