public override void Init() { EnemyDict.Clear(); foreach (EnemyBase enemy in EnemyList) { EnemyDict.Add(enemy.Id, enemy); CheckList(enemy.FearRaceList); CheckList(enemy.ResistRaceList); } }
public void SpawnOneEnemy(Byte index) { // TODO work out better the frame delay. UInt16 frameDelay = Constants.TestFrameDelay; //UInt16 frameDelay = MyGame.Manager.RandomManager.Next(MinDelay, MaxDelay); SByte slotID = Constants.INVALID_INDEX; while (true) { slotID = (SByte)MyGame.Manager.RandomManager.Next(Constants.MAX_ENEMYS_SPAWN); if (!EnemyDict.ContainsKey((Byte)slotID)) { break; } } // TODO delete //slotID = 0; // hard code slotID to test. MyGame.Manager.Logger.Info((slotID + 1).ToString()); Enemy enemy = EnemyList[index]; Vector2 position = enemy.Position; Byte randomX = (Byte)MyGame.Manager.RandomManager.Next(Constants.ENEMY_RANDOM_X); Byte randomY = (Byte)MyGame.Manager.RandomManager.Next(Constants.ENEMY_RANDOM_Y); UInt16 offsetX = EnemyOffsetX[(Byte)slotID]; UInt16 offsetY = EnemyOffsetY[(Byte)slotID]; position.X = randomX + offsetX; position.Y = randomY + offsetY; Rectangle bounds = EnemyBounds[(Byte)slotID]; enemy.Spawn((Byte)slotID, frameDelay, position, bounds); EnemyDict.Add((Byte)slotID, enemy); EnemySpawn++; }
public void SpawnOneEnemy(Byte index) { UInt16 frameDelay = enemyDelays[EnemySpawn]; Boolean enemyRotate = enemyRotates[EnemySpawn]; MoveType moveType = enemyMoves[EnemySpawn]; Byte theEnemySpeed = levelConfigData.EnemyVelocity; Byte slotID; while (true) { slotID = (Byte)MyGame.Manager.RandomManager.Next(Constants.MAX_ENEMYS_SPAWN); if (!EnemyDict.ContainsKey(slotID)) { break; } } // TODO delete //slotID = 0; // hard code slotID to test. //MyGame.Manager.Logger.Info((slotID+1).ToString()); // Retrieve the enemy from list. Enemy enemy = EnemyList[index]; Vector2 position = enemy.Position; Byte randomX = (Byte)MyGame.Manager.RandomManager.Next(Constants.ENEMY_RANDOM_X); Byte randomY = (Byte)MyGame.Manager.RandomManager.Next(Constants.ENEMY_RANDOM_Y); UInt16 offsetX = EnemyOffsetX[slotID]; UInt16 offsetY = EnemyOffsetY[slotID]; // This fits within [160,200] = [40,80] = [32,72] => [32 = 160-120-(2*4)] // [32,72] => [32 = 160-120-(2*4), 72 = 200-120-(2*4)] position.X = randomX + offsetX + Constants.BorderSize; position.Y = randomY + offsetY + Constants.BorderSize; // Implement bounds checking... Rectangle bounds = EnemyBounds[slotID]; if (position.X < bounds.Left) { position.X = bounds.Left; } if (position.X > bounds.Right) { position.X = bounds.Right; } if (position.Y < bounds.Top) { position.Y = bounds.Top; } if (position.Y > bounds.Bottom) { position.Y = bounds.Bottom; } enemy.Spawn(slotID, frameDelay, position, bounds, levelType, enemyRotate, moveType, theEnemySpeed); EnemyDict.Add(slotID, enemy); EnemySpawn++; }