public SceneLevelSelect(Game game) : base(game)
        {
            dim   = GameInstance.ScreenInfo;
            root  = GameInstance.UI.Root;
            cache = GameInstance.ResourceCache;
            font  = cache.GetFont("Fonts/OpenSans-Bold.ttf");

            _racesNumber = TrackManager.Instance.TrackCount;
            if (CharacterManager.Instance.User.LastCompletedRace > 0)
            {
                lastComplededRace = CharacterManager.Instance.User.LastCompletedRace;
            }
            else
            {
                lastComplededRace = 0;
            }

            if (TrackManager.Instance.Tracks.TrackModel.Count > 1)
            {
                _counter = lastComplededRace + 1;
                TrackManager.Instance.SelectedTrackId = _counter;
                TrackManager.Instance.LoadSingleLevel(TrackManager.Instance.SelectedTrackId);
            }

            CreateUI();
        }
示例#2
0
        public static List <Point> ArrayToMatrix(List <float> srsNormalizedData, ScreenInfoRatio screenInfo, bool addEndingPoints = true)
        {
            List <Point> points = new List <Point>();
            uint         idx    = 0;

            foreach (var point in srsNormalizedData)
            {
                // Terrain point = collision chain index
                // + terrain X coord progressive value (same distance each step)
                // + terrain Y coord from srs data
                points.Add(new Point(idx, TerrainStepLength * idx + TerrainBeginningOffset * screenInfo.XScreenRatio, point * screenInfo.YScreenRatio));
                idx++;
            }

            if (addEndingPoints)
            {
                var lastPoint = points.Last();
                for (var i = 0; i < EndOfLevelSurfaceLength; i++)
                {
                    points.Add(new Point(idx, TerrainStepLength * idx + TerrainBeginningOffset * screenInfo.XScreenRatio, lastPoint.Vector.Y * screenInfo.YScreenRatio));
                    idx++;
                }
            }

            return(points);
        }
示例#3
0
        public static Text CreateText(UIElement parent, ScreenInfoRatio screenInfo, Font font, int fontSize, int xPos, int yPos, HorizontalAlignment hAlign, VerticalAlignment vAlign, string value)
        {
            var text = CreateText(parent, screenInfo, font, fontSize, xPos, yPos, hAlign, vAlign);

            text.Value = value;

            return(text);
        }
 public SceneUserProfile(Game game) : base(game)
 {
     dim   = GameInstance.ScreenInfo;
     root  = GameInstance.UI.Root;
     cache = GameInstance.ResourceCache;
     font  = cache.GetFont(GameInstance.defaultFont);
     ui    = GameInstance.UI;
     JsonReaderCharacter.GetCharacterConfig();
     counter = Plugin.Settings.CrossSettings.Current.GetValueOrDefault("img_character_id", 0);
     CreateUI();
 }
示例#5
0
        public static Text CreateText(UIElement parent, ScreenInfoRatio screenInfo, Font font, int fontSize, int xPos, int yPos, HorizontalAlignment hAlign, VerticalAlignment vAlign)
        {
            var text = new Text();

            parent.AddChild(text);

            text.SetAlignment(hAlign, vAlign);
            text.SetPosition(screenInfo.SetX(xPos), screenInfo.SetY(yPos));
            text.SetFont(font, screenInfo.SetX(fontSize));
            text.SetColor(Color.Black);

            return(text);
        }
        public SceneProfileImage(Game game, bool IsUserProfile = false) : base(game)
        {
            dim            = GameInstance.ScreenInfo;
            root           = GameInstance.UI.Root;
            cache          = GameInstance.ResourceCache;
            font           = cache.GetFont("Fonts/OpenSans-Bold.ttf");
            ui             = GameInstance.UI;
            _isUserProfile = IsUserProfile;
            JsonReaderCharacter.GetCharacterConfig();
            counter   = CharacterManager.Instance.User != null ? CharacterManager.Instance.User.PortraitId : 0;
            _nameText = CharacterManager.Instance.User?.Username;

            CreateUI();
        }
