public static void NextColor(this FastRandom random, out HslColor color, Range <HslColor> range) { var maxH = range.Max.H >= range.Min.H ? range.Max.H : range.Max.H + 360; color = new HslColor(random.NextSingle(range.Min.H, maxH), random.NextSingle(range.Min.S, range.Max.S), random.NextSingle(range.Min.L, range.Max.L)); }
public static void NextColor(this FastRandom random, out HslColor color, Range <HslColor> range) { HslColor min = range.Min; HslColor max = range.Max; float maxH = max.H >= min.H ? max.H : max.H + 360; color = new HslColor( random.NextSingle(min.H, maxH), random.NextSingle(min.S, max.S), random.NextSingle(min.L, max.L)); }
public Entity CreateBloodExplosion(Vector2 position, float totalSeconds = 1.0f) { var random = new FastRandom(); var textureRegion = _characterTextureAtlas[0]; var entity = _entityComponentSystem.CreateEntity(position); var profile = Profile.Spray(new Vector2(0, -1), MathHelper.Pi); var term = TimeSpan.FromSeconds(totalSeconds); var particleEmitter = new ParticleEmitter(textureRegion, 32, term, profile) { Parameters = new ParticleReleaseParameters { Speed = new Range <float>(140, 200), Quantity = new Range <int>(32, 64), Rotation = new Range <float>(-MathHelper.TwoPi, MathHelper.TwoPi) }, Modifiers = new IModifier[] { new LinearGravityModifier { Direction = Vector2.UnitY, Strength = 350 }, new OpacityFastFadeModifier(), new RotationModifier { RotationRate = random.NextSingle(-MathHelper.TwoPi, MathHelper.TwoPi) } } }; entity.AttachComponent(new TransformableComponent <ParticleEmitter>(particleEmitter)); entity.Destroy(delaySeconds: totalSeconds); return(entity); }
public override void Update(GameTime gameTime) { var elapsedSeconds = gameTime.GetElapsedSeconds(); var mouseState = MouseExtended.GetState(); var keyboardState = KeyboardExtended.GetState(); if (keyboardState.WasKeyJustDown(Keys.Escape)) { ScreenManager.LoadScreen(new TitleScreen(Game), new ExpandTransition(GraphicsDevice, Color.Black)); } MovePaddlePlayer(mouseState); MovePaddleAi(_redPaddle, elapsedSeconds); ConstrainPaddle(_bluePaddle); ConstrainPaddle(_redPaddle); MoveBall(elapsedSeconds); if (BallHitPaddle(_ball, _bluePaddle)) { // TODO: Change the angle of the bounce //_tweener.TweenTo(_bluePaddle, p => p.Rotation, MathHelper.Pi / 16f, 0.2f) // //.OnSet(v => new Vector2(v.X, _bluePaddle.Position.Y)) // .RepeatReverse() // .Easing(EasingFunctions.ExponentialIn); _plopSoundEffect.Play(1.0f, _random.NextSingle(0.5f, 1.0f), -1f); } if (BallHitPaddle(_ball, _redPaddle)) { // TODO: Change the angle of the bounce //_tweener.TweenTo(_redPaddle, p => p.Position, _redPaddle.Position + new Vector2(15, 0), 0.2f) // .RepeatReverse() // .Easing(EasingFunctions.ExponentialIn); _plopSoundEffect.Play(1f, _random.NextSingle(-1f, 1f), 1f); } _tweener.Update(elapsedSeconds); }
public void Trigger(LineSegment line) { var numToRelease = _random.Next(Parameters.Quantity); var lineVector = line.ToVector(); for (var i = 0; i < numToRelease; i++) { var offset = lineVector * _random.NextSingle(); Release(line.Origin + offset, 1); } }
public override void Update(GameTime gameTime) { var elapsedSeconds = gameTime.GetElapsedSeconds(); foreach (var entityId in ActiveEntities) { var transform = _transformMapper.Get(entityId); var raindrop = _raindropMapper.Get(entityId); raindrop.Velocity += new Vector2(0, 500) * elapsedSeconds; transform.Position += raindrop.Velocity * elapsedSeconds; if (transform.Position.Y >= 480 && !_expiryMapper.Has(entityId)) { for (var i = 0; i < 3; i++) { var velocity = new Vector2(_random.NextSingle(-100, 100), -raindrop.Velocity.Y * _random.NextSingle(0.1f, 0.2f)); var id = CreateRaindrop(transform.Position.SetY(479), velocity, (i + 1) * 0.5f); _expiryMapper.Put(id, new Expiry(1f)); } DestroyEntity(entityId); } } _spawnDelay -= gameTime.GetElapsedSeconds(); if (_spawnDelay <= 0) { for (var q = 0; q < 50; q++) { var position = new Vector2(_random.NextSingle(0, 800), _random.NextSingle(-240, -480)); CreateRaindrop(position); } _spawnDelay = _random.NextSingle(_minSpawnDelay, _maxSpawnDelay); } }
public float NextFloat() { return(random2.NextSingle()); }