示例#1
0
    void Awake()
    {
        _horizontalInput = new AxisTrigger();
        _useBonusInput   = new ActionTrigger();

        _carPhysics = GetComponent <CarPhysics>();
    }
    private void Start()
    {
        //NullCheck our nav agent
        if (aiAgent == null)
        {
            Debug.LogWarning("AI Car does not have a nav mesh agent assigned");
        }
        //Initalise our path to be an empty path
        latestPath = new NavMeshPath();

        //Get the Car we are controlling, this is a required component so we will have it,
        //thus no null check
        controllingCar = GetComponent <CarPhysics>();

        //Set us to move forwards
        currentGear = Gear.Forward;

        //Set our car stuck timer to 0
        carStuckTimer = 0f;

        //If we do not have a target then try and find the player
        if (target == null)
        {
            target = FindObjectOfType <PlayerMovement>().gameObject;
        }
    }
示例#3
0
文件: Car.cs 项目: zbx1425/OpenBVE
 internal Car(Train baseTrain)
 {
     this.baseTrain = baseTrain;
     this.Specs     = new CarPhysics();
     this.Sounds    = new CarSounds();
     InitializeCarSounds();
 }
    private void Awake()
    {
        // get the car controller reference
        carController = GetComponent <CarPhysics>();

        // give the random perlin a random value
        randomPerlin = Random.value * 100;
    }
示例#5
0
 private void RespawnCheck(CarPhysics currentVehicle)
 {
     if (currentVehicle.transform.position.y < -0.5f)
     {
         fallen = true;
         onFall?.Invoke(this);
     }
 }
 private void Start()
 {
     //Get out car physics
     controllingCar = GetComponent <CarPhysics>();
     if (controllingCar == null)
     {
         Debug.LogWarning("Player Movement does not have a CAR assigned");
     }
 }
示例#7
0
    public void OnBuildingEntered(CarPhysics vehicle, BuildingController.BuildingType buildingType)
    {
        var driver = vehicle.GetComponentInParent <AbstractDriver>();

        if (driver != null && driver is HumanDriver)
        {
            //locationManager.SetLocation((int)buildingType);
            Doozy.Engine.GameEventMessage.SendEvent(locationDoozyEvents[(int)buildingType]);
        }
    }
示例#8
0
    void Start()
    {
        carScript = GetComponent <CarPhysics>();

        for (int i = 0; i < axelData.Length; i++)
        {
            axelData[i].armLengthLeft  = Vector3.Distance(axelData[i].armLeft.position, axelData[i].armTargetLeft.position);
            axelData[i].armLengthRight = Vector3.Distance(axelData[i].armRight.position, axelData[i].armTargetRight.position);
        }
    }
    void Awake()
    {
        physics = GetComponent <CarPhysics>();

        ResetStats();

        driveState = new IdleMoveState();
        driveState = driveState.Init(this);
        healthManager.SetHealth(stats.health);
    }
    void Start()
    {
        carScript = GetComponent <CarPhysics>();

        refreshTimer = 1f / Screen.currentResolution.refreshRate;

        if (wheelInfo.Length > 0)
        {
            matInstances = new Material[wheelInfo.Length];
            for (int x = 0; x < wheelInfo.Length; x++)
            {
                matInstances[x]      = new Material(wheelInfo[x].material);
                matInstances[x].name = "Material Instance " + x.ToString();

                for (int i = 0; i < meshes.Length; i++)
                {
                    for (int j = 0; j < meshes[i].sharedMaterials.Length; j++)
                    {
                        if (meshes[i].sharedMaterials[j] == wheelInfo[x].material)
                        {
                            Debug.Log("found material match at " + meshes[i].name);
                            Material[] mats = meshes[i].sharedMaterials;
                            mats[j] = matInstances[x];
                            meshes[i].sharedMaterials = mats;

                            if (meshes[i].sharedMaterials[j] == matInstances[x])
                            {
                                Debug.Log("material replacement successful");
                            }
                        }
                    }
                }

                for (int i = 0; i < skinnedMeshes.Length; i++)
                {
                    for (int j = 0; j < skinnedMeshes[i].sharedMaterials.Length; j++)
                    {
                        if (skinnedMeshes[i].sharedMaterials[j] == wheelInfo[x].material)
                        {
                            Debug.Log("found material match at " + skinnedMeshes[i].name);
                            Material[] mats = skinnedMeshes[i].sharedMaterials;
                            mats[j] = matInstances[x];
                            skinnedMeshes[i].sharedMaterials = mats;

                            if (skinnedMeshes[i].sharedMaterials[j] == matInstances[x])
                            {
                                Debug.Log("material replacement successful");
                            }
                        }
                    }
                }
            }
        }
    }