示例#7
0
        public static Button CreateButton(UIElement parent, ScreenInfoRatio screenInfo, int posX, int posY, int width, int height, HorizontalAlignment hAlign, VerticalAlignment vAlign)
        {
            Button button = new Button();

            parent.AddChild(button);

            button.SetStyleAuto(null);
            button.SetPosition(screenInfo.SetX(posX), screenInfo.SetY(posY));
            button.SetAlignment(hAlign, vAlign);
            button.SetSize(screenInfo.SetX(width), screenInfo.SetY(height));
            button.SetColor(Color.White);

            return(button);
        }
示例#8
0
        public void InitUiInfo()
        {
            //Options.AdditionalFlags = " -hd";

            Input.Enabled  = true;
            Input.KeyDown += HandleKeyDown;

            ScreenInfo = new ScreenInfoRatio(Graphics.Width, Graphics.Height);

            XmlFile uiStyle = ResourceCache.GetXmlFile("UI/DefaultStyle.xml");

            UI.Root.SetDefaultStyle(uiStyle);

            //Engine.MaxFps = 30;
        }
示例#9
0
        ScreenInfoRatio dim; //variabile rapporto dimensioni schermo

        public SceneMenu(Game game) : base(game)
        {
            dim = GameInstance.ScreenInfo;
            if (CharacterManager.Instance.User == null)
            {
                GameInstance.LaunchScene(GameScenesEnumeration.PROFILE);
            }
            else if (VehicleManager.Instance.SelectedVehicleModel == null || VehicleManager.Instance.SelectedVehicleModel.IdVehicle == -1)
            {
                GameInstance.LaunchScene(GameScenesEnumeration.GARAGE);
            }
            else
            {
                CreateUI();
            }
        }
示例#10
0
        public ScenePostRace(Game game, bool randomLevel = false) : base(game)
        {
            dim        = GameInstance.ScreenInfo;
            root       = GameInstance.UI.Root;
            cache      = GameInstance.ResourceCache;
            font       = cache.GetFont(GameInstance.defaultFont);
            _levelInfo = TrackManager.Instance.SelectedTrackModel ?? null;

            // Update best time data if not random level
            if (!randomLevel)
            {
                UpdateLevelInfo();
            }

            CreateBackground();
            CreateTopBar();
            CreateScene();
        }
示例#11
0
        void InitTouchInput()
        {
            graphics        = Graphics;
            screenInfoRatio = new ScreenInfoRatio(graphics.Width, graphics.Height);

            TouchEnabled = true;
            var layout = ResourceCache.GetXmlFile("UI/ScreenJoystick_Samples.xml");

            JoystickLayoutPatch = JoystickLayoutPatches.MainGameUI;
            if (!string.IsNullOrEmpty(JoystickLayoutPatch))
            {
                XmlFile patchXmlFile = new XmlFile();
                patchXmlFile.FromString(JoystickLayoutPatch);
                layout.Patch(patchXmlFile);
            }
            var screenJoystickIndex = Input.AddScreenJoystick(layout /*, ResourceCache.GetXmlFile("UI/DefaultStyle.xml")*/);

            Input.SetScreenJoystickVisible(screenJoystickIndex, true);
        }
示例#12
0
        public SceneGarage(Game game) : base(game)
        {
            _idDVehicle = VehicleManager.Instance.SelectedVehicleModel != null ? VehicleManager.Instance.SelectedVehicleModel.IdVehicle : -1;
            if (_idDVehicle < 0)
            {
                _idDVehicle = 0;
            }

            _dim   = GameInstance.ScreenInfo;
            _root  = GameInstance.UI.Root;
            _cache = GameInstance.ResourceCache;
            _font  = _cache.GetFont("Fonts/OpenSans-Bold.ttf");
            JsonReaderVehicles.GetVehicleConfig();

            _currentVehicleModel      = VehicleManager.Instance.SelectedVehicleModel;
            _lastSelectedVehicleModel = _currentVehicleModel;

            CreateUI();
        }
