Mireben, you have been quite the help! Thank you so much for your time and effort. Your first post about the 'distance calculation' and the 'dbPositionObject' where so helpful. Definitely makes the code a lot more compact.
Before I got your reply though, I did some trial and error of my own. I know that there can be a whole lot of things that can improve the code... but it works.
First, I set a bunch of arrays, at least what I think are arrays:
int MaxZombies = 5;
int NumberZombies = 0;
int N;
int HurtWait = 0;
int SP = 0;
int ZombSync;
int ZombAttackAnim;
int ZombDieAnim;
int ZombieAttack[] = {37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37};
int ZombieHealth[] = {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100};
int ZombDie[] = {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100};
int ZN[] = {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100};
int Distance[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int ZombMode[] = {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2};
bool ZombTing1[] = {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false};
bool ZombTing2[] = {true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true};
bool ZombTing3[] = {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false};
Then I remade the zombie function:
void Zombies(void)
{
if (NumberZombies < MaxZombies)
{
for ( N=0 ; N<10 ; N++ )
{
if (NumberZombies < MaxZombies)
{
NumberZombies += 1;
dbLoadObject("Media//Zombie_Walk_Forward.x", NumberZombies);
dbPositionObject(NumberZombies, dbRND(5000),200, dbRND(5000));
dbLoopObject ( NumberZombies );
dbSetObjectSpeed ( NumberZombies, 12500 + dbRND(5000));
dbLoadObject("Media//Zombie_Attack01.x", NumberZombies+50);
dbPositionObject(NumberZombies+50, dbRND(5000),200, dbRND(5000));
dbLoopObject ( NumberZombies+50 );
dbSetObjectSpeed ( NumberZombies+50, 8000 + dbRND(4000));
dbHideObject(NumberZombies+50);
dbLoadObject("Media//Zombie_Death_Front_Origin.x", NumberZombies+100);
dbPositionObject(NumberZombies+100, dbRND(5000),200, dbRND(5000));
dbSetObjectSpeed ( NumberZombies+100, 8000 + dbRND(4000));
dbHideObject(NumberZombies+100);
dbPositionCamera(oldx,oldy,oldz);
dbPositionObject(530,oldx,oldy,oldz);
}
}
}
ZombSync = 0;
for ( N=0 ; N<10 ; N++ )
{
if (ZombSync < MaxZombies)
{
ZombSync += 1;
float ground_height_enemy = dbGetTerrainGroundHeight(300,dbObjectPositionX(ZombSync),dbObjectPositionZ(ZombSync));
void FollowPath(int object, int waypoints);
{
if (PausedOn == true && LoopTing == true)
{
LoopTing = false;
dbStopObject(ZombSync);
dbStopObject(ZombSync+50);
}
if (PausedOn == false)
{
if (LoopTing == false)
{
LoopTing = true;
dbLoopObject(ZombSync);
dbLoopObject(ZombSync+50);
}
PlyrX = dbCameraPositionX();
PlyrZ = dbCameraPositionZ();
ZombX = dbObjectPositionX(ZombSync);
ZombZ = dbObjectPositionZ(ZombSync);
ComputeDistance( );
ZombAttackAnim = ZombSync+50;
ZombDieAnim = ZombSync+100;
dbPositionObject(ZombAttackAnim, dbObjectPositionX(ZombSync),dbObjectPositionY(ZombSync),dbObjectPositionZ(ZombSync));
dbRotateObject(ZombAttackAnim, dbObjectAngleX(ZombSync),dbObjectAngleY(ZombSync),dbObjectAngleZ(ZombSync));
dbPositionObject(ZombDieAnim, dbObjectPositionX(ZombSync),dbObjectPositionY(ZombSync),dbObjectPositionZ(ZombSync));
dbRotateObject(ZombDieAnim, dbObjectAngleX(ZombSync),dbObjectAngleY(ZombSync),dbObjectAngleZ(ZombSync));
if (ZombMode[ZombSync] == 1 && ZombTing1[ZombSync] == false)
{
ZombTing1[ZombSync] = true;
ZombTing2[ZombSync] = false;
ZombTing3[ZombSync] = false;
dbShowObject(ZombSync);
dbHideObject(ZombAttackAnim);
dbHideObject(ZombDieAnim);
dbSetObjectSpeed ( ZombSync, 12500 + dbRND(5000));
}
if (ZombMode[ZombSync] == 3 && ZombTing3[ZombSync] == false)
{
ZombTing1[ZombSync] = false;
ZombTing2[ZombSync] = false;
ZombTing3[ZombSync] = true;
dbHideObject(ZombSync);
dbHideObject(ZombAttackAnim);
dbShowObject(ZombDieAnim);
dbPlayObject(ZombDieAnim);
dbSetObjectSpeed ( ZombDieAnim, 8000 + dbRND(4000));
Kills = Kills + 1;
Combos = Combos + 1;
dbSync ( );
}
if (ZombMode[ZombSync] == 2)
{
if (ZombTing2[ZombSync] == false)
{
ZombTing1[ZombSync] = false;
ZombTing2[ZombSync] = true;
ZombTing3[ZombSync] = false;
dbHideObject(ZombSync);
dbShowObject(ZombAttackAnim);
dbHideObject(ZombDieAnim);
}
if (ZombieAttack[ZombSync] == 0 && Health > 0)
{
ZombieAttack[ZombSync] = 37;
if (ZombMode[ZombSync] == 2)
{
Health = Health - 5;
Combos = 0;
dbShowSprite(50);
HurtWait = 100;
SP = 0;
}
}
if (ZombieAttack[ZombSync] > 0)
{
ZombieAttack[ZombSync] -= 1;
}
}
if (ZombMode[ZombSync] == 1)
{
dbPointObject(ZombSync,dbCameraPositionX(),ground_height_enemy,dbCameraPositionZ());
dbPositionObject(ZombSync, dbObjectPositionX(ZombSync), ground_height_enemy, dbObjectPositionZ(ZombSync));
dbMoveObject(ZombSync,1);
dbRotateObject(ZombSync,dbObjectAngleX(ZombSync),dbObjectAngleY(ZombSync)+180,dbObjectAngleZ(ZombSync));
}
if (ZombMode[ZombSync] == 3)
{
if (ZombDie[ZombSync] > 0)
{
ZombDie[ZombSync] -= 1;
}
if (ZombDie[ZombSync] == 0 && ZN[ZombSync] > 0)
{
ZN[ZombSync] -= 1;
dbSetAlphaMappingOn(ZombDieAnim,ZN[ZombSync]);
if (ZN[ZombSync] % 10 == 0 || ZN[ZombSync] == 5)
{
dbPositionObject(ZombSync,dbObjectPositionX(ZombSync),dbObjectPositionY(ZombSync)-1,dbObjectPositionZ(ZombSync));
}
if (ZN[ZombSync] == 0)
{
dbPositionObject(ZombSync,dbObjectPositionX(ZombSync),dbObjectPositionY(ZombSync)-1,dbObjectPositionZ(ZombSync));
dbPositionObject(ZombSync, dbRND(5000),ground_height_enemy, dbRND(5000));
dbSetAlphaMappingOn(ZombDieAnim,100);
ZombieAttack[ZombSync] = 37;
ZombieHealth[ZombSync] = 100;
ZombDie[ZombSync] = 100;
ZN[ZombSync] = 100;
Distance[ZombSync] = 0;
ZombMode[ZombSync] = 2;
ZombTing1[ZombSync] = false;
ZombTing2[ZombSync] = true;
ZombTing3[ZombSync] = false;
}
}
}
}
}
}
}
if (ZombKillCount+5 == Kills)
{
ZombKillCount = Kills;
MaxZombies += 1;
}
char str1[200];
sprintf_s ( str1, 200, "Kills: %d", Kills);
dbText ( 0, 0, str1);
char str2[200];
sprintf_s ( str2, 200, "Combos: %d", Combos);
dbText ( 0, 20, str2 );
char str3[200];
sprintf_s ( str3, 200, "Zombies: %d", MaxZombies);
dbText ( 0, 40, str3 );
}
And rewrote the ComputeDistance function useing your advice:
void ComputeDistance(void)
{
int XX = PlyrX - ZombX;
int ZZ = PlyrZ - ZombZ;
int AA = dbSQRT(XX * XX + ZZ * ZZ);
if (AA > 40 && ZombMode[ZombSync] < 3)
{
ZombMode[ZombSync] = 1;
}
if (AA <= 40 && ZombMode[ZombSync] < 3)
{
ZombMode[ZombSync] = 2;
}
if (ZombieHealth[ZombSync] < 1)
{
ZombMode[ZombSync] = 3;
}
}
Now bear in mind that I wrote the code before I read your post, so it’s not as efficient as yours is, and I am going to change it up a bit.
For example, I'm creating a new zombie for each and every one of them, instead of useing 'dbCloneObect()'.