Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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 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);
        }
Example #5
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);
             * }
             */
        }
Example #6
0
        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);
            }
        }
Example #7
0
        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;
            }
        }
Example #8
0
        /// <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);
        }
Example #9
0
        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);
        }
Example #10
0
        /// <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);
        }
Example #11
0
        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);
        }
Example #12
0
        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());
        }
Example #13
0
        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);
        }
Example #14
0
        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();
                }
            }
        }
Example #15
0
        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);
        }
Example #17
0
        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);
            }
        }
Example #18
0
        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);
        }
Example #19
0
        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));
        }
Example #20
0
        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;
                    }
                }
            }
        }
        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);
        }
        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);
        }
        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;

            // direction changing
            if (timeSinceLastChange >= dirChangeTime)
            {
                timeSinceLastChange = 0f;
                dirChangeTime       = RandomMath.RandomBetween(MinDirectionChangeTime, MaxDirectionChangeTime);
                CurrentDirection    = RandomMath.RandomDirection();
            }
        }
Example #24
0
        protected override void OnNextMove()
        {
            base.OnNextMove();

            // check for enemy facing
            List <Thing> facing = ParentThing.DetectCollisions(ParentThing.FacingDirection);

            WasCombat = IsCombat;
            IsCombat  = false;
            float randomVal = RandomMath.RandomUnit();

            foreach (Thing t in facing)
            {
                if (t.GetType() == EnemyType && t.Health > 0 && !t.IsStealthy)
                {
                    IsCombat            = true;
                    IsTargetMoveDefined = true;
                    TargetMove          = Vector2.Zero;
                    if (!WasCombat || randomVal < 0.08f)
                    {
                        var damage = RandomMath.RandomBetween(MinDamage, MaxDamage);
                        HurtBehavior.Apply(t, damage, MaxDamage);
                        t.Health -= damage;
                    }
                    break; // only attack one thing at a time
                }
            }

            if (IsCombat)
            {
                if (!WasCombat || randomVal < 0.08f)
                {
                    var dist = (ParentThing.Position - Level.Current.hero.Position).Length();
                    Level.Current.Sound.PlayRandomCombatSound(0.2f, 0.3f, dist);
                }
            }
        }
Example #25
0
        public void NextCharacterTurn()
        {
            LastAction = LastAction.None;
            var selectedCharacters = from key in characters.Keys
                                     where characters[key].ActionGauge > 1
                                     select key;
            int count = selectedCharacters.Count();

            while (count == 0)
            {
                IncreaseActionGauges();
                selectedCharacters = from key in characters.Keys
                                     where characters[key].ActionGauge > 1
                                     select key;
                count = selectedCharacters.Count();
            }

            // Dos personagens prontos para jogar, selecione aleatóriamente
            float index = RandomMath.RandomBetween(0, count);

            if (index == count)
            {
                index--;
            }

            actualCharacter = selectedCharacters.ElementAt((int)Math.Floor(index));
            if (ActualCharacter.Health.IsDead)
            {
                ActualCharacterHasAttacked = true;
                ActualCharacterHasWalked   = true;
                FinalizeCharacterTurn();
                NextCharacterTurn();
            }

            ActualCharacterHasAttacked = false;
            ActualCharacterHasWalked   = false;
        }
Example #26
0
        public override void Process(Entity entity, ThingComp tc, RandomWanderComp rwc)
        {
            if (!rwc.IsActive)
            {
                return;
            }
            rwc.UpdateComp(dt);
            rwc.CurrentDirectionChangeTime -= dt;
            Vector2 dir = rwc.CurrentDirection;

            if (dir.Length() < 0.1f)
            {
                dir = Vector2.Zero;
            }
            rwc.TargetMove = dir;

            // direction changing after some random time
            if (rwc.CurrentDirectionChangeTime <= 0)
            {
                // TODO double version of randombetween
                rwc.CurrentDirectionChangeTime = RandomMath.RandomBetween((float)rwc.MinDirectionChangeTime, (float)rwc.MaxDirectionChangeTime);
                rwc.CurrentDirection           = RandomMath.RandomDirection();
            }
        }
        public BadPixel(Thing chaseTarget)
            : base("shape2x2")
        {
            IsCollisionFree    = false;
            DrawInfo.DrawColor = new Color(255, 10, 4);

            SubsumptionBehavior sub = new SubsumptionBehavior();

            Add(sub);

            Chasing            = new ChaseBehavior(chaseTarget);
            Chasing.MoveSpeed  = RandomMath.RandomBetween(0.47f, 0.75f);
            Chasing.ChaseRange = 6f; // RandomMath.RandomBetween(12f, 40f);
            sub.Add(Chasing);

            Turning           = new AlwaysTurnRightBehavior();
            Turning.MoveSpeed = Chasing.MoveSpeed; //RandomMath.RandomBetween(0.57f, 1.05f);
            Turning.MoveSpeed = 0.7f;
            sub.Add(Turning);

            Wandering           = new RandomWanderBehavior(2.7f, 11.3f);
            Wandering.MoveSpeed = 0.7f;
            sub.Add(Wandering);
        }
