Example #1
0
        private static Particle GenerateNewParticle(ParticlesStyle style)
        {
            Texture2D texture  = textures[RandomNumbersHelper.ReturnRandomNumber(textures.Count)];
            Vector2   position = EmitterLocation;
            Vector2   velocity = new Vector2(
                1f * (float)(RandomNumbersHelper.ReturnRandomDouble() * 2 - 1),
                1f * (float)(RandomNumbersHelper.ReturnRandomDouble() * 2 - 1));
            float angle           = 0;
            float angularVelocity = 0.1f * (float)(RandomNumbersHelper.ReturnRandomDouble() * 2 - 1);
            Color color;
            float size = (float)RandomNumbersHelper.ReturnRandomDouble();
            int   ttl  = 5 + RandomNumbersHelper.ReturnRandomNumber(20);

            switch (style)
            {
            case ParticlesStyle.ATTACK:
                color     = Color.DarkRed;
                position += new Vector2(Constants.TILESIZE / 2, Constants.TILESIZE / 2);
                size      = size / 2;
                break;

            default:
                color = new Color(
                    (float)RandomNumbersHelper.ReturnRandomDouble(),
                    (float)RandomNumbersHelper.ReturnRandomDouble(),
                    (float)RandomNumbersHelper.ReturnRandomDouble());
                break;
            }

            return(new Particle(texture, position, velocity, angle, angularVelocity, color, size, ttl));
        }
Example #2
0
 public NonPlayerCharacter(string SpriteName = Constants.NPC.DEFAULT_SPRITE) : base()
 {
     aiBehaviorComponent             = new AIBehaviorsComponent();
     PhysicsComponent.position       = new Vector2(RandomNumbersHelper.ReturnRandomNumber(Constants.Map.DEFAULT_MAP_WIDTH - 1) * Constants.TILESIZE, RandomNumbersHelper.ReturnRandomNumber(Constants.Map.DEFAULT_MAP_HEIGHT - 1) * Constants.TILESIZE);
     PhysicsComponent.destination    = this.PhysicsComponent.position;
     PhysicsComponent.Speed          = Constants.NPC.DEFAULT_SPEED;
     SpriteComponent.TextureName     = SpriteName;
     SpriteComponent.TextureModifier = Constants.NPC.DEFAULT_NPC_SIZE_MODIFIER;
 }
Example #3
0
        public void TestAverageMethodTest()
        {
            // Arrange
            var numbers = RandomNumbersHelper.GetRandomNumbers();

            // Act
            var actualResult   = numbers.TestAverage();
            var expectedResult = numbers.Average();

            // Assert
            expectedResult.Should().Be(actualResult);
        }
Example #4
0
        public void TestSelectOnCubeTest()
        {
            // Arrange
            Func <int, double> cube = a => Math.Pow(a, 3);
            var numbers             = RandomNumbersHelper.GetRandomNumbers();

            // Act
            var actualResult   = numbers.TestSelect(cube);
            var expectedResult = numbers.Select(cube);

            // Assert
            expectedResult.Should().BeEquivalentTo(actualResult);
        }
Example #5
0
        public void TestSelectOnTripleTest()
        {
            // Arrange
            Func <int, int> triple  = a => a * 3;
            var             numbers = RandomNumbersHelper.GetRandomNumbers();

            // Act
            var actualResult   = numbers.TestSelect(triple);
            var expectedResult = numbers.Select(triple);

            // Assert
            expectedResult.Should().BeEquivalentTo(actualResult);
            CollectionAssert.AreEqual(expectedResult, actualResult);
        }
Example #6
0
        private static Particle GenerateNewParticle()
        {
            Texture2D texture  = textures[RandomNumbersHelper.ReturnRandomNumber(textures.Count)];
            Vector2   position = EmitterLocation;
            Vector2   velocity = new Vector2(
                1f * (float)(RandomNumbersHelper.ReturnRandomDouble() * 2 - 1),
                1f * (float)(RandomNumbersHelper.ReturnRandomDouble() * 2 - 1));
            float angle           = 0;
            float angularVelocity = 0.1f * (float)(RandomNumbersHelper.ReturnRandomDouble() * 2 - 1);
            Color color           = new Color(
                (float)RandomNumbersHelper.ReturnRandomDouble(),
                (float)RandomNumbersHelper.ReturnRandomDouble(),
                (float)RandomNumbersHelper.ReturnRandomDouble());
            float size = (float)RandomNumbersHelper.ReturnRandomDouble();
            int   ttl  = 20 + RandomNumbersHelper.ReturnRandomNumber(40);

            return(new Particle(texture, position, velocity, angle, angularVelocity, color, size, ttl));
        }
Example #7
0
        private static void AIIdle(NonPlayerCharacter caller, GameMap map)
        {
            if (caller.aiBehaviorComponent.Clock.isIntervalTicked(Constants.NPC.DEFAULT_UNIT_MOVE_INTERVAL_IDLE))
            {
                // Negative or positive
                if (RandomNumbersHelper.ReturnRandomNumber(2) == 1)
                {
                    // X or Y
                    if (RandomNumbersHelper.ReturnRandomNumber(2) == 1)
                    {
                        caller.PhysicsComponent.destination += new Vector2(-1 * Constants.TILESIZE, 0);
                    }
                    else
                    {
                        caller.PhysicsComponent.destination += new Vector2(0, -1 * Constants.TILESIZE);
                    }
                }
                else
                {
                    // X or Y
                    if (RandomNumbersHelper.ReturnRandomNumber(2) == 1)
                    {
                        caller.PhysicsComponent.destination += new Vector2(Constants.TILESIZE, 0);
                    }
                    else
                    {
                        caller.PhysicsComponent.destination += new Vector2(0, Constants.TILESIZE);
                    }
                }

                if (CheckColission(map, caller.PhysicsComponent.destination))
                {
                    caller.PhysicsComponent.destination = caller.PhysicsComponent.position;
                }
            }
        }