/// ------------------------------------------------------------------------------------------------------ /// <summary> /// Actually shoots the C.W.I.S style bullet /// </summary> /// <param name="spawnPosition">Vec3 | place to spawn</param> /// <param name="rateOfFire">Float | the speed of which the next bullet will be allowed</param> /// ------------------------------------------------------------------------------------------------------ private IEnumerator ShootCWISBulletCO(Vector3 spawnPosition, float rateOfFire) { canShoot = false; for (int i = 0; i < poolSize; i++) { if (!bulletPool[i].activeInHierarchy) { // Place and spawn bulletPool[i].transform.position = spawnPosition; bulletPool[i].transform.rotation = Quaternion.Euler(GetRandom.Vector3(transform.rotation.eulerAngles, 0, 0, 3f, 3f, 0, 0)); bulletPool[i].GetComponent <Rigidbody>().velocity = -bulletPool[i].transform.forward * bulletSpeed; bulletPool[i].SetActive(true); ammo -= 1; // Audio on shoot _audio.PlayFromTime("cwisShoot", .65f, GetRandom.Float(.2f, .3f), GetRandom.Float(.6f, .75f)); break; } } yield return(new WaitForSeconds(rateOfFire)); canShoot = true; }
private IntRect GlyphArea; // Total glyph-occupied region - doesn't change public GlyphStream(GlyphStreamConfig settings, Rectangle workingArea) { _workingArea = workingArea; _glyphConfig = settings.GlyphConfig; MAX_GLYPHS = settings.MaxGlyphs; MIN_GLYPHS = settings.MinGlyphs; MAX_MOVEMENTRATE = settings.MaxMovementRate; MIN_MOVEMENTRATE = settings.MinMovementRate; MIN_GLYPHSCALE = settings.MinGlyphScale; MAX_GLYPHSCALE = settings.MaxGlyphScale; MARGIN_SCALE = settings.MarginScale; movementRate = GetRandom.Float(MIN_MOVEMENTRATE, MAX_MOVEMENTRATE); var numberOfGlyphs = GetRandom.Int(MIN_GLYPHS, MAX_GLYPHS); scale = GetRandom.Float(MIN_GLYPHSCALE, MAX_GLYPHSCALE); displayDurationMultipier = GetRandom.Float(0.5f / numberOfGlyphs, 1f); GlyphPosition = new Vector2f( GetRandom.Int((int)-GlyphSize.X, (int)(_workingArea.Width + GlyphSize.X)), GetRandom.Int((int)-GlyphSize.Y, (int)(_workingArea.Height + GlyphSize.Y))); ////TODO: refactor to a debugGlpyhStream class //if (Config.IsDebugGlyphStreams) //{ // // Just for debugging // numberOfGlyphs = 6; // GlyphPosition = new Vector2f(10,10); // movementRate = 80; // scale = 0.2f; // displayDurationMultipier = 0.5f; //} _glyphs = new List <Glyph>(); for (int i = 0; i < numberOfGlyphs; i++) { var y = GlyphPosition.Y + (i * Glyph.GLYPH_HEIGHT * scale * MARGIN_SCALE); if (y + Glyph.GLYPH_HEIGHT < 0) { continue; } if (y > workingArea.Height) { continue; } _glyphs.Add(new Glyph(new Vector2f(GlyphPosition.X, y), scale, _glyphConfig)); } MaskPosition = new Vector2f(GlyphPosition.X, GlyphPosition.Y - MaskSize.Y); GlyphArea = new IntRect( (int)GlyphPosition.X, (int)GlyphPosition.Y, (int)GlyphSize.X, (int)GlyphSize.Y + (int)(GlyphSize.Y * MARGIN_SCALE * (_glyphs.Count - 1f)) ); }
[TestMethod] public void ToDecimalTest() { var m = GetRandom.Decimal(); var d = GetRandom.Double(Convert.ToSingle(decimal.MinValue), Convert.ToSingle(decimal.MaxValue)); var f = GetRandom.Float(Convert.ToSingle(decimal.MinValue), Convert.ToSingle(decimal.MaxValue)); var l = GetRandom.Int64(); var i = GetRandom.Int32(); var s = GetRandom.Int16(); var b = GetRandom.Int8(); var ul = GetRandom.UInt64(); var ui = GetRandom.UInt32(); var us = GetRandom.UInt16(); var ub = GetRandom.UInt8(); Assert.AreEqual(m, Decimals.ToDecimal(m)); Assert.AreEqual(Convert.ToDecimal(d), Decimals.ToDecimal(d)); Assert.AreEqual(Convert.ToDecimal(f), Decimals.ToDecimal(f)); Assert.AreEqual(Convert.ToDecimal(l), Decimals.ToDecimal(l)); Assert.AreEqual(Convert.ToDecimal(i), Decimals.ToDecimal(i)); Assert.AreEqual(Convert.ToDecimal(s), Decimals.ToDecimal(s)); Assert.AreEqual(Convert.ToDecimal(b), Decimals.ToDecimal(b)); Assert.AreEqual(Convert.ToDecimal(ul), Decimals.ToDecimal(ul)); Assert.AreEqual(Convert.ToDecimal(ui), Decimals.ToDecimal(ui)); Assert.AreEqual(Convert.ToDecimal(us), Decimals.ToDecimal(us)); Assert.AreEqual(Convert.ToDecimal(ub), Decimals.ToDecimal(ub)); Assert.AreEqual(1.2345M, Decimals.ToDecimal("1.2345")); Assert.AreEqual(1.2345M, Decimals.ToDecimal(1.2345D)); Assert.AreEqual(1.2345M, Decimals.ToDecimal(1.2345F)); }
private void UpdateTriggerFrequency(bool force = false) { if (force || _changeFrequencyOnTrigger) { _minTwitchFrequency = GetRandom.Float(MINIMUM_TWITCH_FREQUENCY, MAXIMUM_TWITCH_FREQUENCY); _maxTwitchFrequency = GetRandom.Float(MINIMUM_TWITCH_FREQUENCY, MAXIMUM_TWITCH_FREQUENCY); _chanceOfTrigger = GetRandom.Float(0.05f, 0.95f); } _twitchFrequency = GetRandom.Float(_minTwitchFrequency, _maxTwitchFrequency); }
public void TestChangeAmount() { float initialValue = ClassObj.Amount; float amountToChange = GetRandom.Float(); ClassObj.ChangeAmount(amountToChange); Assert.AreEqual(initialValue + amountToChange, ClassObj.Amount); ClassObj.ChangeAmount(-amountToChange); Assert.AreEqual(initialValue, ClassObj.Amount); }
protected override void Update(GameTime time) { var elapsed = (float)time.ElapsedGameTime.TotalSeconds; var frameTime = new FrameTime(elapsed, TimeScale); var keyState = Keyboard.GetState(); KeyInput.Update(keyState); MouseInput.Update(); ToggleHotspotBoxes.Perform(this); ToggleQuitGame.Perform(this); ToggleFullscreen.Perform(this); ToggleEditingMode.Perform(this); ReloadGameInterface.Perform(this); RefreshHotspotsState.Perform(this); RefreshToysState.Perform(this); RefreshBackgroundElements.Perform(this); EditingMouseGrab.Perform(this); if (State == GameState.WaitingForClient) { Customer.State = Customer.StateType.Waiting; GenerateNewCustomer.Perform(this, frameTime); } if (State == GameState.FixingToy) { Customer.State = Customer.StateType.Waiting; HandleHotspotInteraction.Perform(this); ResolveCurrentToy.Perform(this); HandlePaymentProcess.Paid = false; HandlePaymentProcess.Delay = 1.5f; } if (State == GameState.ClientPayment) { Customer.State = Customer.StateType.Happy; HandlePaymentProcess.Perform(this, frameTime); } if (State == GameState.ClientLeaving) { Customer.State = Customer.StateType.Waiting; GameInterface.SpeechSprite.Tint = new Color(GameInterface.SpeechSprite.Tint, 0.0f); GenerateNewCustomer.WaitTime = GetRandom.Float(1.0f, 2.0f); ChangeState(GameState.WaitingForClient); } Clock.Update(frameTime); GameCamera.Update(GraphicsDevice.Viewport); DebugMonitor.Update(frameTime); base.Update(time); }
public GlyphStreamNoise(GlyphStreamConfig settings, Rectangle workingArea) { _glyphs = new List <Glyph>(); _workingArea = workingArea; _movementRate = GetRandom.Float(settings.MinMovementRate, settings.MaxMovementRate); _scale = GetRandom.Float(settings.MinGlyphScale, settings.MaxGlyphScale); var glyphCount = GetRandom.Int(settings.MinGlyphs, settings.MaxGlyphs); float displayDurationMultipier = GetRandom.Float(0.5f, 2f); var glyphSize = new Vector2f(Glyph.GLYPH_WIDTH * _scale, Glyph.GLYPH_HEIGHT * _scale); _maskSize = new Vector2f(glyphSize.X, glyphSize.Y * _glyphs.Count * displayDurationMultipier); // TODO: incorporate margin GlyphPosition = new Vector2f( GetRandom.Int((int)-glyphSize.X, (int)(_workingArea.Width + glyphSize.X)), GetRandom.Int((int)-glyphSize.Y, (int)(_workingArea.Height + glyphSize.Y))); GlyphArea = new IntRect( (int)GlyphPosition.X, (int)GlyphPosition.Y, (int)glyphSize.X, (int)glyphSize.Y + (int)(glyphSize.Y * settings.MarginScale * (_glyphs.Count - 1f)) ); for (int i = 0; i < glyphCount; i++) { var y = GlyphPosition.Y + (i * Glyph.GLYPH_HEIGHT * _scale * settings.MarginScale); if (y + Glyph.GLYPH_HEIGHT < 0) { continue; } if (y > workingArea.Height) { continue; } _glyphs.Add(new Glyph(new Vector2f(GlyphPosition.X, y), _scale, settings.GlyphConfig)); } MaskPosition = new Vector2f(GlyphPosition.X, GlyphPosition.Y - _maskSize.Y); }
private static void DragCurrentTools() { if (MouseInput.LeftButtonJustReleased) { Log.Message($"Released: Hotspot: {Current.Name}"); SendCurrentToolToStart(); return; } Current.Transform.Position = MouseInput.WorldPosition; var toolPosition = new Vector3(CurrentPosition.X, CurrentPosition.Y, 0.0f); var toolMin = Current.BoundingBox.Min + toolPosition; var toolMax = Current.BoundingBox.Max + toolPosition; var toolBounds = new BoundingBox(toolMin, toolMax); foreach (var toy in GameDriver.Instance.Toys) { foreach (var damageModel in toy.DamagePoints.Where(element => element.Active)) { var pointTransform = damageModel.GetGlobalTransform(); var pointCenter = new Vector3(pointTransform.Position.X, pointTransform.Position.Y, 0.0f); var pointMin = pointCenter + new Vector3(-20.0f, -20.0f, 0.0f); var pointMax = pointCenter + new Vector3(+20.0f, +20.0f, 0.0f); var pointBounds = new BoundingBox(pointMin, pointMax); if (!toolBounds.Intersects(pointBounds)) { continue; } if (Current.DamageTarget != damageModel.Type) { continue; } damageModel.Active = false; var timeSpent = GetRandom.Float(Current.ActivationTime, -5.0f, +5.0f); GameDriver.Instance.Clock.AddMinutes(timeSpent); } } }
public void AddMoney(int value) { Value += value; if (Value > 10) { return; } var center = GameDriver.Instance.GameInterface.MoneyLocation.Position; var transform = new Transform2D { Angle = GetRandom.Float(-15.0f, 15.0f), Position = new Vector2( GetRandom.Float(center.X, -10.0f, +10.0f), GetRandom.Float(center.Y, -10.0f, +10.0f)), Scale = new Vector2(0.2f, 0.15f), }; Transforms.Add(transform); }
public static void Perform(GameDriver driver, FrameTime time) { if (WaitTime > 0.0f) { WaitTime -= time.Elapsed; return; } var speechSprite = driver.GameInterface.SpeechSprite; speechSprite.Tint = new Color(speechSprite.Tint, 0.8f); var customerIndex = GetRandom.Int(0, 2); driver.Customer.Transform.Position = driver.GameInterface.CustomerLocation.Position; driver.Customer.Sprite.ImageId = $"Customer_00{customerIndex}"; foreach (var toy in driver.Toys) { toy.Active = false; } if (driver.WaitingToyLine == null || driver.WaitingToyLine.Count == 0) { driver.WaitingToyLine = RegenerateToyLine(driver.Toys); } var selectedToy = driver.WaitingToyLine.PopRandom(); foreach (var damagePoint in selectedToy.DamagePoints) { var activationChance = GetRandom.Float(0.0f, 100.0f); damagePoint.Active = activationChance < 50.0f; } selectedToy.Active = true; driver.CurrentToy = selectedToy; driver.ChangeState(GameState.FixingToy); }
public void Update(ChronoEventArgs chronoArgs, IntRect visibleRegion) { var modifier = GetVisibility(visibleRegion); _isDraw = modifier > 0; if (!_isDraw) { return; } if (GetRandom.Float(1f) < _config.ChanceOfHeavyFlicker) { _isFlickering = !_isFlickering; } _spriteOutline.Color = new Color(0, 0, 0, (byte)(CalculateOpacity() * 0.6f)); _sprite.Color = new Color(0, 255, 0, CalculateOpacity()); if (_twitch.IsTriggered(chronoArgs)) { Index = GetRandom.Int(MAX_INDEX); } }
public void GetRandom_Float_should_work() { float randomValue = GetRandom.Float(); Assert.IsNotNull(randomValue); }
/// <summary> /// Get random <see cref="Float"/> value. /// </summary> /// <returns>Random <see cref="Float"/> value.</returns> public static float Float() => GetRandom.Float();