Exemple #1
0
        public override void Think(float curTime, float deltaTime)
        {
            float noiseLeft = CMath.Lerp(1 - (startTime + falloff - OwningWorld.CurrentTime()) / falloff, startNoise, 0);

            Console.WriteLine(noiseLeft);
            noiseLeft = Math.Max(noiseLeft, 0);

            OwningWorld.SetNoise(noiseLeft);

            if (noiseLeft <= 0)
            {
                this.Destroy();
            }
        }
Exemple #2
0
        public override void Think(float curTime, float deltaTime)
        {
            if (Interop.IsKeyDown(Keys.Space))
            {
                if (!wasPressed)
                {
                    OnShoot();
                }
                wasPressed = true;
            }
            else
            {
                wasPressed = false;
            }

            float thrust = 0;

            if (Interop.IsKeyDown(Keys.Up) || Interop.IsKeyDown(Keys.W))
            {
                thrust += 1;
            }
            if (Interop.IsKeyDown(Keys.Down) || Interop.IsKeyDown(Keys.S))
            {
                thrust -= 1;
            }
            thrust *= 7;

            if (IsBoosting())
            {
                thrust += 20;
            }
            else if (velocity.Length() > 1500f)
            {
                thrust = 0f;
            }

            float spin = 0;

            if (Interop.IsKeyDown(Keys.Left) || Interop.IsKeyDown(Keys.A))
            {
                spin += 1;
            }
            if (Interop.IsKeyDown(Keys.Right) || Interop.IsKeyDown(Keys.D))
            {
                spin -= 1;
            }
            spin *= 5;

            rotationVelocity += spin * deltaTime;

            rotation  = (rotation + rotationVelocity * deltaTime) % 360;
            velocity += new Vector(0, thrust).Rotate(rotation - (float)Math.PI / 2f);

            //Apply dampening
            float dampen = thrust != 0 ? 0.9999f : 0.994f;

            if (IsBoosting())
            {
                dampen = 1f;
            }
            velocity         = velocity * (thrust != 0 ? 0.9999f : 0.994f);
            rotationVelocity = rotationVelocity * 0.99f;

            SetPosition(this.Position + velocity * deltaTime);

            long tickDiff = OwningWorld.CurrentTick() - lastShoot;

            if (tickDiff > 100 || tickDiff % 16 == 0)
            {
                OwningWorld.SetTone((int)(this.velocity.Length() / 8 + 90));
            }
            else
            {
                OwningWorld.SetTone(1000 - (int)tickDiff * 2);
            }


            OwningWorld.SetNoise(IsBoosting() ? 20f + this.velocity.Length() / 64 : 0f);
            if (this.velocity.Length() > 10000)
            {
                OwningWorld.SetNoise(0);
            }
        }