コード例 #1
0
ファイル: Engine.cs プロジェクト: samuelarbibe/car-game
        public void Update(BaseKeys keys)
        {
            actualTorque = -20;

            if (keys.GoLeft())
            {
                steeringRotation += -0.1f;
            }
            else if (keys.GoRight())
            {
                steeringRotation += 0.1f;
            }
            else if (steeringRotation > 0)
            {
                steeringRotation += -0.1f;
            }
            else if (steeringRotation < 0)
            {
                steeringRotation += 0.1f;
            }

            //else if (steeringRotation < 0) steeringRotation += 0.2f;
            //else if (steeringRotation > 0) steeringRotation -= 0.2f;

            //steeringRotation += 1 / 100;

            steeringRotation = MathHelper.Clamp(steeringRotation * 0.97f, -maxSteeringRotation, maxSteeringRotation);

            if (keys.GoUp()) // push gas
            {
                // Acceleration = (wheel power - drag power - rolling resistance power)/(mass x speed)
                actualTorque = Torque;
            }

            if (keys.GoDown()) // push break
            {
                actualTorque = brakeTorque;
            }
        }
コード例 #2
0
 public Car(BaseKeys directionKeys, Texture2D texture, Vector2 position, Rectangle?sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth, float speed) : base(directionKeys, texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth, speed)
 {
     this.engine    = new Engine();
     mass           = 1200;
     Game1.Updated += this.update;
 }