Example #28
0
        // get some new randomness in this sucker
        public void Reroll()
        {
            try
            {
                // new sound instance plz
                _sound = null;

                int totWeight = 0;
                for (int i = 0; i < mData.mEntries.Length; i++)
                {
                    totWeight += mData.mEntries[i]._weight;
                }

                int weight = 0;
                switch (mData.mVariation)
                {
                case 0:     //kOrdered
                    mData.currIdx++;
                    if (mData.currIdx >= mData.mEntries.Length)
                    {
                        mData.currIdx = 0;
                    }
                    break;

                case 2:    //kRandom
                    weight        = GSGE.RandomMath.RandomInt(totWeight);
                    totWeight     = 0;
                    mData.currIdx = 0;
                    for (int i = 0; i < mData.mEntries.Length; i++)
                    {
                        totWeight += mData.mEntries[i]._weight;
                        if (weight < totWeight)
                        {
                            mData.currIdx = i;
                            break;
                        }
                    }
                    break;

                case 3:    //kRandomNoImmediateRepeat
                    if (mData.currIdx >= 0 && mData.currIdx < mData.mEntries.Length)
                    {
                        totWeight -= mData.mEntries[mData.currIdx]._weight;
                    }
                    else
                    {
                        mData.currIdx = 0;
                    }

                    weight    = GSGE.RandomMath.RandomInt(totWeight);
                    totWeight = 0;
                    for (int i = 0; i < mData.mEntries.Length; i++)
                    {
                        if (i == mData.currIdx)
                        {
                            continue;
                        }

                        totWeight += mData.mEntries[i]._weight;
                        if (weight < totWeight)
                        {
                            mData.currIdx = i;
                            break;
                        }
                    }

                    break;

                case 4:    //kShuffle
                    mData.shuffleIdx++;
                    if (mData.shuffleIdx >= mData.mEntries.Length)
                    {
                        mData.shuffleIdx = 0;

                        int i;

                        // reorder next random set
                        List <int> ls = new List <int>();
                        for (i = 0; i < mData.mEntries.Length; i++)
                        {
                            ls.Add(i);
                        }

                        i = 0;
                        while (ls.Count > 0)
                        {
                            int idx = GSGE.RandomMath.RandomInt(ls.Count);
                            mData.shuffle[i] = ls[idx];
                            ls.RemoveAt(idx);
                            i++;
                        }
                    }
                    mData.currIdx = mData.shuffle[mData.shuffleIdx];
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            catch (Exception)
            {
                mData.currIdx = 0;
            }

            if (0 <= mData.currIdx && mData.currIdx < mData.mEntries.Length)
            {
                PlayWaveHelper pwh = mData.mEntries[mData.currIdx];

                AudioEngine audioengine = AudioManager.GetAudioManager().GetAudioEngine();
                foreach (WaveBank wavebank in audioengine.Wavebanks)
                {
                    if (wavebank.IsLoaded && wavebank.BankName == pwh._bankname)
                    {
                        if (0 <= pwh._index && wavebank.mSounds.Length > pwh._index)
                        {
                            SoundData sd = wavebank.mSounds[pwh._index];
                            sd.Looping = mData.mLoopCount == 255;
                            _sound     = new Sound(sd);
                        }
                        break;
                    }
                }
                //GSGE.Debug.assert(_sound != null);

                mVolVar   = RandomMath.RandomBetween(mData.mVolumeVariationMin, mData.mVolumeVariationMax) + mData.mVolume;
                mPitchVar = RandomMath.RandomBetween(mData.mPitchVariationMin, mData.mPitchVariationMax);
            }
        }
Example #29
0
        public void PlayRandomCombatSound(float volumeMin, float volumeMax)
        {
            int n = RandomMath.RandomIntBetween(1, 6);

            Play(n, RandomMath.RandomBetween(volumeMin, volumeMax));
        }
Example #30
0
 public void PlaySound(int effect, float volumeMin, float volumeMax)
 {
     Play(effect, RandomMath.RandomBetween(volumeMin, volumeMax));
 }