private void InitializeParticles(Explosion explosion) { var lifeTime = RandomNumber.Get(LifetimeRange); for (var i = 0; i < explosion.Particles.Length; i++) { var angleOfVelocity = i / Math.PI * 2; var direction = new Vector2f( (float)Math.Cos(angleOfVelocity), (float)Math.Sin(angleOfVelocity) ); var variance = RandomNumber.Get(-(int)explosion.Strength, 30); var velocity = direction * (explosion.Strength + variance); var color = _colorRange[RandomNumber.Get(0, _colorRange.Count)]; explosion.Particles[i] = new Particle { R = color.R, G = color.G, B = color.B, Position = explosion.Position, Velocity = velocity, TotalLifetime = lifeTime, Mass = RandomNumber.GetFloat(.75f, 1.25f) }; } }
//********************************************************** //** methods: //********************************************************** public void SpawnOnEarthSurface() { var angle = MathUtils.DegreeToRadian(RandomNumber.Get(0, 360)); var dir = new Vector2f( (float)Math.Cos(angle), (float)Math.Sin(angle) ); var position = _game.Earth.Position + dir * (_game.Earth.Radius + 10); // Just to make it more interesting. var randomAngle = angle + RandomNumber.GetFloat(-1, 1) * Math.PI * .13f; var randomDir = new Vector2f( (float)Math.Cos(randomAngle), (float)Math.Sin(randomAngle) ); var rocket = new Rocket(RandomNumber.Get(StrengthRange)) { Position = position, Direction = randomDir, Mass = RandomNumber.Get(MassRange), Fuel = RandomNumber.Get(FuelRange), TotalLifetime = RandomNumber.Get(TotalLifeTime) }; _game.AddRocket(rocket); }
/// <summary> /// Starts the time marker in seconds. /// </summary> public void Start() { if (validRandomLimitWaitTime && !isInitedChronWaitTime) { Reset(); sortedWaitTime = RandomNumber.GetFloat(minNumber, maxNumber); InitChronWaitTime(sortedWaitTime); } else { chronometer = Stopwatch.StartNew(); chronometerWasInitiated = true; isReseted = false; IsStopped = false; sortedWaitTime = -1; } }
public static void Main() { Console.WriteLine("Random float:"); Console.WriteLine(RandomNumber.GetFloat()); Console.WriteLine(RandomNumber.GetFloat()); Console.WriteLine(RandomNumber.GetFloat()); Console.WriteLine("Random int, 0 to 200:"); Console.WriteLine(RandomNumber.GetInt(200)); Console.WriteLine(RandomNumber.GetInt(200)); Console.WriteLine(RandomNumber.GetInt(200)); Console.WriteLine("Random int, 100 to 160:"); Console.WriteLine(RandomNumber.GetInt(100, 160)); Console.WriteLine(RandomNumber.GetInt(100, 160)); Console.WriteLine(RandomNumber.GetInt(100, 160)); }
public void SetRandomTimeGoal(int minNumber, int maxNumber) { SetTimeGoal(RandomNumber.GetFloat(minNumber, maxNumber)); }