public Vector2 GenerateValidCenter(int radius) { Vector2 spawnPosition = new Vector2(0, 0); do { spawnPosition.X = random.NextSingle(-CVars.Get <float>("screen_width") / 2 + radius, CVars.Get <float>("screen_width") / 2 - radius); spawnPosition.Y = random.NextSingle(-CVars.Get <float>("screen_height") / 2 + radius, CVars.Get <float>("screen_height") / 2 - radius); } while (IsTooCloseToPlayer(spawnPosition, radius)); return(spawnPosition); }
protected override void OnUpdate(float dt) { _timer.Update(dt); if (_timer.HasElapsed()) { Color randomColor = new HSLColor(_random.NextSingle(0, 240), 240, 120); EventManager.Instance.QueueEvent(new CreateExplosionEvent(new Vector2(_random.NextSingle(-CVars.Get <float>("screen_width") / 2, CVars.Get <float>("screen_width") / 2), _random.NextSingle(-CVars.Get <float>("screen_height") / 2, CVars.Get <float>("screen_height") / 2)), randomColor, false)); _timer.Reset(_random.NextSingle(0.005f, 0.001f)); //_timer.Reset(5); } base.OnUpdate(dt); }
protected override void OnTick(float interval) { if (_enemyEntities.Count < CVars.Get <int>("spawner_max_enemy_count")) { Vector2 spawnPosition = new Vector2(0, 0); do { spawnPosition.X = random.NextSingle(-CVars.Get <float>("screen_width") / 2 * 0.9f, CVars.Get <float>("screen_width") / 2 * 0.9f); spawnPosition.Y = random.NextSingle(-CVars.Get <float>("screen_height") / 2 * 0.9f, CVars.Get <float>("screen_height") / 2 * 0.9f); } while (IsTooCloseToPlayer(spawnPosition)); CreateEntityAtPosition(spawnPosition); } Interval = MathHelper.Max(Interval * CVars.Get <float>("spawner_gravity_enemy_period_multiplier"), CVars.Get <float>("spawner_gravity_enemy_period_min")); }
protected override void OnTick(float interval) { if (_enemyEntities.Count < CVars.Get <int>("spawner_max_enemy_count")) { Vector2 spawnPosition = new Vector2(0, 0); do { spawnPosition.X = random.NextSingle(-CVars.Get <float>("screen_width") / 2 * 0.9f, CVars.Get <float>("screen_width") / 2 * 0.9f); spawnPosition.Y = random.NextSingle(-CVars.Get <float>("screen_height") / 2 * 0.9f, CVars.Get <float>("screen_height") / 2 * 0.9f); } while (IsTooCloseToPlayer(spawnPosition)); float facingNearestPlayer = AngleFacingNearestPlayerShip(spawnPosition); ShootingEnemyEntity.Spawn(Engine, ProcessManager, spawnPosition, facingNearestPlayer); } Interval = MathHelper.Max(Interval * CVars.Get <float>("spawner_shooting_enemy_period_multiplier"), CVars.Get <float>("spawner_shooting_enemy_period_min")); }
protected override void OnTick(float interval) { if (_enemyEntities.Count < Constants.GamePlay.SPAWNER_MAX_ENEMY_COUNT) { Vector2 spawnPosition = new Vector2(0, 0); do { spawnPosition.X = random.NextSingle(-Constants.Global.WINDOW_WIDTH / 2 * 0.9f, Constants.Global.WINDOW_WIDTH / 2 * 0.9f); spawnPosition.Y = random.NextSingle(-Constants.Global.WINDOW_HEIGHT / 2 * 0.9f, Constants.Global.WINDOW_HEIGHT / 2 * 0.9f); } while (IsTooCloseToPlayer(spawnPosition)); ShootingEnemyEntity.Create(Engine, Content.Load <Texture2D>(Constants.Resources.TEXTURE_SHOOTER_ENEMY), spawnPosition, ProcessManager, Content); } Interval = MathHelper.Max(Interval, Constants.GamePlay.SPAWNER_KAMIKAZE_PERIOD_MIN); }
void CreateExplosion(Vector2 position) { for (int i = 0; i < 150; i++) { float speed = 2000 * (1f - 1 / _random.NextSingle(1, 10)); float dir = _random.NextSingle(0, MathHelper.TwoPi); VelocityParticleInfo info = new VelocityParticleInfo() { Velocity = new Vector2((float)(speed * Math.Cos(dir)), (float)(speed * Math.Sin(dir))), LengthMultiplier = 1f, EdgeEntities = _edgeEntities }; _owner.VelocityParticleManager.CreateParticle(_owner.Content.Load <Texture2D>(Constants.Resources.TEXTURE_PARTICLE_VELOCITY), position, Color.White, 150, Vector2.One, info); } }
void AttachFluctuationSequence() { int availableFluctuationsCount = 0; for (int i = 0; i < _fluctuationUnlockedLevel; i++) { availableFluctuationsCount += Constants.Fluctuations.FLUCTUATIONS[i].Length; } Type[] fluctuations = new Type[availableFluctuationsCount]; int k = 0; for (int i = 0; i < _fluctuationUnlockedLevel; i++) { for (int j = 0; j < Constants.Fluctuations.FLUCTUATIONS[i].Length; j++) { fluctuations[k++] = Constants.Fluctuations.FLUCTUATIONS[i][j]; } } Type fluctuationType = null; do { int index = _random.Next(0, fluctuations.Length - 1); fluctuationType = fluctuations[index]; } while (fluctuationType == _lastFluctuation); WaitProcessKillOnEvent timerProcess = new WaitProcessKillOnEvent(_random.NextSingle() * (Constants.Fluctuations.TIMER_MAX - Constants.Fluctuations.TIMER_MIN) + Constants.Fluctuations.TIMER_MIN, typeof(GoalEvent)); timerProcess.SetNext((Fluctuation)Activator.CreateInstance(fluctuationType, _owner)); _processManager.Attach(timerProcess); _lastFluctuation = fluctuationType; _fluctuationUnlockedLevel = MathHelper.Min(++_fluctuationUnlockedLevel, Constants.Fluctuations.FLUCTUATIONS.Length); }
protected override void OnTick(float dt) { SpawnEntity(); Interval = _random.NextSingle(CVars.Get <float>("entity_background_spawner_min"), CVars.Get <float>("entity_background_spawner_max")); }