Beispiel #1
0
    public virtual void SetMaterialModsSeed(MaterialModifier[] mods, int seed, int maxMods)
    {
        var rand = new HelperRandom(seed);
        var mats = mods.OrderBy(x => rand.Double()).Take(rand.IntRange(0, maxMods + 1)).ToArray();

        UpdateMaterialMods(mats);
    }
Beispiel #2
0
        private void GeneratePlatforms()
        {
            int i         = -10;
            int lastWidth = 0;

            while (i < 200)
            {
                i += lastWidth;
                Platform floor = new Platform();
                floor.SetModel(HelperRandom.GetRandomNumber(0, 1) == 0 ? "Platform02" : "Platform10");
                float width = floor.GetMaxDimensions().X;
                if ((int)width > lastWidth)
                {
                    i += (int)(width / 2) + 1;
                }
                else if ((int)width == lastWidth)
                {
                    i += 3;
                }
                else
                {
                    i += 0;
                }
                floor.IsCollisionObject = true;
                floor.SetPosition(i, HelperRandom.GetRandomNumber(-3, -0.5f), 0);
                AddGameObject(floor);

                lastWidth = (int)width;
            }
        }
Beispiel #3
0
    public override void SetDimensionsSeed(int seed)
    {
        // Generate weapon dimensions from a seed
        var rand = new HelperRandom(seed);

        _height           = (float)rand.NormalValue(height);
        _width            = (float)rand.NormalValue(width);
        _depth            = (float)rand.NormalValue(depth);
        _heightInnerRatio = (float)rand.NormalValue(heightInnerRatio);
        _widthInnerRatio  = (float)rand.NormalValue(depthInnerRatio);
    }
Beispiel #4
0
 private void SpawnEnemies()
 {
     for (int i = 0; i < 100; i++)
     {
         KWEngine2Test.Objects.SweepAndPruneTest.Enemy e = new Enemy();
         e.SetModel("KWSphere");
         e.SetPosition((i - 50) / 2f, HelperRandom.GetRandomNumber(-7f, 10f), 0);
         e.IsCollisionObject = true;
         AddGameObject(e);
     }
 }
Beispiel #5
0
        public override void Act(KeyboardState ks, MouseState ms)
        {
            long now = GetCurrentTimeInMilliseconds();

            float z = (float)Math.Sin(_spawnTime + now / 75.0);

            //float y = -0.001f * (now * now * now) + 0.1f * (now * now);
            MoveOffset(z * KWEngine.DeltaTimeFactor * _movementSpeed, -_movementSpeed * KWEngine.DeltaTimeFactor, 0);

            if (now - _timestampLastShot > 200)
            {
                Vector3 lav = GetLookAtVector();

                Shot s = new Shot(this);
                s.SetModel("KWCube");
                s.SetRotation(this.Rotation);
                s.AddRotationZ(10, true);
                s.SetPosition(this.Position + 0.5f * lav);
                s.SetScale(0.075f, 0.075f, 0.5f);
                s.IsCollisionObject = true;
                s.SetGlow(1, 0.5f, 0, 1);
                CurrentWorld.AddGameObject(s);

                Shot s2 = new Shot(this);
                s2.SetModel("KWCube");
                s2.SetRotation(this.Rotation);
                s2.AddRotationZ(-10, true);
                s2.SetPosition(this.Position + 0.5f * lav);
                s2.SetScale(0.075f, 0.075f, 0.5f);
                s2.IsCollisionObject = true;
                s2.SetGlow(1, 0.5f, 0, 1);
                CurrentWorld.AddGameObject(s2);


                _timestampLastShot = now + HelperRandom.GetRandomNumber(0, 500);
            }

            if (!IsInsideScreenSpace)
            {
                CurrentWorld.RemoveGameObject(this);
            }

            base.Act(ks, ms);
        }