示例#13
0
        public VehicleCreator(Scene scene, Urho.Resources.ResourceCache cache, ScreenInfoRatio screenInfo, Vector2 initPositionHeight)
        {
            _screenInfo             = screenInfo;
            _vehicleVerticalOffset += initPositionHeight.Y;

            // Load vehicle info
            _vehicleModel = VehicleManager.Instance.SelectedVehicleModel;

            var l = _vehicleModel.BodyPosition.Left;
            var t = _vehicleModel.BodyPosition.Top;
            var r = _vehicleModel.BodyPosition.Right;
            var b = _vehicleModel.BodyPosition.Bottom;

            // Get vehicle texture from coordinates
            var sprite = new Sprite2D {
                Texture   = cache.GetTexture2D("Textures/Garage/vehicles_body.png"),
                Rectangle = new IntRect(l, t, r, b)
            };

            // Create vehicle main body reference
            Node box = scene.CreateChild("Box");

            StaticSprite2D boxSprite = box.CreateComponent <StaticSprite2D>();

            boxSprite.Sprite = sprite;

            _mainBody                = box.CreateComponent <RigidBody2D>();
            _mainBody.BodyType       = BodyType2D.Dynamic;
            _mainBody.LinearDamping  = 0.2f;
            _mainBody.AngularDamping = 0.2f;
            _mainBody.Bullet         = true;
            _mainBody.Mass           = 1.0f;
            //_mainBody.SetMassCenter(new Vector2(-2.1f * _screenInfo.XScreenRatio, -0.1f * _screenInfo.YScreenRatio));

            /****************************************/
            /* Outer body for collision - null mass */
            /****************************************/
            float startVX       = -1.2f + _vehicleModel.BalanceBodyOffset[0];
            float startVY       = -0.55f + _vehicleModel.BalanceBodyOffset[1];
            float driverXOffset = 1.0f + _vehicleModel.BalanceBodyOffset[2];

            VehicleObjectPosition = new Vector3(-0.7f * _screenInfo.XScreenRatio, _vehicleVerticalOffset + _vehicleModel.BalanceBodyOffset[1], 3.0f);
            // MAIN BODY BOUNDS
            CollisionChain2D bodyBounds = box.CreateComponent <CollisionChain2D>();

            bodyBounds.VertexCount = 9;
            bodyBounds.SetVertex(0, new Vector2(startVX, startVY)); // BOTTOM LEFT
            bodyBounds.SetVertex(1, new Vector2(startVX, startVY + 0.1f));
            bodyBounds.SetVertex(2, new Vector2(startVX + driverXOffset, startVY + 0.1f));
            bodyBounds.SetVertex(3, new Vector2(startVX + driverXOffset, startVY + 0.2f));
            bodyBounds.SetVertex(4, new Vector2(startVX + driverXOffset + 0.3f, startVY + 0.2f));
            bodyBounds.SetVertex(5, new Vector2(startVX + driverXOffset + 0.3f, startVY + 0.1f));
            bodyBounds.SetVertex(6, new Vector2(startVX + driverXOffset + 0.8f, startVY + 0.1f));
            bodyBounds.SetVertex(7, new Vector2(startVX + driverXOffset + 0.8f, startVY)); // BOTTOM RIGHT
            bodyBounds.SetVertex(8, new Vector2(startVX, startVY));                        // BOTTOM LEFT
            bodyBounds.Friction    = 1.0f;
            bodyBounds.Restitution = 0.0f;

            // BACK BODY BOUND
            CollisionChain2D backBounds = box.CreateComponent <CollisionChain2D>();

            backBounds.VertexCount = 4;
            backBounds.SetVertex(0, new Vector2(startVX, startVY + 0.1f));
            backBounds.SetVertex(1, new Vector2(startVX, startVY + 0.15f));
            backBounds.SetVertex(2, new Vector2(startVX + 0.02f, startVY + 0.15f));
            backBounds.SetVertex(3, new Vector2(startVX + 0.02f, startVY + 0.1f));
            backBounds.SetVertex(4, new Vector2(startVX, startVY + 0.1f));

            backBounds.Friction    = 1.0f;
            backBounds.Restitution = 0.0f;

            // Main body for constraints and mass
            // Create box shape
            CollisionBox2D shape = box.CreateComponent <CollisionBox2D>();

            // Set size
            shape.Size        = new Vector2(0.32f, 0.32f);
            shape.Density     = 8.0f;  // Set shape density (kilograms per meter squared)
            shape.Friction    = 0.8f;  // Set friction
            shape.Restitution = 0.0f;  // Set restitution (no bounce)

            // Update center of collision body - moves center of mass
            shape.SetCenter(-0.2f, -0.65f);

            // Create a vehicle from a compound of 2 ConstraintWheel2Ds
            var car = box;

            //car.Scale = new Vector3(1.5f * _screenInfo.XScreenRatio, 1.5f * _screenInfo.YScreenRatio, 0.0f);

            // DEFINES POSITION OF SPRITE AND MAIN BODY MASS
            car.Position = new Vector3(0.0f * _screenInfo.XScreenRatio, _vehicleVerticalOffset * _screenInfo.YScreenRatio, 1.0f);

            /*****************/
            /* DEFINE WHEELS */
            /*****************/

            var wheelSprites = new List <Sprite2D>();

            foreach (var w in _vehicleModel.WheelsPosition)
            {
                wheelSprites.Add(new Sprite2D {
                    Texture   = cache.GetTexture2D("Textures/Garage/vehicles_wheels.png"),
                    Rectangle = new IntRect(w.Left, w.Top, w.Right, w.Bottom)
                });
            }
            // Create a ball (will be cloned later)
            Node           ball1WheelNode = scene.CreateChild("Wheel");
            StaticSprite2D ballSprite     = ball1WheelNode.CreateComponent <StaticSprite2D>();

            ballSprite.Sprite    = wheelSprites[0];
            ball1WheelNode.Scale = new Vector3(_vehicleModel.WheelsSize[0], _vehicleModel.WheelsSize[0], 1.0f);

            RigidBody2D ballBody = ball1WheelNode.CreateComponent <RigidBody2D>();

            ballBody.BodyType       = BodyType2D.Dynamic;
            ballBody.LinearDamping  = 0.1f;
            ballBody.AngularDamping = 0.1f;
            ballBody.Bullet         = true;
            ballBody.Mass           = 2.0f;

            // WHEEL COLLISION
            CollisionCircle2D ballShape = ball1WheelNode.CreateComponent <CollisionCircle2D>(); // Create circle shape

            ballShape.Radius      = 0.14f;                                                      // * _vehicleModel.WheelsSize[0]; // Set radius
            ballShape.Density     = 2.0f;                                                       // Set shape density (kilograms per meter squared)
            ballShape.Friction    = (_vehicleModel.Wheel / 2) / 10.0f;                          // Set friction: 1.0 = max friction
            ballShape.Restitution = (20 - _vehicleModel.Suspensions) / 2 / 10.0f;               // Set restitution: make it bounce: 0.0 = no bounce

            // CLONE AND POSITION WHEELS

            for (var i = 0; i < _vehicleModel.WheelsBodyPosition.Count; i++)
            {
                if (i == 0)
                {
                    float x1 = _vehicleModel.WheelsBodyPosition[i].X % _vehicleImgPos;
                    float y1 = _vehicleModel.WheelsBodyPosition[i].Y % _vehicleImgPos;
                    x1 = x1 >= _vehicleImgPos / 2 ? (x1 - _vehicleImgPos / 2) * Application.PixelSize : -(_vehicleImgPos / 2 - x1) * Application.PixelSize;
                    y1 = (_vehicleImgPos / 2 - y1) * Application.PixelSize;

                    // WHEEL POSITION - NEEDS TO BE SET RELATIVE TO MAIN BODY
                    ball1WheelNode.Position = new Vector3(x1, y1 + (_vehicleVerticalOffset - 0.05f) * _screenInfo.YScreenRatio, 1.0f);

                    // SET BACK WHEEL CONSTRAINT COMPONENTS
                    var constraintWheel = car.CreateComponent <ConstraintWheel2D>();
                    constraintWheel.OtherBody      = ball1WheelNode.GetComponent <RigidBody2D>();
                    constraintWheel.Anchor         = ball1WheelNode.Position2D;
                    constraintWheel.Axis           = new Vector2(0.0f, 1.0f);
                    constraintWheel.MaxMotorTorque = 150.0f;
                    constraintWheel.FrequencyHz    = 15.0f;
                    constraintWheel.DampingRatio   = 10.0f;
                    constraintWheel.MotorSpeed     = 0.0f;
                    _wheelsConstraints.Add(constraintWheel);
                }
                else
                {
                    Node           newWheelNode  = ball1WheelNode.Clone(CreateMode.Replicated);
                    StaticSprite2D newBallSprite = newWheelNode.CreateComponent <StaticSprite2D>();
                    newBallSprite.Sprite = wheelSprites.Count > i ? wheelSprites[i] : wheelSprites.Last();

                    float x2 = _vehicleModel.WheelsBodyPosition[i].X % _vehicleImgPos;
                    float y2 = _vehicleModel.WheelsBodyPosition[i].Y % _vehicleImgPos;
                    x2 = x2 >= _vehicleImgPos / 2 ? (x2 - _vehicleImgPos / 2) * Application.PixelSize : -(_vehicleImgPos / 2 - x2) * Application.PixelSize;
                    y2 = (_vehicleImgPos / 2 - y2) * Application.PixelSize;

                    // Update collision shape
                    CollisionCircle2D collisionShape = newWheelNode.GetComponent <CollisionCircle2D>(); // Create circle shape
                    collisionShape.Radius = 0.14f;                                                      // * _vehicleModel.WheelsSize[i];
                    // WHEEL POSITION - NEEDS TO BE SET RELATIVE TO MAIN BODY
                    newWheelNode.Scale    = new Vector3(_vehicleModel.WheelsSize[i], _vehicleModel.WheelsSize[i], 1.0f);
                    newWheelNode.Position = new Vector3(x2, y2 + (_vehicleVerticalOffset - 0.05f) * _screenInfo.YScreenRatio, 1.0f);

                    // SET FRONT WHEEL CONSTRAINT COMPONENTS
                    var constraintWheel = car.CreateComponent <ConstraintWheel2D>();
                    constraintWheel.OtherBody      = newWheelNode.GetComponent <RigidBody2D>();
                    constraintWheel.Anchor         = newWheelNode.Position2D;
                    constraintWheel.Axis           = new Vector2(0.0f, 1.0f);
                    constraintWheel.MaxMotorTorque = 150.0f;
                    constraintWheel.FrequencyHz    = 15.0f;
                    constraintWheel.DampingRatio   = 10.0f;
                    constraintWheel.MotorSpeed     = 0.0f;
                    _wheelsConstraints.Add(constraintWheel);
                }
            }
        }