示例#11
0
 void Start()
 {
     startingFuel      = 50;
     starterRank       = SceneObjects.current.drivers.Count;
     carPhysics        = GetComponent <CarPhysics>();
     carPhysics.driver = this;
     carPhysics.fuel   = startingFuel;
     RpcSelectCar(tempCarIndex);
     SceneObjects.current.drivers.Add(gameObject);
     RpcSetDriverStartUI();
     driverName = "Driverface " + randomPos.ToString();
 }
示例#12
0
 private void Awake()
 {
     _transform    = transform;
     _gameObject   = gameObject;
     _cacheManager = CacheManager.Instance;
     Movement      = new CarPhysics(this);
     AI            = new CarAI(this);
     _camera       = CameraManager.Instance.MainCamera.GetComponent <CameraController>();
     _rigidBody    = GetComponent <Rigidbody>();
     EngineRunning = true;
     _currentVehicleHealthGroup = 1;
 }
示例#13
0
    public void setPropertiesToCar()
    {
        CarPhysics p = transform.parent.GetComponent <CarPhysics>();

        p.aerodynamic    = speed;
        p.acceleration   = acceleration;
        p.turnStrength   = turnStrength;
        p.Traction       = Traction;
        p.orientStrength = orientStrength;
        p.brakeFactor    = brakeFactor;
        p.thrusters      = thrusters;
        p.tyres          = tyres;

        p.setTempAerodynamic();
    }
示例#14
0
    // Use this for initialization
    void Start()
    {
        carController = GetComponent <CarPhysics>();
        carController.VehicleNetworkManager = this;
        rb = GetComponent <Rigidbody>();

        if (isLocalPlayer)
        {
            carController.usedByPlayer = true;
        }

        else
        {
            carController.usedByPlayer = false;
        }
    }
示例#15
0
    // Use this for initialization
    void Start()
    {
        carScript = GetComponent <CarPhysics>();

        if (lightMaterial)
        {
            lightMat      = new Material(lightMaterial);
            lightMat.name = "Instanced Lights";

            MeshRenderer[] renderers = GetComponentsInChildren <MeshRenderer>();

            for (int i = 0; i < renderers.Length; i++)
            {
                for (int j = 0; j < renderers[i].sharedMaterials.Length; j++)
                {
                    if (renderers[i].sharedMaterials[j] == lightMaterial)
                    {
                        Debug.Log("found material match at " + renderers[i].name);
                        Material[] mats = renderers[i].sharedMaterials;
                        mats[j] = lightMat;
                        renderers[i].sharedMaterials = mats;

                        if (renderers[i].sharedMaterials[j] == lightMat)
                        {
                            Debug.Log("material replacement successful");
                        }
                    }
                }
            }

            Debug.Log(Shader.PropertyToID("Headglass"));

            lightMat.SetColor("_Headglass", headlights * unlitBrightness);
            lightMat.SetColor("_Tailglass", brakelights * unlitBrightness);
            lightMat.SetColor("_Reverseglass", reverselights * unlitBrightness);

            lightMat.SetColor("_Headlights", headlights);
            lightMat.SetColor("_Taillights", brakelights);
            lightMat.SetColor("_Reverselights", reverselights);
            lightMat.SetFloat("_Hlight", 1);
            lightMat.SetFloat("_Tlight", 1);
            lightMat.SetFloat("_Rlight", 1);
        }
    }