Beispiel #6
0
        public override void Act(KeyboardState kb, MouseState ms)
        {
            if (kb[Key.Escape])
            {
                CurrentWindow.SetWorld(new GameWorldStart());
                return;
            }

            long now = GetCurrentTimeInMilliseconds();

            if (now - _timeStamp > 3000)
            {
                ParticleObject smoke = new ParticleObject(new Vector3(-32.5f, 1, -22.5f), new Vector3(5, 5, 5), ParticleType.LoopSmoke1);
                smoke.SetColor(0.2f, 0.2f, 0.2f, 1);
                smoke.SetDuration(3.25f);
                AddParticleObject(smoke);
                _timeStamp = now;
            }

            if (now - _timeStampExp > _timeStampExpDiff)
            {
                Explosion ex = new Explosion(new Vector3(-35f, 4, -22.5f), 32, 1, 8, 2, ExplosionType.Cube, new Vector4(1, 1, 1, 1));
                //ex.SetAnimationAlgorithm(ExplosionAnimation.WindUp);
                AddGameObject(ex);

                _timeStampExp     = now;
                _timeStampExpDiff = HelperRandom.GetRandomNumber(3000, 10000);
                //_timeStampExpDiff = HelperRandom.GetRandomNumber(2000, 4000);
            }

            if (kb[Key.KeypadPlus])
            {
                _bloomradius        = HelperGeneral.Clamp(_bloomradius + 0.01f * KWEngine.DeltaTimeFactor, 0, 1);
                KWEngine.GlowRadius = _bloomradius;
                Console.WriteLine("Bloom radius: " + _bloomradius);
            }
            if (kb[Key.KeypadMinus])
            {
                _bloomradius        = HelperGeneral.Clamp(_bloomradius - 0.01f * KWEngine.DeltaTimeFactor, 0, 1);
                KWEngine.GlowRadius = _bloomradius;
                Console.WriteLine("Bloom radius: " + _bloomradius);
            }
        }
Beispiel #7
0
        public override void Act(KeyboardState kb, MouseState ms)
        {
            if (kb[Key.Escape])
            {
                CurrentWindow.SetWorld(new GameWorldStart());
                return;
            }

            long now  = GetCurrentTimeInMilliseconds();
            long diff = now - _timestampLast;

            if (!_test)
            {
                if (diff > 500)
                {
                    EnemySimple es = new EnemySimple();
                    es.SetModel("Spaceship6");
                    es.Name = "Enemy";
                    es.SetRotation(90, 0, 0);
                    es.SetPosition(HelperRandom.GetRandomNumber(-17f, 17f), 10.5f, 0);
                    es.IsCollisionObject = true;
                    AddGameObject(es);

                    _timestampLast = now;
                }
            }

            if (kb[Key.KeypadPlus])
            {
                _bloomradius        = HelperGeneral.Clamp(_bloomradius + 0.01f * KWEngine.DeltaTimeFactor, 0, 1);
                KWEngine.GlowRadius = _bloomradius;
                Console.WriteLine("Bloom radius: " + _bloomradius);
            }
            if (kb[Key.KeypadMinus])
            {
                _bloomradius        = HelperGeneral.Clamp(_bloomradius - 0.01f * KWEngine.DeltaTimeFactor, 0, 1);
                KWEngine.GlowRadius = _bloomradius;
                Console.WriteLine("Bloom radius: " + _bloomradius);
            }
        }
Beispiel #8
0
 public EnemySimple()
 {
     _spawnTime         = GetCurrentTimeInMilliseconds();
     _timestampLastShot = _spawnTime + HelperRandom.GetRandomNumber(0, 1000);
 }
