private void UpdateTimers() { Timer.Count.Update(deltaTime); IncreaseBallVelocityTimer += deltaTime; SpawnPowerUpTimer += deltaTime; if (IncreaseBallVelocityTimer >= IncreaseBallVelocityInterval) { BallVelocity += 10; Balls.ForEach(b => { b.BaseVelocity = BallVelocity; b.Velocity = BallVelocity; }); IncreaseBallVelocityTimer = 0; } if (SpawnPowerUpTimer >= SpawnPowerUpInterval) { var randPowerup = new PowerUp(this, RandomMath.RandomEnum <PowerUpType>()); var randPosition = new Vector2() { X = RandomMath.RandomBetween(0, GlobalData.Screen.Width - SpriteData.PackageWidth), Y = 0 - SpriteData.PackageHeight, }; Packages.AddIfNotNull(ModelFactory.CreatePowerUpPackage(randPowerup, randPosition)); SpawnPowerUpTimer = 0; } }
protected override void InitBadPixels() { // boss //boss = new Boss(); //Add(boss); for (int i = 0; i < 49; i++) { var bp = RedGuard.Create(); // Cloaky(); bp.GetComponent <ThingComp>().PositionAndTarget = new Vector2(RandomMath.RandomBetween(123f, 720f), RandomMath.RandomBetween(9f, 290f)); //bp.TargetSpeed = 18.0f; // TODO FindWalkableGround(bp); } /* * for (int i = 0; i < 40; i++) * { * Servant s = Servant.Create(); * s.PositionAndTarget = new Vector2(RandomMath.RandomBetween(140f, 720f), RandomMath.RandomBetween(9f, 290f)); * Add(s); * FindWalkableGround(s); * } * * for (int i = 0; i < 14; i++) // XIV companions! * { * Companion cp = Companion.Create(); // Cloaky(); * cp.PositionAndTarget = new Vector2(RandomMath.RandomBetween(PIXIE_STARTING_POS.X - 10f, PIXIE_STARTING_POS.X + 10f), RandomMath.RandomBetween(PIXIE_STARTING_POS.Y - 6f, PIXIE_STARTING_POS.Y + 6f)); * //bp.TargetSpeed = 18.0f; // TODO * Add(cp); * pixie.Companions.Add(cp); * FindWalkableGround(cp); * } */ }
public Servant() : base("pixie") { IsCollisionFree = false; Pushing.Force = 0f; // servants cant push others. DrawInfo.DrawColor = Color.Yellow; ComplexBehavior = new SubsumptionBehavior(); Add(ComplexBehavior); // avoid knights - done by a 'reversed' chase AvoidingKnights = new ChaseBehavior(typeof(Knight), true); AvoidingKnights.MoveSpeed = RandomMath.RandomBetween(0.43f, 0.65f); AvoidingKnights.ChaseRange = RandomMath.RandomBetween(10f, 17f); AvoidingKnights.ReverseBehavior(); ComplexBehavior.Add(AvoidingKnights); // avoid hero - done by a 'reversed' chase AvoidingHero = new ChaseBehavior(Level.Current.hero); AvoidingHero.MoveSpeed = RandomMath.RandomBetween(0.43f, 0.65f); AvoidingHero.ChaseRange = RandomMath.RandomBetween(10f, 17f); AvoidingHero.ReverseBehavior(); ComplexBehavior.Add(AvoidingHero); Wandering = new RandomWanderBehavior(9.7f, 14.3f); Wandering.MoveSpeed = 0.3f; ComplexBehavior.Add(Wandering); }
public RedGuard(Thing chaseTarget) : base("pixie") { IsCollisionFree = false; DrawInfo.DrawColor = new Color(255, 10, 4); Health = 13f; ComplexBehavior = new SubsumptionBehavior(); Add(ComplexBehavior); Combat = new CombatBehavior(typeof(Knight)); ComplexBehavior.Add(Combat); // chase knights that are very close ChasingComp = new ChaseBehavior(typeof(Knight), true); ChasingComp.MoveSpeed = RandomMath.RandomBetween(0.43f, 0.65f); ChasingComp.ChaseRange = 2f; // RandomMath.RandomBetween(12f, 40f); ComplexBehavior.Add(ChasingComp); // chase hero Chasing = new ChaseBehavior(chaseTarget); Chasing.MoveSpeed = RandomMath.RandomBetween(0.47f, 0.75f); Chasing.ChaseRange = 14f; // RandomMath.RandomBetween(12f, 40f); ComplexBehavior.Add(Chasing); Turning = new AlwaysTurnRightBehavior(); // patrolling Turning.MoveSpeed = Chasing.MoveSpeed; //RandomMath.RandomBetween(0.57f, 1.05f); Turning.MoveSpeed = 0.7f; ComplexBehavior.Add(Turning); Wandering = new RandomWanderBehavior(2.7f, 11.3f); Wandering.MoveSpeed = 0.7f; ComplexBehavior.Add(Wandering); }
public Servant() : base("pixie") { IsCollisionFree = false; Pushing.Force = 0f; // servants cant push others. DrawInfo.DrawColor = Color.Yellow; // avoid other things Avoiding = new ChaseBehavior(typeof(Companion)); Avoiding.MoveDeltaTime = RandomMath.RandomBetween(0.43f, 0.65f); Avoiding.ChaseRange = 11f; // RandomMath.RandomBetween(12f, 40f); Add(Avoiding); // avoid other things Avoiding = new ChaseBehavior(typeof(Pixie)); Avoiding.MoveDeltaTime = RandomMath.RandomBetween(0.43f, 0.65f); Avoiding.ChaseRange = 11f; // RandomMath.RandomBetween(12f, 40f); //Avoiding.Avoidance = true; Add(Avoiding); Wandering = new RandomWanderBehavior(9.7f, 14.3f); Wandering.MoveDeltaTime = 0.3f; Add(Wandering); Reverse = new ReverseControlBehavior(); Add(Reverse); }
public override IEnumerable <RunStatus> Execute(object context) { BTAIContext ctx = context as BTAIContext; var tc = ctx.Entity.GetComponent <ThingComp>(); var tcc = ctx.Entity.GetComponent <ThingControlComp>(); // only attack if not blocked there. List <Entity> col = tc.DetectCollisions(ctx.Entity, tc.FacingDirection); foreach (Entity e in col) { var tc2 = e.GetComponent <ThingComp>(); if (tc2.Faction != tc.Faction && tc2.Faction != Faction.NEUTRAL) { IsAttacking = true; tcc.TargetMove = tc.FacingDirection; tcc.DeltaTimeBetweenMoves = this.DeltaTimeBetweenMoves; // TODO color set! and health decrease values parameterize. Level.Current.Subtitles.Show(3, AttackStrings[RandomMath.RandomIntBetween(0, AttackStrings.Length - 1)], 3.5f, tc.Color); ctx.Entity.GetComponent <HealthComp>().DecreaseHealth(RandomMath.RandomBetween(1f, 3f)); yield return(RunStatus.Success); yield break; } } yield return(RunStatus.Failure); }
public Companion() : base("pixie") { IsCollisionFree = false; SetColors(4f, new Color(38, 30, 240), new Color(150, 150, 255)); Pushing.Force = RandomMath.RandomBetween(1f, 1.5f); SubsumptionBehavior sub = new SubsumptionBehavior(); Add(sub); Combat = new CombatBehavior(typeof(RedGuard)); sub.Add(Combat); ChasingHero = new ChaseBehavior(Level.Current.pixie); ChasingHero.ChaseRange = 370f; ChasingHero.SatisfiedRange = 6f; ChasingHero.MoveDeltaTime = RandomMath.RandomBetween(1.2f, 1.5f); sub.Add(ChasingHero); ChasingRedGuard = new ChaseBehavior(typeof(RedGuard)); ChasingRedGuard.ChaseRange = 20f; ChasingRedGuard.MoveDeltaTime = RandomMath.RandomBetween(1.1f, 1.5f); sub.Add(ChasingRedGuard); Attacking = new AttackBehavior(Level.Current.pixie); Attacking.AttackDuration = RandomMath.RandomBetween(1.5f, 2.8f); sub.Add(Attacking); Wandering = new RandomWanderBehavior(2.7f, 11.3f); Wandering.MoveDeltaTime = RandomMath.RandomBetween(0.09f, 0.25f); sub.Add(Wandering); }
/// <summary> /// Create ball randomly. Used in spawning in menu /// </summary> /// <returns></returns> public static List <Ball> CreateRandomBalls() { List <Ball> balls = new List <Ball>(); int numOfBall = RandomMath.RandomBetween(1, 4); // Random spawn 1-3 balls var ballSize = RandomMath.RandomEnum <BallSize>(); var ballStrength = RandomMath.RandomEnum <BallStrength>(); foreach (int i in Enumerable.Range(1, numOfBall)) { Vector2 position = new Vector2() { X = RandomMath.RandomBetween(0, GlobalData.Screen.Width - Ball.RadiusDict[ballSize] * 2), Y = RandomMath.RandomBetween(0, GlobalData.Screen.Height - Ball.RadiusDict[ballSize] * 2), }; Ball ball = new Ball(EntryPoint.Game.Scene, position); ball.Size = ballSize; ball.Strength = ballStrength; ball.Angle = RandomMath.RandomBetween(0, 360); balls.Add(ball); } return(balls); }
protected override void OnNextMove() { base.OnNextMove(); Vector2 dir = CurrentDirection; if (dir.Length() < 0.1f) { dir = Vector2.Zero; } else { // choose one direction randomly, if diagonals would be required if (dir.X != 0f && dir.Y != 0f) { float r = RandomMath.RandomUnit(); if (r > 0.5f) { dir.X = 0f; } else { dir.Y = 0f; } } dir.Normalize(); } TargetMove = dir; }
/// <summary> /// Builds StaticRandomSelector & clears internal buffers. Must be called after you finish Add-ing items. /// </summary> /// <param name="seed">Seed for random selector. If you leave it -1, the internal random will generate one.</param> /// <returns>Returns IRandomSelector, underlying objects are either StaticRandomSelectorLinear or StaticRandomSelectorBinary. Both are non-mutable.</returns> public IRandomSelector <T> Build(int seed = -1) { T[] items = itemBuffer.ToArray(); float[] CDA = weightBuffer.ToArray(); itemBuffer.Clear(); weightBuffer.Clear(); RandomMath.BuildCumulativeDistribution(CDA); if (seed == -1) { seed = random.Next(); } // RandomMath.ArrayBreakpoint decides where to use Linear or Binary search, based on internal buffer size // if CDA array is smaller than breakpoint, then pick linear search random selector, else pick binary search selector if (CDA.Length < RandomMath.ArrayBreakpoint) { return(new StaticRandomSelectorLinear <T>(items, CDA, seed)); } else { // bigger array sizes need binary search for much faster lookup return(new StaticRandomSelectorBinary <T>(items, CDA, seed)); } }
private BattleEngine(Player localPlayer, Player remotePlayer) { characters = new Dictionary <CharacterKey, Character>(); affects = new Dictionary <CharacterKey, Dictionary <String, Affect> >(); foreach (Character character in localPlayer.GetCharacters()) { CharacterKey key = new CharacterKey(localPlayer.Name, character.RootName); characters.Add(key, character); affects.Add(key, new Dictionary <String, Affect>()); } foreach (Character character in remotePlayer.GetCharacters()) { CharacterKey key = new CharacterKey(remotePlayer.Name, character.RootName); characters.Add(key, character); affects.Add(key, new Dictionary <String, Affect>()); } // Inicie a ActionGauge com valores de 0 - 0.25 foreach (Character character in characters.Values) { character.ActionGauge = RandomMath.RandomBetween(0.0f, 0.25f); } }
/// <summary> /// Factory method to create new Red Guard /// </summary> /// <returns></returns> public static Entity Create() { ChaseBehavior ChasingHero; //ChaseBehavior ChasingCompanions; AlwaysTurnRightBehavior Turning; RandomWanderBehavior Wandering; AttackEnemyBehavior Attacking; var e = GameFactory.CreateThing(ThingType.RED_GUARD, true); var ai = new BTAIComp(); e.AddComponent(ai); var sub = new PrioritySelector(); ai.rootNode = sub; var tc = e.GetComponent <ThingComp>(); tc.IsCollisionFree = false; tc.Color = new Color(255, 10, 4); tc.Faction = Faction.EVIL; var rwc = new RandomWanderComp(); e.AddComponent(rwc); rwc.MinDirectionChangeTime = 2.7; rwc.MaxDirectionChangeTime = 11.3; // attack hero or companions Attacking = new AttackEnemyBehavior(attackString); // chase companions that are very close /* * ChasingCompanions = new ChaseBehavior(typeof(Companion)); * ChasingCompanions.DeltaTimeBetweenMoves = RandomMath.RandomBetween(0.43f, 0.65f); * ChasingCompanions.ChaseRange = 1.5f; // RandomMath.RandomBetween(12f, 40f); * sub.AddChild(ChasingCompanions); */ // chase hero ChasingHero = new ChaseBehavior(Level.Current.Hero); ChasingHero.DeltaTimeBetweenMoves = RandomMath.RandomBetween(0.47f, 0.75f); ChasingHero.ChaseRange = 15f; // RandomMath.RandomBetween(12f, 40f); sub.AddChild(ChasingHero); Turning = new AlwaysTurnRightBehavior(); // patrolling Turning.DeltaTimeBetweenMoves = ChasingHero.DeltaTimeBetweenMoves; //RandomMath.RandomBetween(0.57f, 1.05f); Turning.DeltaTimeBetweenMoves = 0.7f; sub.AddChild(Turning); Wandering = new RandomWanderBehavior(); Wandering.DeltaTimeBetweenMoves = 0.7f; sub.AddChild(Wandering); e.Refresh(); return(e); }
public BadPixel(string shape) : base(shape) { IsCollisionFree = false; MyMotion = new LinearMotionBehavior(new Vector2(0f, 1f)); MyMotion.MoveSpeed = RandomMath.RandomBetween(0.2f, 1.6f); Add(MyMotion); }
void OnExploding() { Vector2 pos = Target; LevelBackground bg = Level.Current.Background; Vector2 pixPos; pixPos.X = pos.X + RandomMath.RandomBetween(-ExplosionRange, ExplosionRange); pixPos.Y = pos.Y + RandomMath.RandomBetween(-ExplosionRange, ExplosionRange); bg.SetPixel(pixPos, RandomMath.RandomColor()); }
public Boss() : base("boss") { PositionAndTarget = new Microsoft.Xna.Framework.Vector2(520f, 290f); // chase hero Chasing = new ChaseBehavior(Level.Current.pixie); Chasing.MoveDeltaTime = RandomMath.RandomBetween(0.18f, 0.22f); Chasing.ChaseRange = 26f; // RandomMath.RandomBetween(12f, 40f); Add(Chasing); DrawInfo.Center = new Microsoft.Xna.Framework.Vector2(0.5f, 0.5f); }
protected override void OnUpdate(ref UpdateParams p) { base.OnUpdate(ref p); // adapt scroll speed to how fast pixie goes Background.TargetSpeed = SCREEN_MOTION_SPEED * pixie.Velocity; // create new pixels falling timerNewBaddie += p.Dt; if (timerNewBaddie >= nextBaddieInterval && SimTime >= 4.0f) { timerNewBaddie = 0f; nextBaddieInterval = RandomMath.RandomBetween(MinPauseBetweenBaddies, MaxPauseBetweenBaddies); BadPixel b = BadPixel.Create((int)Math.Round(RandomMath.RandomBetween(-0.49f, 23.49f))); float x = RandomMath.RandomBetween(-40f, 40f); float y = RandomMath.RandomBetween(-50f, -40f); b.PositionAndTarget = new Vector2(x + pixie.Target.X, y + LevelBackground.ViewPos.Y); AddNextUpdate(b); } if (pixie.Score > 0) { tObjCount.Text = "Tree-score: " + pixie.Score; tObjCount.Visible = true; } // scroll background if (SimTime >= SCROLLING_START_TIME) { Background.Target.Y = BG_STARTING_POS.Y - SCROLL_SPEED_PIXELS_PER_SEC * (SimTime - SCROLLING_START_TIME); } //Level.Current.Background.Motion.ZoomCenterTarget = Level.Current.pixie.Motion; // resolution scale changing //if (SimTime>= SCROLLING_START_TIME && Background.Target.Y < 700f && numberOfZoomOuts == 0) // ScreenBorderHit(); //if (Background.Target.Y < 710f && numberOfZoomOuts == 1) ScreenBorderHit(); //if (Background.Target.Y < 700f && numberOfZoomOuts == 2) ScreenBorderHit(); // test position on screen - if pixie beneath lower border much, lose if (SimTime >= SCROLLING_START_TIME && !hasLost && (pixie.Motion.PositionAbsZoomedPixels.Y > Screen.HeightPixels + 100f)) { hasLost = true; } if (hasLost) { Music.Fade(-0.1f * p.Dt); this.Background.DrawInfo.DrawColor = Color.White * Music.Volume; if (Music.Volume == 0) { PixieGame.Instance.Exit(); } } }
public void TestDan() { var r = new RandomMath(); int N = 50; // Generate an array of independent estimates of whether a signal // is high or low Uncertain <bool>[] data = (from i in Enumerable.Range(0, N) let noise = r.NextGaussian(0, 0.01) let vad = i > 15 && i < 30 ? 0.9 : 0.1 let param = Math.Abs(vad + noise) let f = new Bernoulli(param > 1 ? 1 : param) select f).ToArray(); // history operator we chatted about Uncertain <bool[]> history = data.USeq(N); // Inference computes a weighted bool[] object: effectively a histogram // The call to SampledInference needs to know (i) how many samples to take and how to compare bool[] Uncertain <bool[]> posterior = history.SampledInference(10000, new SequenceComparer <bool>()); // now inspect by materializing a list List <Weighted <bool[]> > top5 = posterior .Support() // enumerate the histogram .OrderByDescending(k => k.Probability) // sorted by probability .Take(5) // just top 5 .ToList(); // produce list //var program = from bools in history // let sum = bools.Select(Convert.ToInt32).Sum() // from prior in new Gaussian(20, 0.01) // where sum == (int) prior // select bools; //Uncertain<bool[]> posterior1 = program.SampledInference(10000, new BoolArrayEqualityComparer()); Func <bool[], bool[]> Intervalize = _ => _; var program = from bools in data.USeq(N) select Intervalize(bools); // now inspect by materializing a list List <Weighted <bool[]> > top51 = posterior .Support() // enumerate the histogram .OrderByDescending(k => k.Probability) // sorted by probability .Take(5) // just top 5 .ToList(); // produce list // set breakpoint int x = 10; }
public Boss() : base("boss") { PositionAndTarget = new Vector2(520f, 290f); // chase hero Chasing = new ChaseBehavior(Level.Current.hero); Chasing.MoveSpeed = RandomMath.RandomBetween(0.18f, 0.24f); Chasing.ChaseRange = 30f; // RandomMath.RandomBetween(12f, 40f); Chasing.SatisfiedRange = 1f; Add(Chasing); DrawInfo.Center = new Vector2(0.5f, 0.5f); MySpriteBatch = new TTSpriteBatch(Screen.graphicsDevice, SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); }
protected override void InitToys() { base.InitToys(); Vector2 p; for (int i = 0; i < 10; i++) { Toy t = new SpeedModifyToy(2f); t.UsesLeft = 3; p = PIXIE_STARTING_POS + new Vector2(RandomMath.RandomBetween(10f, 50f), RandomMath.RandomBetween(-40f, 40f)); t.PositionAndTarget = p; Add(t); } // test paint Toy pt = new PaintToy(); p = PIXIE_STARTING_POS + new Vector2(3f, 0f); pt.PositionAndTarget = p; Add(pt); // test zoomout Toy zo = new ZoomOutToy(); p = PIXIE_STARTING_POS + new Vector2(5f, 1f); zo.PositionAndTarget = p; Add(zo); // test bomb Toy bo = new BombToy(); p = PIXIE_STARTING_POS + new Vector2(-1f, 5f); bo.PositionAndTarget = p; Add(bo); // music credits object Toy musicMsg = new MusicCreditsToy(); musicMsg.PositionAndTarget = new Vector2(2f, 36f); Add(musicMsg); Toy invisToy = new InvisibilityToy(); invisToy.PositionAndTarget = PIXIE_STARTING_POS + new Vector2(20f, 0f); Add(invisToy); // attach test //test.AttachmentPosition = new Vector2(3f, 0f); //pixie.Add(test); }
public void LeadAttack() { if (SimTime < 280 && SimTime > 21.6) { ShowAttackDirectionString(); } if (SimTime > 45 && RandomMath.RandomUnit() < 0.4) { Level.Current.Sound.PlayAttackSignal(); } foreach (Knight c in Knights) { c.Attacking.TriggerAttack(); } }
protected override void InitBadPixels() { base.InitBadPixels(); // boss boss = new Boss(); Add(boss); for (int i = 0; i < 412; i++) { RedGuard bp = RedGuard.Create(); // Cloaky(); bp.PositionAndTarget = new Vector2(RandomMath.RandomBetween(123f, 720f), RandomMath.RandomBetween(9f, 290f)); //bp.TargetSpeed = 18.0f; // TODO Add(bp); AllEnemies.Add(bp); FindWalkableGround(bp); } for (int i = 0; i < 36; i++) { Servant s = Servant.Create(); s.PositionAndTarget = new Vector2(RandomMath.RandomBetween(140f, 720f), RandomMath.RandomBetween(9f, 290f)); Add(s); FindWalkableGround(s); } // servants at local hero's castle for (int i = 0; i < 3; i++) { Servant s = Servant.Create(); s.AvoidingKnights.ChaseRange = 4f; s.AvoidingHero.ChaseRange = 4f; s.PositionAndTarget = new Vector2(RandomMath.RandomBetween(0f, 20f), RandomMath.RandomBetween(32f, 90f)); Add(s); FindWalkableGround(s); } for (int i = 0; i < 14; i++) // XIV companions! { Knight cp = Knight.Create(); cp.PositionAndTarget = new Vector2(KnightsStartingPositions[2 * i] + DEBUG_SHIFT_POS_RIGHT, KnightsStartingPositions[2 * i + 1]); //bp.TargetSpeed = 18.0f; // TODO Add(cp); hero.Knights.Add(cp); FindWalkableGround(cp); } }
/// <summary> /// Re/Builds internal CDL (Cummulative Distribution List) /// Must be called after modifying (calling Add or Remove), or it will break. /// Switches between linear or binary search, depending on which one will be faster. /// Might generate some garbage (list resize) on first few builds. /// </summary> /// <param name="seed">You can specify seed for internal random gen or leave it alone</param> /// <returns>Returns itself</returns> public IRandomSelector <T> Build(int seed = -1) { if (itemsList.Count == 0) { throw new Exception("Cannot build with no items."); } // clear list and then transfer weights CDL.Clear(); for (int i = 0; i < weightsList.Count; i++) { CDL.Add(weightsList[i]); } RandomMath.BuildCumulativeDistribution(CDL); // default behavior // if seed wasn't specified (it is seed==-1), keep same seed - avoids garbage collection from making new random if (seed != -1) { // input -2 if you want to randomize seed if (seed == -2) { seed = random.Next(); random = new Random(seed); } else { random = new Random(seed); } } // RandomMath.ListBreakpoint decides where to use Linear or Binary search, based on internal buffer size // if CDL list is smaller than breakpoint, then pick linear search random selector, else pick binary search selector if (CDL.Count < RandomMath.ListBreakpoint) { selectFunction = RandomMath.SelectIndexLinearSearch; } else { selectFunction = RandomMath.SelectIndexBinarySearch; } return(this); }
public Knight() : base("pixie") { IsCollisionFree = false; SetColors(4f, new Color(28, 20, 230), new Color(76, 76, 255)); Health = 13f; Pushing.Force = RandomMath.RandomBetween(1f, 1.5f); ComplexBehavior = new SubsumptionBehavior(); ComplexBehavior.Active = false; // initially, knight stays near square table. Add(ComplexBehavior); Combat = new CombatBehavior(typeof(RedGuard)); ComplexBehavior.Add(Combat); ChasingHero = new ChaseBehavior(Level.Current.hero); ChasingHero.ChaseRange = 20f; ChasingHero.SatisfiedRange = 8f; ChasingHero.MoveSpeed = RandomMath.RandomBetween(1.54f, 1.87f); ComplexBehavior.Add(ChasingHero); var tb = new PathFindToTargetBehavior() { ChaseTarget = Level.Current.hero, ChaseRange = 970f, SatisfiedRange = ChasingHero.ChaseRange - 2f }; ComplexBehavior.Add(tb); ChasingRedGuard = new ChaseBehavior(typeof(RedGuard), true); ChasingRedGuard.ChaseRange = 20f; ChasingRedGuard.MoveSpeed = RandomMath.RandomBetween(1.1f, 1.5f); ComplexBehavior.Add(ChasingRedGuard); Attacking = new AttackBehavior(Level.Current.hero); Attacking.AttackDuration = RandomMath.RandomBetween(1.9f, 2.95f); ComplexBehavior.Add(Attacking); Wandering = new RandomWanderBehavior(15.7f, 23.3f); Wandering.MoveSpeed = RandomMath.RandomBetween(0.001f, 0.02f); ComplexBehavior.Add(Wandering); }
void Explode() { Vector2 pos = Target; int posX = (int)Math.Round(pos.X); int posY = (int)Math.Round(pos.Y); LevelBackground bg = Level.Current.Background; Vector2 pixPos; for (int x = posX - ExplosionRange; x <= posX + ExplosionRange; x++) { for (int y = posY - ExplosionRange; y <= posY + ExplosionRange; y++) { pixPos.X = x; pixPos.Y = y; bg.SetPixel(pixPos, RandomMath.RandomColor()); } } }
protected override void OnUpdate(ref UpdateParams p) { base.OnUpdate(ref p); if (TargetMove.LengthSquared() > 0) { if (CollidesWhenThisMoves(Level.Current.hero, TargetMove)) { if (Level.Current.Subtitles.Children.Count <= 4 && Level.Current.hero.Health > 0f) { Level.Current.Sound.PlayRandomCombatSound(0.2f, 0.3f); Level.Current.Subtitles.Show(3, "(Red:) " + attackString[RandomMath.RandomIntBetween(0, attackString.Length - 1)], 3.5f, Color.IndianRed); var damage = RandomMath.RandomBetween(MinDamage, MaxDamage); HurtBehavior.Apply(Level.Current.hero, damage, MaxDamage); Level.Current.hero.Health -= damage; } } } }
private PowerUpPackage SpawnPowerUpPackage() { // TODO: remove //PowerUp pu = null; //if (RandomMath.RandomBoolean()) // pu = new PowerUp(scene, PowerUpType.Magnetize); //else // pu = new PowerUp(scene, PowerUpType.Triple); //return ModelFactory.CreatePowerUpPackage(pu, this.Position); if (!RandomMath.RandomPercent(powerUpSpawnChance)) { return(null); } PowerUp powerUp = null; var randNum = RandomMath.RandomBetween(0, 100); if (0 <= randNum && randNum < 30 && favoredPowerUp != PowerUpType.Nothing) { powerUp = new PowerUp(scene, favoredPowerUp); } else if (30 <= randNum && randNum < 50 && secondaryfavoredPowerUp != PowerUpType.Nothing) { powerUp = new PowerUp(scene, secondaryfavoredPowerUp); } else { powerUp = new PowerUp(scene, RandomMath.RandomEnum <PowerUpType>()); } if (powerUp.PowerUpType == PowerUpType.Nothing) { return(null); } return(ModelFactory.CreatePowerUpPackage(powerUp, this.Position)); }
protected override void InitToys() { base.InitToys(); for (int i = 0; i < 20; i++) { Toy test = new SpeedModifyToy(2f); test.PositionAndTarget = PIXIE_STARTING_POS + new Vector2(RandomMath.RandomBetween(10f, 50f), RandomMath.RandomBetween(-40f, 40f)); Add(test); } Toy invisToy = new InvisibilityToy(); invisToy.PositionAndTarget = PIXIE_STARTING_POS + new Vector2(20f, 0f); Add(invisToy); // attach test //test.AttachmentPosition = new Vector2(3f, 0f); //pixie.Add(test); }
/// <summary> /// Test and compare linear and binary searches, they should return identical results /// </summary> /// <returns></returns> bool TestEqualityOfLinearVsBinarySearch() { var random = new System.Random(); for (int i = 0; i < 1000000; i++) { float u = i / 999999f; float r = (float)random.NextDouble(); float[] randomWeights = RandomMath.RandomWeightsArray(random, 33); RandomMath.BuildCumulativeDistribution(randomWeights); if (randomWeights.SelectIndexLinearSearch(1f) != randomWeights.SelectIndexBinarySearch(1f)) { return(false); } if (randomWeights.SelectIndexLinearSearch(u) != randomWeights.SelectIndexBinarySearch(u)) { Debug.Log("Not matching u"); Debug.Log(u); Debug.Log(randomWeights.SelectIndexLinearSearch(u)); Debug.Log(randomWeights.SelectIndexBinarySearch(u)); return(false); } if (randomWeights.SelectIndexLinearSearch(r) != randomWeights.SelectIndexBinarySearch(r)) { Debug.Log("Not matching r"); Debug.Log(r); Debug.Log(randomWeights.SelectIndexLinearSearch(r)); Debug.Log(randomWeights.SelectIndexBinarySearch(r)); return(false); } } return(true); }
public override IEnumerable <RunStatus> Execute(object context) { BTAIContext ctx = context as BTAIContext; // time keeping timeSinceLastChange += ctx.Dt; // direction changing if (timeSinceLastChange >= dirChangeTime) { timeSinceLastChange = 0f; // TODO: define a double functino also dirChangeTime = (double)RandomMath.RandomBetween((float)MinDirectionChangeTime, (float)MaxDirectionChangeTime); // TODO: length-preservation in VelocityComp Vector3 v = ctx.Entity.GetComponent <VelocityComp>().Velocity; CurrentDirection = RandomMath.RandomDirection() * v.Length(); OnExecute(ctx); } yield return(RunStatus.Success); }
public Affect Process(Character actor, Character target) { if (RandomMath.Percentage(Percentage)) { if (Type == SpecialAbilityType.Attack) { return(Affect); } else { int x_gap = Math.Abs(actor.MapLocation.X - target.MapLocation.X); int y_gap = Math.Abs(actor.MapLocation.Y - target.MapLocation.Y); if (x_gap + y_gap <= Range) { return(Affect); } } } return(null); }