示例#16
0
    public void SetVehicle(int vehicleIndex)
    {
        index = Mathf.Clamp(vehicleIndex, 0, allVehicles.Length - 1);
        if (allVehicles.Length > 0)
        {
            CarPhysics prevVehicle = null;
            if (prevIndex >= 0 && prevIndex < allVehicles.Length)
            {
                prevVehicle = allVehicles[prevIndex];
                if (prevVehicle != null)
                {
                    prevVehicle.SetVisible(false);
                }
            }

            currentVehicle = allVehicles[index];
            currentVehicle.Match(prevVehicle);
            currentVehicle.SetVisible(true);
        }
        prevIndex = index;
    }
示例#17
0
    private static void AvoidObstacles(CarPhysics currentVehicle, ref float nextGas, ref float nextSteer, ref float nextBrake, float maxSteer = 0.2f)
    {
        var forwardHitInfo = currentVehicle.GetForwardHitInfo();
        var leftHitInfo    = currentVehicle.GetLeftHitInfo();
        var rightHitInfo   = currentVehicle.GetRightHitInfo();
        var rearHitInfo    = currentVehicle.GetRearHitInfo();

        if (forwardHitInfo.hit)
        {
            if (forwardHitInfo.info.distance <= 5)
            {
                nextGas   = -1;
                nextSteer = leftHitInfo.info.distance < rightHitInfo.info.distance ? -1 : 1;
            }
            else if (currentVehicle.currentForwardSpeed > 5)
            {
                nextBrake = 1;
            }
        }
        else if (rearHitInfo.hit)
        {
            if (rearHitInfo.info.distance <= 5)
            {
                nextGas   = 1;
                nextSteer = leftHitInfo.info.distance < rightHitInfo.info.distance ? 1 : -1;
            }
            else if (currentVehicle.currentForwardSpeed < -5)
            {
                nextBrake = 1;
            }
        }
        else if (leftHitInfo.hit && leftHitInfo.info.distance <= 1)
        {
            nextSteer = maxSteer;
        }
        else if (rightHitInfo.hit && rightHitInfo.info.distance <= 1)
        {
            nextSteer = -maxSteer;
        }
    }
示例#18
0
文件: Car.cs 项目: r1sc/Open76
        private void Explode()
        {
            _rigidBody.AddForce(Vector3.up * _rigidBody.mass * 5f, ForceMode.Impulse);

            CarInput carInputController = GetComponent <CarInput>();

            if (carInputController != null)
            {
                Destroy(carInputController);
            }

            AudioSource explosionSource = _cacheManager.GetAudioSource(_gameObject, "xcar");

            if (explosionSource != null)
            {
                explosionSource.volume = 0.9f;
                explosionSource.Play();
            }

            EngineRunning = false;
            Destroy(_engineLoopSound);
            Destroy(_engineStartSound);

            Destroy(_carPhysics);
            _carPhysics = null;
            AI          = null;

            WeaponsController  = null;
            SpecialsController = null;
            SystemsPanel       = null;
            GearPanel          = null;
            _compassPanel      = null;
            RadarPanel         = null;

            Destroy(transform.Find("FrontLeft").gameObject);
            Destroy(transform.Find("FrontRight").gameObject);
            Destroy(transform.Find("BackLeft").gameObject);
            Destroy(transform.Find("BackRight").gameObject);
        }