Beispiel #9
0
        /// <summary>
        /// Explosionskonstruktormethode
        /// </summary>
        /// <param name="position">Position der Explosion</param>
        /// <param name="particleCount">Anzahl der Partikel</param>
        /// <param name="particleSize">Größe der Partikel</param>
        /// <param name="radius">Radius der Explosion</param>
        /// <param name="durationInSeconds">Dauer der Explosion in Sekunden</param>
        /// <param name="type">Art der Explosion</param>
        /// <param name="glow">Glühfarbe der Explosion</param>
        /// <param name="texture">Textur der Explosion (optional)</param>
        public Explosion(Vector3 position, int particleCount, float particleSize, float radius, float durationInSeconds, ExplosionType type, Vector4 glow, string texture = null)
        {
            _currentWorld = GLWindow.CurrentWindow.CurrentWorld;

            if (_currentWorld == null)
            {
                throw new Exception("World is null. Cannot create Explosion in an empty world.");
            }


            if (type == ExplosionType.Cube || type == ExplosionType.CubeRingY || type == ExplosionType.CubeRingZ)
            {
                _model = KWEngine.GetModel("KWCube");
            }
            else if (type == ExplosionType.Sphere || type == ExplosionType.SphereRingY || type == ExplosionType.SphereRingZ)
            {
                _model = KWEngine.GetModel("KWSphere");
            }
            else if (type == ExplosionType.Star || type == ExplosionType.StarRingY || type == ExplosionType.StarRingZ)
            {
                _model = KWEngine.KWStar;
            }
            else if (type == ExplosionType.Heart || type == ExplosionType.HeartRingY || type == ExplosionType.HeartRingZ)
            {
                _model = (KWEngine.KWHeart);
            }
            else if (type == ExplosionType.Skull || type == ExplosionType.SkullRingY || type == ExplosionType.SkullRingZ)
            {
                _model = (KWEngine.KWSkull);
            }
            else
            {
                _model = (KWEngine.KWDollar);
            }

            _type         = type;
            Glow          = glow;
            Position      = position;
            _amount       = particleCount >= 4 && particleCount <= MAX_PARTICLES ? particleCount : particleCount < 4 ? 4 : MAX_PARTICLES;
            _spread       = radius > 0 ? radius : 10;
            _duration     = durationInSeconds > 0 ? durationInSeconds : 2;
            _particleSize = particleSize > 0 ? particleSize : 1f;

            for (int i = 0, arrayIndex = 0; i < _amount; i++, arrayIndex += 4)
            {
                if ((int)type < 100)
                {
                    int randomIndex  = HelperRandom.GetRandomNumber(0, AxesCount - 1);
                    int randomIndex2 = HelperRandom.GetRandomNumber(0, AxesCount - 1);
                    int randomIndex3 = HelperRandom.GetRandomNumber(0, AxesCount - 1);
                    _directions[arrayIndex]     = Axes[randomIndex].X;
                    _directions[arrayIndex + 1] = Axes[randomIndex2].Y;
                    _directions[arrayIndex + 2] = Axes[randomIndex3].Z;
                    _directions[arrayIndex + 3] = HelperRandom.GetRandomNumber(0.1f, 1.0f);
                }
                else if ((int)type >= 100 && (int)type < 1000)
                {
                    _directions[arrayIndex]     = 0;
                    _directions[arrayIndex + 1] = 1;
                    _directions[arrayIndex + 2] = 0;
                    _directions[arrayIndex + 3] = HelperRandom.GetRandomNumber(0.01f, 1.0f);
                }
                else
                {
                    _directions[arrayIndex]     = 0;
                    _directions[arrayIndex + 1] = 0;
                    _directions[arrayIndex + 2] = 1;
                    _directions[arrayIndex + 3] = HelperRandom.GetRandomNumber(0.01f, 1.0f);
                }
            }
            int  texId        = -1;
            bool textureFound = false;

            if (texture != null && texture.Length > 0)
            {
                textureFound = KWEngine.CustomTextures[_currentWorld].TryGetValue(texture, out texId);
            }
            if (textureFound)
            {
                _textureId = texId;
            }
            else
            {
                if (texture != null)
                {
                    Action a = () => SetTexture(texture);
                    HelperGLLoader.AddCall(this, a);
                }
            }
        }