Ejemplo n.º 1
0
        public void RecieveInput(InputType input, InputState state, Point mousePos, int scrollDelta)
        {
            if (input == InputType.Select)
            {
                Vector2 click = ScreenToWorld(mousePos.ToVector2());
                DebugRenderer.AddText(String.Format("X:{0} Y:{1}", click.X, click.Y), "Last Click Location");

                tileEntities.Add(new TestTileEntity(selector.Tile));
            }
            if (input == InputType.SecondarySelect)
            {
                tileEntities.RemoveAll((TileEntity entity) => { return(entity.Location == selector.Tile); });
            }

            int movementSpeed = 10;

            if (Keyboard.GetState().IsKeyDown(Keys.LeftShift))
            {
                movementSpeed = 100;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.LeftControl))
            {
                movementSpeed = 1;
            }

            switch (input)
            {
            case InputType.CameraUp:
                camera.Location += new Vector2(0, movementSpeed);
                break;

            case InputType.CameraDown:
                camera.Location += new Vector2(0, -movementSpeed);
                break;

            case InputType.CameraLeft:
                camera.Location += new Vector2(-movementSpeed, 0);
                break;

            case InputType.CameraRight:
                camera.Location += new Vector2(movementSpeed, 0);
                break;

            case InputType.CameraZoom:
                if (scrollDelta > 0 && camera.Zoom < 16)
                {
                    camera.Zoom *= 2;
                }
                if (scrollDelta < 0 && camera.Zoom > 0.0625f)
                {
                    camera.Zoom /= 2;
                }
                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            DebugRenderer.Initialize(GraphicsDevice, Content.Load <SpriteFont>("Default"));

            camera          = new Camera();
            camera.Location = new Vector2(Chunk.SIZE * Tile.PIXEL_LENGTH * 0.5f, Chunk.SIZE * Tile.PIXEL_LENGTH * 0.5f);
            effect          = new BasicEffect(GraphicsDevice);
            effect.World   *= Matrix.CreateScale(Tile.PIXEL_LENGTH); // Scale tiles drawn at 1x1 to full pixel size
            UpdateProjection();

            IsMouseVisible            = true;
            Window.AllowUserResizing  = true;
            Window.ClientSizeChanged += Window_ClientSizeChanged;

            selector = new Selector();

            terrain = new Terrain();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            fpsCounter.Update(gameTime);
            GraphicsDevice.Clear(Color.Black);
            GraphicsDevice.SamplerStates[0] = SamplerState.PointWrap;

            effect.View = camera.View;

            terrain.Draw(GraphicsDevice, effect);

            DrawEntities();

            DebugRenderer.AddText(
                "Zoom: " + camera.Zoom.ToString() + "\nLocation: " + camera.Location.ToString() +
                "\nViewport Bounds: " + GraphicsDevice.Viewport.Bounds.ToString() + "\nWorld Bounds: " +
                GetScreenWorldBounds().ToString(), "Camera/View Parameters");

            DebugRenderer.AddText(fpsCounter.AverageFps.ToString(), "FPS");

            DebugRenderer.Draw();
            base.Draw(gameTime);
        }
Ejemplo n.º 4
0
        public void UpdateChunkGraphics(Vector4 bounds)
        {
            // Add one to top and right to remove half tile gap
            bounds.Z++;
            bounds.W++;
            bounds /= Chunk.SIZE;

            int xMin = (int)Math.Floor(bounds.X);
            int yMin = (int)Math.Floor(bounds.Y);
            int xMax = (int)Math.Ceiling(bounds.Z);
            int yMax = (int)Math.Ceiling(bounds.W);

            DebugRenderer.AddText(String.Format("X:{0} Y:{1} X:{2} Y:{3}", xMin, yMin, xMax, yMax), "CHUNKY");

            // Unload old chunk graphics that have moved beyond the unload distance
            UnloadChunkGroupGraphics(lastXMin + 1 - UNLOAD_EXTENT, xMin - UNLOAD_EXTENT, lastYMin - UNLOAD_EXTENT, lastYMax + UNLOAD_EXTENT);
            UnloadChunkGroupGraphics(xMax + UNLOAD_EXTENT, lastXMax - 1 + UNLOAD_EXTENT, lastYMin - UNLOAD_EXTENT, lastYMax + UNLOAD_EXTENT);
            UnloadChunkGroupGraphics(lastXMin - UNLOAD_EXTENT, lastXMax + UNLOAD_EXTENT, lastYMin + 1 - UNLOAD_EXTENT, yMin - UNLOAD_EXTENT);
            UnloadChunkGroupGraphics(lastXMin - UNLOAD_EXTENT, lastXMax + UNLOAD_EXTENT, yMax + UNLOAD_EXTENT, lastYMax - 1 + UNLOAD_EXTENT);

            // Generate new chunks
            GenerateChunkGroup(xMin - GENERARION_EXTENT, lastXMin - 1 - GENERARION_EXTENT, yMin - GENERARION_EXTENT, yMax + GENERARION_EXTENT);
            GenerateChunkGroup(lastXMax + 1 + GENERARION_EXTENT, xMax + GENERARION_EXTENT, yMin - GENERARION_EXTENT, yMax + GENERARION_EXTENT);
            GenerateChunkGroup(xMin - GENERARION_EXTENT, xMax + GENERARION_EXTENT, yMin - GENERARION_EXTENT, lastYMin - 1 - GENERARION_EXTENT);
            GenerateChunkGroup(xMin - GENERARION_EXTENT, xMax + GENERARION_EXTENT, lastYMax + 1 + GENERARION_EXTENT, yMax + GENERARION_EXTENT);

            // Load chunk graphics
            LoadChunkGroupGraphics(xMin - LOAD_EXTENT, lastXMin - 1 - LOAD_EXTENT, yMin - LOAD_EXTENT, yMax + LOAD_EXTENT);
            LoadChunkGroupGraphics(lastXMax + 1 + LOAD_EXTENT, xMax + LOAD_EXTENT, yMin - LOAD_EXTENT, yMax + LOAD_EXTENT);
            LoadChunkGroupGraphics(xMin - LOAD_EXTENT, xMax + LOAD_EXTENT, yMin - LOAD_EXTENT, lastYMin - 1 - LOAD_EXTENT);
            LoadChunkGroupGraphics(xMin - LOAD_EXTENT, xMax + LOAD_EXTENT, lastYMax + 1 + LOAD_EXTENT, yMax + LOAD_EXTENT);

            lastXMin = xMin;
            lastYMin = yMin;
            lastXMax = xMax;
            lastYMax = yMax;
        }