Esempio n. 1
0
        public void Control(float thrust, float torque, bool firing)
        {
            Firing = firing;

            thrust = Fmath.Clamp(thrust, 0.0f, 1.0f);


            if (torque == 0)
            {
                // This is negative feedback, so im unsure why torque and angular velocity have different signs.
                torque = AngularVelocity * 10f;
            }
            torque = Fmath.Clamp(torque, -1.0f, 1.0f);

            /*
             * float epsilon = 0.001f;
             * if (torque < epsilon && torque > -epsilon)
             * {
             *  float dt = (CollisionBody.AngularVelocity > epsilon) ? 1f : ((CollisionBody.AngularVelocity < -epsilon) ? -1f : 0f);
             *  torque = dt;
             * }
             */


            CollisionBody.AddForce(Fmath.CosSin(Angle, Thrust * thrust));
            CollisionBody.AddTorque(Torque * torque);
        }
Esempio n. 2
0
        public override void Predict(long timestamp)
        {
            long  delta  = timestamp - baseTimestamp;
            float deltas = (delta / 1000.0f);

            Velocity = baseVelocity + Fmath.CosSin(Angle, Acceleration * deltas);
            Position = basePosition + (baseVelocity * deltas) + Fmath.CosSin(Angle, Acceleration * (deltas * deltas) / 2);
            Angle    = baseAngle + (AngularVelocity * deltas);
        }
Esempio n. 3
0
        public override void Draw(SpriteBatch batch)
        {
            Color color = (Creator == null) ? Color.White : Color.Lerp(Creator.Color, Color.White, 0.5f);
            float gSize = Fmath.Sqrt(Size) + 0.1f;

            Drawing.DrawTriangle(batch, Position, new Vector2(15, 5) * gSize, Angle, color);
            float tSize = gSize * Velocity.Length() / 6f;

            Drawing.DrawBullet(batch, Position - Fmath.CosSin(Angle, (12f + tSize) / 2f * gSize), new Vector2(tSize, 6) * gSize, Angle, color);
        }
Esempio n. 4
0
 private Ship NewPlayer(Color color)
 {
     return(new Ship(
                Fmath.RandomVector(Boundary / 2) + (Boundary / 4),
                Fmath.CosSin(Fmath.RandAngle(), Fmath.RandF(50)),
                color,
                Fmath.RandAngle(),
                Fmath.RandF(1f)
                ));
 }
Esempio n. 5
0
 private Asteroid NewAsteroid(float scale)
 {
     return(new Asteroid(
                Fmath.RandomVector(Boundary),
                Fmath.CosSin(Fmath.RandAngle(), Fmath.RandF(50)),
                scale / 2 + Fmath.RandF(scale / 2),
                Fmath.RandAngle(),
                Fmath.RandF(1f)
                ));
 }
Esempio n. 6
0
        public Projectile(Ship creator)
        {
            Position        = creator.Position;
            Angle           = creator.Angle;
            Velocity        = creator.Velocity + Fmath.CosSin(Angle, Speed);
            AngularVelocity = 0f;

            Position += Fmath.CosSin(Angle) * creator.Size.X / 2;

            Creator = creator;

            Creator.Push(-Fmath.CosSin(Angle, Recoil));
        }
Esempio n. 7
0
        public Missile(Ship creator, float size)
        {
            Size            = size;
            Position        = creator.Position;
            Angle           = creator.Angle;
            baseVelocity    = creator.baseVelocity + Fmath.CosSin(Angle, Speed);
            AngularVelocity = 0f;

            Position += Fmath.CosSin(Angle) * creator.Size.X / 2;
            Velocity  = baseVelocity;

            Creator = creator;

            Creator.Push(-Fmath.CosSin(Angle, Recoil));
        }
Esempio n. 8
0
 public override void Update(float delta)
 {
     Velocity += Fmath.CosSin(Angle, Acceleration) * delta;
     base.Update(delta);
 }