Hello again,
I am currently working on a 2D game where I want the enemy to move closer to the player while it is alive.
Then, once the enemy is killed a certain number of times, move on to the next level where there will be 2 enemies (so on and so forth).
I got the code down for moving the first enemy, that is no problem. But I am stuck trying to figure out how I can increase the number of enemies while still only using this single function.
Also I would like the new enemy to be a different sprite on every level so its not just a bunch of the same looking enemy.
Here is my code so far:
void Enemy::enemyMovements()
{
//If no enemy, create one on one of the corners
if(dbSpriteExist(enemy)==0 && dbSpriteExist(player))
{
spawnLocationX = dbRND(1);
spawnLocationY = dbRND(1);
if(spawnLocationX == 0 && spawnLocationY == 0)
{
dbSprite(enemy,0,0,enemy);
dbMirrorSprite(enemy);
}
if(spawnLocationX == 1 && spawnLocationY == 0)
{
dbSprite(enemy,1105,0,enemy);
}
if(spawnLocationX == 0 && spawnLocationY == 1)
{
dbSprite(enemy,0,600,enemy);
dbMirrorSprite(enemy);
}
if(spawnLocationX == 1 && spawnLocationY == 1)
{
dbSprite(enemy,1105,600,enemy);
}
}
//Enemy AI
if(dbSpriteExist(enemy))
{
//Enemies X movements
if(dbSpriteX(enemy) < dbSpriteX(player))
{
dbRotateSprite(enemy,90);
dbMoveSprite(enemy,enemySpeed);
dbRotateSprite(enemy,0);
}
if(dbSpriteX(enemy) > dbSpriteX(player))
{
dbRotateSprite(enemy,270);
dbMoveSprite(enemy,enemySpeed);
dbRotateSprite(enemy,0);
}
//Enemies Y movements
if(dbSpriteY(enemy) < dbSpriteY(player))
{
dbMoveSprite(enemy,-(enemySpeed));
}
if(dbSpriteY(enemy) > dbSpriteY(player))
{
dbMoveSprite(enemy,enemySpeed);
}
}
//Kill enemy when shot
if(dbSpriteExist(enemy) && dbSpriteExist(bullet))
{
if(dbSpriteCollision(enemy,bullet))
{
dbDeleteSprite(bullet);
dbDeleteSprite(enemy);
enemiesKilled++;
if(enemySpeed <= maxEnemySpeed)
enemySpeed = (enemySpeed + 0.25);
else if(enemySpeed >= maxEnemySpeed)
{
enemySpeed = 1;
//level++;
}
}
}
}