예제 #1
0
        public static CubeCoordinates GetTargetedCube(this CubeWorld cubeWorld, Camera camera, int maxLayingDistance) // is not 100% trustworthy, and is not powerful, be careful
        {
            Vector3 checkPosition = camera.ScreenPosition * cubeWorld.GetGraphicsCubeRatio();                         // Not a beautiful way!

            CubeCoordinates actualPosition = null;
            CubeCoordinates convertedCheckPosition;

            const int checkIntensity = 100;
            float     checkIncrement = (float)maxLayingDistance / checkIntensity;

            for (int i = 0; i < checkIntensity; i++)
            {                                                           // in World, is free space
                checkPosition         += camera.Front * checkIncrement; // increment check zone
                convertedCheckPosition = CubeCoordinates.FromVector3(checkPosition);

                if (convertedCheckPosition == actualPosition)
                {
                    if (!cubeWorld.IsFreeSpace(convertedCheckPosition))                     // check if it's a free space
                    {
                        return(convertedCheckPosition);
                    }
                }

                actualPosition = convertedCheckPosition;
            }

            return(actualPosition);
        }
예제 #2
0
        public static CubeCoordinates GetTargetedNewCube(this CubeWorld cubeWorld, Camera camera, int maxLayingDistance)         // is not 100% trustworthy, and is not powerful, be careful
        {
            Vector3 checkPosition = camera.ScreenPosition * cubeWorld.GetGraphicsCubeRatio();

            CubeCoordinates oldPosition    = null;
            CubeCoordinates actualPosition = null;
            CubeCoordinates convertedCheckPosition;

            const int checkIntensity = 100;
            float     checkIncrement = (float)maxLayingDistance / checkIntensity;

            for (int i = 0; i < checkIntensity; i++)
            {                                                           // in World, is free space
                checkPosition         += camera.Front * checkIncrement; // increment check zone
                convertedCheckPosition = CubeCoordinates.FromVector3(checkPosition);

                if (convertedCheckPosition == actualPosition)                                     // perf maintainer
                {
                    if (!(oldPosition is null) && !cubeWorld.IsFreeSpace(convertedCheckPosition)) // check if it's a free space
                    {
                        return(oldPosition);
                    }
                    else if (!(actualPosition is null))                     // or accept the new checkable position (or exit if actualPosition wasn't initialized)
                    {
                        oldPosition = actualPosition;
                    }
                }

                actualPosition = convertedCheckPosition;
            }
예제 #3
0
        protected override void Initialize()
        {
            SpriteBatch = new SpriteBatch(GraphicsDevice);

            SetState(NocubelessState.Playing);             // starting state
            CubeWorld = new CubeWorld(Settings.CubeWorld, /*new ShallowCubeWorldHandler()*/ new CubeWorldSaveHandler("save.nclws"));
            Player    = new Player(PlayerSettings.Default, WorldCoordinates.Zero);

            #region Graphics Config
            var blendState      = BlendState.AlphaBlend;
            var rasterizerState = new RasterizerState
            {
                CullMode = CullMode.None
            };

            GraphicsDevice.BlendState      = blendState;
            GraphicsDevice.RasterizerState = rasterizerState;
            #endregion

            #region Components Linking
            Components.Add(new ColorPickerMenu(this));
            Components.Add(new NocubelessInputProcessorSelector(this));
            Components.Add(new DynamicEntitiesComponent(this));
            Components.Add(new CubeWorldProcessor(this));
            Components.Add(new InfoDisplayer(this));
            #endregion

            Input.MiddlePoint = new Point(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);             // DESIGN

            base.Initialize();
        }
예제 #4
0
        public void SetState(NocubelessState state, NocubelessState?fromState = null)
        {
            CurrentState = state;

            switch (state)
            {
            case NocubelessState.Playing:
            {
                Camera = new PlayingCamera(Settings.Camera, GraphicsDevice.Viewport);
                Input.SetMouseInTheMiddle();                                 // important! Do not ignore

                clearColor = new Color(149, 165, 166);

                if (Settings.Song.MusicEnabled)
                {
                    MediaPlayer.Play(Content.Load <Song>("Music/playing_theme"));                                                            // I'm nice, I am making only one line for fun by waiting Content Design Update
                }
            }
            break;

            case NocubelessState.Editing:
            {
                if (fromState != NocubelessState.ColorPicking)
                {
                    CubeWorld.PreviewableCube.Coordinates =
                        CubeWorld.GetCoordinatesFromGraphics(Camera.ScreenPosition);

                    Camera = new EditingCamera(Settings.Camera, GraphicsDevice.Viewport, Settings.EditingMode.WorldRotationDistance);

                    clearColor = Color.CadetBlue;

                    if (Settings.Song.MusicEnabled)
                    {
                        MediaPlayer.Play(Content.Load <Song>("Music/editing_theme"));                                                                // I'm nice, I am making only one line for fun by waiting Content Design Update
                    }
                }
            }
            break;
            }
        }