示例#14
0
        public static Node CreateBalanceObject(Game GameInstance, BaseScene scene, string objectName, ScreenInfoRatio _screenInfo, Vector3 verticalOffset)
        {
            Node node = scene.CreateChild(objectName);

            node.Position = verticalOffset;
            node.Scale    = new Vector3(0.8f, 0.8f, 0.8f);

            // Create rigid body
            RigidBody2D body = node.CreateComponent <RigidBody2D>();

            body.BodyType = BodyType2D.Dynamic;

            // TODO: select proper balance object
            Sprite2D boxSprite = GameInstance.ResourceCache.GetSprite2D(AssetsCoordinates.Level.BalanceObjects.ResourcePath);

            boxSprite.Rectangle = AssetsCoordinates.Level.BalanceObjects.JukeBox;
            //Sprite2D boxSprite = GameInstance.ResourceCache.GetSprite2D("Urho2D/Box.png");
            StaticSprite2D staticSprite = node.CreateComponent <StaticSprite2D>();

            staticSprite.Sprite = boxSprite;

            // Create box
            CollisionBox2D box = node.CreateComponent <CollisionBox2D>();

            // Set size
            box.Size = new Vector2(0.25f, 0.25f);
            // Set density
            box.Density = 0.6f;
            // Set friction
            box.Friction = 1.0f;
            // Set restitution
            box.Restitution = 0.1f;

            return(node);
        }