示例#19
0
    void Start()
    {
        _Physics = GetComponent <CarPhysics>();



        if (!didQueryNumOfCtrlrs)
        {
            didQueryNumOfCtrlrs = true;

            int queriedNumberOfCtrlrs = XCI.GetNumPluggedCtrlrs();

            if (queriedNumberOfCtrlrs == 1)
            {
                Debug.Log("Only " + queriedNumberOfCtrlrs + " Xbox controller plugged in.");
            }
            else if (queriedNumberOfCtrlrs == 0)
            {
                Debug.Log("No Xbox controllers plugged in!");
            }
            else
            {
                Debug.Log(queriedNumberOfCtrlrs + " Xbox controllers plugged in.");
            }

            XCI.DEBUG_LogControllerNames();

            // This code only works on Windows
            if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)
            {
                Debug.Log("Windows Only:: Any Controller Plugged in: " + XCI.IsPluggedIn(XboxController.Any).ToString());

                Debug.Log("Windows Only:: Controller 1 Plugged in: " + XCI.IsPluggedIn(XboxController.First).ToString());
                Debug.Log("Windows Only:: Controller 2 Plugged in: " + XCI.IsPluggedIn(XboxController.Second).ToString());
                Debug.Log("Windows Only:: Controller 3 Plugged in: " + XCI.IsPluggedIn(XboxController.Third).ToString());
                Debug.Log("Windows Only:: Controller 4 Plugged in: " + XCI.IsPluggedIn(XboxController.Fourth).ToString());
            }
        }
    }
示例#20
0
    private void Drive(CarPhysics currentVehicle)
    {
        //Calculate steer value to reach target
        float   nextSteer         = 0;
        Vector3 vehicleFrontPoint = currentVehicle.vehicleRigidbody.transform.GetPointInBounds(new Vector3(0, -0.5f, 0.9f));
        Vector3 hypotenuse        = targets[currentTargetIndex].position - vehicleFrontPoint;
        float   targetAngle       = Vector3.SignedAngle(hypotenuse.normalized, targets[currentTargetIndex].forward, currentVehicle.transform.up);
        float   vehicleAngle      = -Vector3.SignedAngle(currentVehicle.transform.forward, hypotenuse.normalized, currentVehicle.transform.up);
        //Debug.Log(vehicleAngle.ToString());
        float oppSide = -Mathf.Sin(targetAngle * Mathf.Deg2Rad) * hypotenuse.magnitude;

        Debug.DrawRay(vehicleFrontPoint, hypotenuse, Color.yellow);
        Debug.DrawRay(vehicleFrontPoint, currentVehicle.transform.right * oppSide, Color.yellow);
        if (Mathf.Abs(oppSide) >= minDistance && (Mathf.Abs(vehicleAngle) < maxAngle || Mathf.Sign(vehicleAngle) != Mathf.Sign(oppSide)))
        {
            nextSteer = Mathf.Clamp(oppSide / laneDistance, -1, 1) * maxSteer;
        }
        else if (Mathf.Abs(vehicleAngle) >= maxAngle)
        {
            nextSteer = maxSteer * -Mathf.Sign(vehicleAngle);
        }
        else if (Mathf.Abs(oppSide) < minDistance && Mathf.Abs(vehicleAngle) > minAngle)
        {
            nextSteer = maxSteer * -Mathf.Sign(vehicleAngle) / 8;
        }

        //Calculating gas value to conform to set speed
        float nextGas   = currentVehicle.currentForwardSpeed < spawnSpeed ? 1 : 0;
        float nextBrake = 0;

        AvoidObstacles(currentVehicle, ref nextGas, ref nextSteer, ref nextBrake, maxSteer);

        //Apply values to car
        currentVehicle.gas   = nextGas;
        currentVehicle.steer = nextSteer;
        currentVehicle.brake = nextBrake;
    }
示例#21
0
 public Car() : base(null, 0)
 {
     Sounds           = new CarSounds();
     Specs            = new CarPhysics();
     Specs.IsMotorCar = true;
 }
示例#22
0
 void Start()
 {
     carScript = GetComponent <CarPhysics>();
 }
