Hey all
I recently got the Enemy1 Struct array working and now i got multiple enemies with the same base.. xD
So.. After the includes i added:
float En1X [10] = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100};
float En1Y [10] = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100};
This is the Enemies (array of enemy1) Spawn Positions. Each one for each enemy.
So, you can see that there are 10 values for X and for Y.
So at the LoadEnemy function i got:
void Enemy1::LoadEnemy(int PosID)
{
int rnd = GetFreeSpriteID();
id = rnd + 200 + dbRnd(EnemyCount + 10);
dbLoadImage("enemy1.png", id);
//speed = -0.5 * round; //Just using the speed 0 for testing the spawn position.
speed = 0;
score = 100;
hp = 100;
spawnX = En1X[PosID]; //Here i got the SpawnX of the array previously created...
spawnY = En1Y[PosID];
int reload = PosID;
sizeX = 35;
sizeY = 10;
cSpawn = true;
alive = true;
}
Then in the Spawn i simply got this:
void Enemy1::Spawn()
{
dbSprite(id, spawnX, spawnY, id);
}
I also have at the Main Function:
for(int n = 0;n<10;n++)
{
enemy1[n].LoadEnemy(n);
}
So basicly this will Load the array and automaticly points that enemy array "id" and checks that ID in the Position arrays..
It should work right?
Well the problem is they are not spawning at that positions.
Here's all the positions:
Enemy1: 100 100
Enemy2: 100 100
Enemy3: 100 100
Enemy4: 100 100
Enemy5: 200 -600
Enemy6: 200 -600
Enemy7: -400 700
Enemy8: 100 100
Enemy9: 100 100
Enemy10: 100 100
So the Enemy5, 6, and 7 are not spawning on their locations..
Why this happens?
Here you have the entire struct of the Enemy1:
struct Enemy1
{
public:
void LoadEnemy(int PosID);
void Spawn();
void Move(int LastX, int LastY);
void Update();
void Reload();
void DestroyEnemy(int spawwtime);
bool cSpawn;
bool alive;
float speed;
int hp;
int spawnX, spawnY;
int id;
int x, y, sizeX, sizeY;
int score;
}enemy1 [10];
/////////////////////////////////////////////////////////
/*
================================================
ENEMY 1
================================================
*/
void Enemy1::LoadEnemy(int PosID)
{
int rnd = GetFreeSpriteID();
id = rnd + 200 + dbRnd(EnemyCount + 10);
dbLoadImage("enemy1.png", id);
//speed = -0.5 * round;
speed = 0;
score = 100;
hp = 100;
spawnX = En1X[PosID];
spawnY = En1Y[PosID];
int reload = PosID;
sizeX = 35;
sizeY = 10;
cSpawn = true;
alive = true;
}
void Enemy1::Move(int LastX, int LastY)
{
PointSprite(id, LastX, LastY);
dbMoveSprite(id, speed);
}
void Enemy1::Update()
{
x = dbSpriteX(id);
y = dbSpriteY(id);
if(cSpawn)
{
Spawn();
EnemyCount += 1;
cSpawn = false;
}
if(!dbSpriteCollision(id, 1))
{
Move(player.x + player.SizeX, player.y + player.SizeY);
}
else
{
//remove player hp
}
}
void Enemy1::Spawn()
{
dbSprite(id, spawnX, spawnY, id);
}
void Enemy1::DestroyEnemy(int spawntime)
{
dbDeleteSprite(id);
}
void Enemy1::Reload()
{
}
C++ Medium 3.5/5
www.oryzhon.com <-- My company's website (W.I.P)