コード例 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        float dt = Time.fixedDeltaTime;

        car.UpdateLocationAndVelocity(dt);

        double rpm = car.GetVx() * 60.0 * car.GetGearRatio() * car.FinalDriveRatio / (2.0 * Mathf.PI * car.WheelRadius);

        car.OmegaE = rpm;

        transform.position = new Vector3(transform.position.x, transform.position.y, (float)car.GetX());
    }
コード例 #2
0
        //  This method redraws the GUI display.
        private void UpdateDisplay()
        {
            Graphics g      = drawingPanel.CreateGraphics();
            int      width  = drawingPanel.Width - 1;
            int      height = drawingPanel.Height - 1;

            //  Clear the current display.
            g.Clear(Color.White);

            //  Update the position of the soccerball on the screen.
            SolidBrush brush    = new SolidBrush(Color.Black);
            Pen        blackPen = new Pen(Color.Black, 1);

            //  Display the current time
            timeTextBox.Text = "" + (float)car.GetTime();

            //  Convert the velocity from m/s to km/hr and
            //  only show integer values
            velocityTextBox.Text = "" + (int)(car.GetVx() * 3.6);

            //  Only show integer values for rpm, gear number,
            //  and distance.
            rpmTextBox.Text      = "" + (int)car.OmegaE;
            gearTextBox.Text     = "" + (int)car.GearNumber;
            distanceTextBox.Text = "" + (int)car.GetX();

            //  Draw the car and the ground.
            g.DrawLine(blackPen, 0, 70, width, 70);
            g.DrawImage(carIcon, 100, 95, carWidth, carHeight);

            //  Draw the markers
            g.FillRectangle(brush, (int)rectangleOneX, 40, 10, 30);
            g.FillRectangle(brush, (int)rectangleTwoX, 40, 10, 30);

            //  Clean up the Graphics object.
            g.Dispose();
        }
コード例 #3
0
    //private bool isGnd = false;


    private void FixedUpdate()
    {
        //중력
        if (transform.position.y > 0.05)
        {
            vel += -9.81f * Time.fixedDeltaTime;
        }
        else
        {
            vel = 0f;
        }
        carRB.velocity = new Vector3(0f, vel, 0f);


        // //max rpm 도달 시간 출력
        // if (car.OmegaE <= 8000.0)
        // {
        //
        // }

        realtime += Time.fixedDeltaTime;


        //  Display the current time
        timeTextBox.text = "" + realtime;
        //timeTextBox.text = "" + (float)car.GetTime() * realtime;

        //  Convert the velocity from m/s to km/hr and
        //  only show integer values
        velocityTextBox.text = "" + (int)(car.GetVx() * 3.6);      //시간과 관련

        if ((int)(car.GetVx() * 3.6) < 271)
        {
            maxSpeedTime.text = realtime + "";
        }

        this.transform.Translate(new Vector3(0f, 0f, (float)(car.GetVx() * 3.6 * (float)timeIncrement)));   //거리=속도*시간
        //Debug.Log((float)(car.GetVx() * 3.6 * (float)timeIncrement));

        //  Only show integer values for rpm, gear number,
        //  and distance.
        rpmTextBox.text      = "" + (int)car.OmegaE;
        gearTextBox.text     = "" + (int)car.GearNumber;
        distanceTextBox.text = "" + (int)car.GetX();


        car.Mode = "accelerating";  //임시
        if (Input.GetKey(KeyCode.W))
        {
            car.Mode = "accelerating";
        }
        else if (Input.GetKey(KeyCode.Space))
        {
            car.Mode = "braking";
        }
        else
        {
            car.Mode = "accelerating";  //임시
            //car.Mode = "cruising";
        }

        if (Input.GetKeyDown(KeyCode.E) || car.OmegaE > 7500)   //테스트
        {
            car.ShiftGear(1);
        }
        if (Input.GetKeyDown(KeyCode.Q))
        {
            car.ShiftGear(-1);
        }

        //  Update the car velocity and position at the next
        //  time increment.
        timeIncrement = 0.06 * tempDiv;  //시간과 관련
        car.UpdateLocationAndVelocity(timeIncrement);

        //  Compute the new engine rpm value
        double rpm = car.GetVx() * 60.0 * car.GetGearRatio()
                     * car.FinalDriveRatio / (2.0 * Math.PI * car.WheelRadius); //시간과 관련

        car.OmegaE = rpm;

        // rpm이 redline을 넘어서면 Warning
        // rpm이 8000을 넘어서면 엔진 정지
        messageTextBox.text = "";
        if (car.OmegaE > car.Redline)
        {
            messageTextBox.text = "Warning: Exceeding redline rpm";
        }
        if (car.OmegaE > 8000.0)
        {
            messageTextBox.text = "You have blown the engine!";
            //gameTimer.Stop();
        }
    }