示例#23
0
 private void Start()
 {
     _Physics       = GetComponent <CarPhysics>();
     _KANSAIDORIFTO = GetComponent <KANSAIDORIFTO>();
 }
示例#24
0
 private void Buildings_onCarParked(CarPhysics car, BuildingController.BuildingType buildingType)
 {
     onCarEnteredBuilding?.Invoke(car, buildingType);
 }
示例#25
0
        // Rest of car variables is automatically calculated below!
        #endregion

        #region Render
        /// <summary>
        /// Render
        /// </summary>
        /// <returns>Bool</returns>
        public bool Render()
        {
            if (BaseGame.AllowShadowMapping)
            {
                // Let camera point directly at the center, around 10 units away.
                BaseGame.ViewMatrix = Matrix.CreateLookAt(
                    new Vector3(0, 10.45f, 2.75f),
                    new Vector3(0, 0, -1),
                    new Vector3(0, 0, 1));

                // Let the light come from the front!
                Vector3 lightDir = -LensFlare.DefaultLightPos;
                lightDir = new Vector3(lightDir.X, lightDir.Y, -lightDir.Z);
                // LightDirection will normalize
                BaseGame.LightDirection = lightDir;

                // Show 3d cars
                // Rotate all 3 cars depending on the current selection
                float perCarRot = MathHelper.Pi * 2.0f / 3.0f;
                float newCarSelectionRotationZ =
                    RacingGameManager.currentCarNumber * perCarRot;
                carSelectionRotationZ = InterpolateRotation(
                    carSelectionRotationZ, newCarSelectionRotationZ,
                    BaseGame.MoveFactorPerSecond * 5.0f);
                // Prebuild all render matrices, we will use them for several times
                // here.
                Matrix[] renderMatrices = new Matrix[3];
                for (int carNum = 0; carNum < 3; carNum++)
                {
                    renderMatrices[carNum] =
                        Matrix.CreateRotationZ(BaseGame.TotalTime / 3.9f) *
                        Matrix.CreateTranslation(new Vector3(0, 5.0f, 0)) *
                        Matrix.CreateRotationZ(-carSelectionRotationZ + carNum * perCarRot) *
                        Matrix.CreateTranslation(new Vector3(1.5f, 0.0f, 1.0f));
                }
                // Last translation translates the position of the cars in the UI;

                // For shadows make sure the car position is the origin
                RacingGameManager.Player.SetCarPosition(Vector3.Zero,
                                                        new Vector3(0, 1, 0), new Vector3(0, 0, 1));

                // Generate shadows
                ShaderEffect.shadowMapping.GenerateShadows(
                    delegate
                {
                    for (int carNum = 0; carNum < 3; carNum++)
                    {
                        // Only the car throws shadows
                        RacingGameManager.CarModel.GenerateShadow(
                            renderMatrices[carNum]);
                    }
                });

                // Render shadows
                ShaderEffect.shadowMapping.RenderShadows(
                    delegate
                {
                    for (int carNum = 0; carNum < 3; carNum++)
                    {
                        // Both the car and the selection plate receive shadows
                        RacingGameManager.CarSelectionPlate.UseShadow(
                            renderMatrices[carNum]);
                        RacingGameManager.CarModel.UseShadow(renderMatrices[carNum]);
                    }
                });
            }

            // This starts both menu and in game post screen shader!
            // It will render into the sceneMap texture which we will use
            // later then.
            BaseGame.UI.PostScreenMenuShader.Start();

            // Render background and black bar
            BaseGame.UI.RenderMenuBackground();
            BaseGame.UI.RenderBlackBar(170, 390);

            // Immediately paint here, else post screen UI will
            // be drawn over!
            Texture.additiveSprite.End();
            Texture.alphaSprite.End();
            //SpriteHelper.DrawAllSprites();

            // Restart the sprites after the paint
            Texture.additiveSprite.Begin(SpriteBlendMode.Additive);
            Texture.alphaSprite.Begin(SpriteBlendMode.AlphaBlend);

            // Cars header
            int posX = 10;
            int posY = 18;

            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                posX += 36;
                posY += 26;
            }

            BaseGame.UI.Headers.RenderOnScreenRelative1600(
                posX, posY, UIRenderer.HeaderChooseCarGfxRect);

            // Allow selecting the car color
            TextureFont.WriteText(BaseGame.XToRes(85), BaseGame.YToRes(512),
                                  "Car Color: ");
            for (int num = 0; num < RacingGameManager.CarColors.Count; num++)
            {
                Rectangle rect =
                    RacingGameManager.currentCarColor == num?
                    BaseGame.CalcRectangle(250 + num * 50 - 6, 500 - 6, 46 + 12, 46 + 12) :
                        BaseGame.CalcRectangle(250 + num * 50, 500, 46, 46);

                RacingGameManager.colorSelectionTexture.RenderOnScreen(
                    rect, RacingGameManager.colorSelectionTexture.GfxRectangle,
                    RacingGameManager.CarColors[num]);

                if (Input.MouseInBox(rect) &&
                    Input.MouseLeftButtonPressed)
                {
                    if (RacingGameManager.currentCarColor != num)
                    {
                        Sound.Play(Sound.Sounds.Highlight);
                    }
                    RacingGameManager.currentCarColor = num;
                }
            }

            // Show car maxSpeed, Acceleration and Mass values.
            // Also show braking, friction and engine values based on that.
            CarPhysics.SetCarVariablesForCarType(
                CarTypeMaxSpeed[RacingGameManager.currentCarNumber],
                CarTypeMass[RacingGameManager.currentCarNumber],
                CarTypeMaxAcceleration[RacingGameManager.currentCarNumber]);

            // Show info and helper texts
            //TextureFont.WriteText(30, BaseGame.YToRes(280),
            //    "Car: Left/Right");
            //TextureFont.WriteText(30, BaseGame.YToRes(370),
            //    "Color: Up/Down");

            // Calculate values
            float maxSpeed =
                -1.5f + 2.45f *
                (CarTypeMaxSpeed[RacingGameManager.currentCarNumber] /
                 CarPhysics.DefaultMaxSpeed);
            float acceleration =
                -1.25f + 1.85f *
                (CarTypeMaxAcceleration[RacingGameManager.currentCarNumber] /
                 CarPhysics.DefaultMaxAccelerationPerSec);
            float mass =
                -0.65f + 1.5f *
                (CarTypeMass[RacingGameManager.currentCarNumber] /
                 CarPhysics.DefaultCarMass);
            float braking =
                -0.2f + acceleration - mass + maxSpeed;
            float friction =
                -1 + (1 / mass + maxSpeed / 5);
            float engine =
                -0.2f + 0.5f * (maxSpeed / mass + acceleration - maxSpeed * 5 + 5);

            if (engine > 0.95f)
            {
                engine = 0.95f;
            }

            ShowCarPropertyBar(
                BaseGame.XToRes(1024 - 258), BaseGame.YToRes(190),
                "Max Speed: " +
                (int)(CarTypeMaxSpeed[RacingGameManager.currentCarNumber] /
                      CarPhysics.MphToMeterPerSec) + "mph",
                maxSpeed);
            ShowCarPropertyBar(
                BaseGame.XToRes(1024 - 258), BaseGame.YToRes(235),
                "Acceleration:", acceleration);
            ShowCarPropertyBar(
                BaseGame.XToRes(1024 - 258), BaseGame.YToRes(280),
                "Car Mass:",
                mass);
            ShowCarPropertyBar(
                BaseGame.XToRes(1024 - 258), BaseGame.YToRes(335),
                "Braking:", braking);
            ShowCarPropertyBar(
                BaseGame.XToRes(1024 - 258), BaseGame.YToRes(390),
                "Friction:", friction);
            ShowCarPropertyBar(
                BaseGame.XToRes(1024 - 258), BaseGame.YToRes(445),
                "Engine:", engine);

            // Also show bouncing arrow on top of car
            float arrowWave =
                (float)Math.Sin(BaseGame.TotalTime / 0.46f) *
                (float)Math.Cos(BaseGame.TotalTime / 0.285f);
            float     arrowScale = 0.75f - 0.065f * arrowWave;
            Rectangle arrowRect  = BaseGame.CalcRectangle(512, 120,
                                                          (int)Math.Round(UIRenderer.BigArrowGfxRect.Width * arrowScale),
                                                          (int)Math.Round(UIRenderer.BigArrowGfxRect.Width * arrowScale));

            arrowRect.X -= arrowRect.Width / 2;
            // Not displayed anymore ..

            // Show left/right arrows
            Rectangle selArrowGfxRect = UIRenderer.SelectionArrowGfxRect;
            Rectangle leftRect        = BaseGame.CalcRectangle(35, 250,
                                                               selArrowGfxRect.Width, selArrowGfxRect.Height);

            leftRect.Y  = BaseGame.YToRes(300 + 60) + arrowRect.Y / 3;
            leftRect.X += (int)Math.Round(BaseGame.XToRes(12) * arrowWave);
            BaseGame.UI.Buttons.RenderOnScreen(
                leftRect, new Rectangle(selArrowGfxRect.X + selArrowGfxRect.Width,
                                        selArrowGfxRect.Y, -selArrowGfxRect.Width, selArrowGfxRect.Height));

            Rectangle rightRect = BaseGame.CalcRectangle(
                1024 - 335 - selArrowGfxRect.Width, 250,
                selArrowGfxRect.Width, selArrowGfxRect.Height);

            rightRect.Y  = BaseGame.YToRes(300 + 60) + arrowRect.Y / 3;
            rightRect.X -= (int)Math.Round(BaseGame.XToRes(12) * arrowWave);
            BaseGame.UI.Buttons.RenderOnScreen(
                rightRect, UIRenderer.SelectionArrowGfxRect);

            // Also handle xbox controller input
            if (Input.GamePadLeftJustPressed ||
                Input.KeyboardLeftJustPressed ||
                Input.MouseLeftButtonJustPressed &&
                Input.MouseInBoxRelative(new Rectangle(512 + 50, 170, 512 - 150, 135)))
            {
                Sound.Play(Sound.Sounds.Highlight);
                RacingGameManager.currentCarNumber =
                    (RacingGameManager.currentCarNumber + 1) % 3;
            }
            else if (Input.GamePadRightJustPressed ||
                     Input.KeyboardRightJustPressed ||
                     Input.MouseLeftButtonJustPressed &&
                     Input.MouseInBoxRelative(new Rectangle(100, 170, 512 - 200, 135)))
            {
                Sound.Play(Sound.Sounds.Highlight);
                RacingGameManager.currentCarNumber =
                    (RacingGameManager.currentCarNumber + 2) % 3;
            }

            // Mouse input is handled in RacingGameManager.cs
            if (Input.GamePadUpJustPressed ||
                Input.KeyboardUpJustPressed)
            {
                Sound.Play(Sound.Sounds.Highlight);
                RacingGameManager.currentCarColor = (RacingGameManager.currentCarColor +
                                                     RacingGameManager.NumberOfCarColors - 1) %
                                                    RacingGameManager.NumberOfCarColors;
            }
            else if (Input.GamePadDownJustPressed ||
                     Input.KeyboardDownJustPressed)
            {
                Sound.Play(Sound.Sounds.Highlight);
                RacingGameManager.currentCarColor =
                    (RacingGameManager.currentCarColor + 1) %
                    RacingGameManager.NumberOfCarColors;
            }

            bool aButtonPressed = BaseGame.UI.RenderBottomButtons(false);

            if (Input.GamePadAJustPressed ||
                Input.KeyboardSpaceJustPressed ||
                aButtonPressed)
            {
                RacingGameManager.AddGameScreen(new TrackSelection());
                return(false);
            }

            if (Input.KeyboardEscapeJustPressed ||
                Input.GamePadBJustPressed ||
                Input.GamePadBackJustPressed ||
                BaseGame.UI.backButtonPressed)
            {
                return(true);
            }

            return(false);
        }
