Make all turrets shoot at same time - Hayashikiyoi/SP2_DM2199 GitHub Wiki
-
After declaring a bullet as Bullet* Name[numOfBullets], initialize it as NULL and delete during exit.
-
Set collider box for it.
-
Implement the follow codes under Update.
-
`for(int i = 0; i<numOfNullet;++i)
{
if(bullet[i] && player->trigger(bullet[i])
{ if(!smtHappen) //smtHappen is a bool initialized as false under .h { player->DmgPlayer(damageAmount); smtHappen = true; //to make it so that player will get hit by one bullet at a time } bullet[i]->shoot = false; }
}`
-
`if(DelayTimer<0.1)
for(int i = 1; i <=2;++i)
bullet[i]->shootBullet(turretBody[i]->RotateToPlayer(player->position),turretBody[i]->Position);
for(int i = 1 ; i<= 2; ++i)
{
if(bullet[i]->shoot) { bullet[i]->bulletUpdate(dt); bullet[i]->updateCurPos(); }
}
if(DelayTimer>5) //The time set here is the rate of fire of turret
{ DelayTimer=0; for(int i =1;i<=2;++i) { bullet[i]->shoot = false; } }`
-
`if(smtHappen)
{
time+=dt; // time is a static float initialized as 0 if(time >5)
// the time set here should be the same as the rate of fire of turret to prevent player taking damage if they stand still while being attacked
{
time = 9;
smtHappen = false;
}
}`
// NOTE : remember to set a condition in render to only render bullets when they are true
// And also remember to set its position at the turret position and to set rotation.