Edit: Hello! I just solved my problem, it just happens that I have forgotten to change
isReset bool back to false after reseting it therefore it was constantly reseting on update.
Hello, I’ve recently made a list on an enemies and whenever I reset/delete EnemyA’s list it won’t update or do movement, the enemies. Help? Thank you in advance to anyone who could help me/
Here’s the code:
Code for Reset, Add Enemy and the Update:
public void Reset()
{
playerLife = 1;
playerScore = 0;
EnemyA.Clear();
AddEnemyA();
}
public void AddEnemyA()
{
EnemyA = new List<Scripts.EnemyA>();
enemyRec = new List<Rectangle>();
int x = 0;
int y = 0;
enemySpeed = 2; // 8 max speed
for (int i = 1; i <= 5; i++)
{
Rectangle enemyR = new Rectangle(55 * i, 50, enemySize, enemySize);
enemyRec.Add(enemyR);
EnemyA.Add(new Scripts.EnemyA(enemyATexture, enemyR, enemySize, enemySpeed));
}
}
public void Update(GameTime gameTime)
{
//for gameStatus
if (playerLife <= 0)
{
gameOver = true; Reset();
}
else
{
gameOver = false;
}
if (playerLife!= 0)
{
Player.Update(gameTime);
//for enemy movements
foreach (Scripts.EnemyA eA in EnemyA)
{
eA.EnemyMovement();
}
}
}
public void EnemyMovement()
{
i++;
if (enemyRec.X >= 560)
{
enemyRec.X = 550;
Right = true;
addY();
}
if (enemyRec.X <= -10)
{
enemyRec.X = 0;
Right = false;
addY();
}
if (enemyRec.X <= 600 && Right == false) //going to Right
{
if (i == 2)
{
enemyRec.X = enemyRec.X + enemySpeed; i = 0;
}
}
if (enemyRec.X > -50 && Right == true) // to Left
{
if (i == 2)
{
enemyRec.X = enemyRec.X - enemySpeed; i = 0;
}
}
}