示例#26
0
 private void Start()
 {
     _Physics = GetComponent <CarPhysics>();
     _HitMesh = new Mesh();
 }
示例#27
0
 internal Car(Train baseTrain)
 {
     this.baseTrain = baseTrain;
     this.Specs     = new CarPhysics();
 }
示例#28
0
        /// <summary>
        /// Add brake track
        /// </summary>
        /// <param name="position">Position</param>
        /// <param name="dir">Dir vector</param>
        /// <param name="right">Right vector</param>
        public void AddBrakeTrack(CarPhysics car)
        {
            Vector3 position = car.CarPosition + car.CarDirection * 1.25f;

            // Just skip if we setting to a similar location again.
            // This check is much faster and accurate for tracks on top of each
            // other than the foreach loop below, which is only useful to
            // put multiple tracks correctly behind each other!
            if (Vector3.DistanceSquared(position, lastAddedTrackPos) < 0.024f ||
                // Limit number of tracks to keep rendering fast.
                brakeTracksVertices.Count > MaxBrakeTrackVertices)
            {
                return;
            }

            lastAddedTrackPos = position;

            const float width   = 2.4f; // car is 2.6m width, we use 2.4m for tires
            const float length  = 4.5f; // Length of break tracks
            float       maxDist =
                (float)Math.Sqrt(width * width + length * length) / 2 - 0.35f;

            // Check if there is any track already set here or nearby?
            for (int num = 0; num < brakeTracksVertices.Count; num++)
            {
                if (Vector3.DistanceSquared(brakeTracksVertices[num].pos, position) <
                    maxDist * maxDist)
                {
                    // Then skip this brake track, don't put that much stuff on
                    // top of each other.
                    return;
                }
            }

            // Move position a little bit up (above the road)
            position += Vector3.Normalize(car.CarUpVector) * RaiseBreakTracksAmount;

            // Just add 6 new vertices to render (2 triangles)
            TangentVertex[] newVertices = new TangentVertex[]
            {
                // First triangle
                new TangentVertex(
                    position - car.CarRight * width / 2 - car.CarDirection * length / 2, 0, 0,
                    car.CarUpVector, car.CarRight),
                new TangentVertex(
                    position - car.CarRight * width / 2 + car.CarDirection * length / 2, 0, 5,
                    car.CarUpVector, car.CarRight),
                new TangentVertex(
                    position + car.CarRight * width / 2 + car.CarDirection * length / 2, 1, 5,
                    car.CarUpVector, car.CarRight),
                // Second triangle
                new TangentVertex(
                    position - car.CarRight * width / 2 - car.CarDirection * length / 2, 0, 0,
                    car.CarUpVector, car.CarRight),
                new TangentVertex(
                    position + car.CarRight * width / 2 + car.CarDirection * length / 2, 1, 5,
                    car.CarUpVector, car.CarRight),
                new TangentVertex(
                    position + car.CarRight * width / 2 - car.CarDirection * length / 2, 1, 0,
                    car.CarUpVector, car.CarRight),
            };

            brakeTracksVertices.AddRange(newVertices);
            brakeTracksVerticesArray = brakeTracksVertices.ToArray();
        }
示例#29
0
 // Use this for initialization
 void Start()
 {
     _Physics        = GetComponentInParent <CarPhysics>();
     _LogicTransform = GetComponentInParent <Transform>();
 }
示例#30
0
        private CarPhysics car; // the car controller we want to use

        private void Awake()
        {
            // get the car controller
            car = GetComponent <CarPhysics>();
        }