Exemple #1
0
        /* #################################################################### */
        /* #                              METHODS                             # */
        /* #################################################################### */

        public void Run()
        {
            SDLWindow.Instance.Start();
            SDLRenderer.Instance.Start();

            bool keepRunning = true;

            while (keepRunning)
            {
                Time.Update();
                SDLEvent.Update();           // This should be updated early, to make sure inputs are available to later activities.
                SDLWindow.Instance.Update(); // This needs to be called before anything that might draw anything, as it clears the backbuffer.
                MouseController.Instance.Update();
                CameraController.Instance.Update();
                WorldController.Instance.Update();

                WorldController.Instance.Render();
                MouseController.Instance.Render();
                CameraController.Instance.Render();

                SDLWindow.Instance.Present();

                if (SDLEvent.Quit || SDLEvent.KeyUp(SDL2.SDL.SDL_Keycode.SDLK_ESCAPE))
                {
                    keepRunning = false;
                }
            }
        }
Exemple #2
0
        private void UpdateCameraMovement()
        {
            // Handle screen dragging
            if (SDLEvent.MouseButtonIsDown(SDL2.SDL.SDL_BUTTON_MIDDLE))
            {
                var diff = new Vector2 <int>();
                diff.X = (int)(_lastFramePosition.X - _currentFramePosition.X);
                diff.Y = (int)(_lastFramePosition.Y - _currentFramePosition.Y);

                var pos = new Vector2 <int>();
                pos.X = CameraController.Instance.Position.X + diff.X;
                pos.Y = CameraController.Instance.Position.Y - diff.Y;

                CameraController.Instance.SetPosition(pos);

                // Zooming
                // Camera.main.orthographicSize -= Camera.main.orthographicSize * Input.GetAxis("Mouse ScrollWheel") * 2f;
                // Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize, 3f, 50f);
            }
        }
Exemple #3
0
        public void Update()
        {
            _currentFramePosition = CameraController.Instance.ScreenToWorldPoint(SDLEvent.MousePosition);

            if (SDLEvent.KeyUp(SDL.SDL_Keycode.SDLK_ESCAPE))
            {
                if (_mode == MouseMode.Build)
                {
                    _mode = MouseMode.Select;
                }
                else if (_mode == MouseMode.Select)
                {
                    // TODO: Show game menu
                }
            }

            UpdateDragging();
            UpdateCameraMovement();

            _lastFramePosition = CameraController.Instance.ScreenToWorldPoint(SDLEvent.MousePosition);
        }
        public void Update()
        {
            // Check for movement input
            float scrollSpeed  = 100f;
            var   dragDistance = Time.DeltaTime * scrollSpeed;

            if (SDLEvent.KeyState(SDL_Keycode.SDLK_a))
            {
                _position.X -= dragDistance;
            }
            if (SDLEvent.KeyState(SDL_Keycode.SDLK_d))
            {
                _position.X += dragDistance;
            }
            if (SDLEvent.KeyState(SDL_Keycode.SDLK_w))
            {
                _position.Y += dragDistance;
            }
            if (SDLEvent.KeyState(SDL_Keycode.SDLK_s))
            {
                _position.Y -= dragDistance;
            }
        }
Exemple #5
0
        private void UpdateDragging()
        {
            /*
             * // If over UI, do nothing
             * if (EventSystem.current.IsPointerOverGameObject())
             * {
             *  return;
             * }
             */

            // Clear the drag-area markers
            while (_dragPreviewGameObjects.Count > 0)
            {
                var go = _dragPreviewGameObjects[0];
                _dragPreviewGameObjects.RemoveAt(0);
                SimplePool.Despawn(go);
            }

            if (_mode != MouseMode.Build)
            {
                return;
            }

            // Start Drag
            if (SDLEvent.MouseButtonWentDown(SDL.SDL_BUTTON_LEFT))
            {
                _dragStartPosition = _currentFramePosition;
                _isDragging        = true;
            }
            else if (_isDragging == false)
            {
                _dragStartPosition = _currentFramePosition;
            }
            if (SDLEvent.MouseButtonWentUp(SDL.SDL_BUTTON_RIGHT) || SDLEvent.KeyUp(SDL.SDL_Keycode.SDLK_ESCAPE))
            {
                // The RIGHT mouse button came up or ESC was pressed, so cancel any dragging.
                _isDragging = false;
            }

            //if (_bmc.IsObjectDraggable() == false)
            //{
            //    _dragStartPosition = _currentFramePosition;
            //}


            var startX = Mathf.FloorToInt(_dragStartPosition.X + 0.5f);
            var endX   = Mathf.FloorToInt(_currentFramePosition.X + 0.5f);
            var startY = Mathf.FloorToInt(_dragStartPosition.Y + 0.5f);
            var endY   = Mathf.FloorToInt(_currentFramePosition.Y + 0.5f);

            if (endX < startX)
            {
                var temp = endX;
                endX   = startX;
                startX = temp;
            }

            if (endY < startY)
            {
                var temp = endY;
                endY   = startY;
                startY = temp;
            }

            // Put one marker at the mouse position for testing
            //var cursor = SimplePool.Spawn(_circleCursorPrefab, new Vector2<float>(_currentFramePosition.X, _currentFramePosition.Y), 0);
            //cursor.Sprite.Centered = true;
            //cursor.Name = "mousepos";
            //_dragPreviewGameObjects.Add(cursor);

            // Display dragged area
            for (var x = startX; x <= endX; x++)
            {
                for (var y = startY; y <= endY; y++)
                {
                    var t = World.Instance.GetTileAt(x, y);
                    if (t != null)
                    {
                        var actionTile = true;

                        // If shift is being held, just action the perimeter
                        if (SDLEvent.KeyState(SDL.SDL_Keycode.SDLK_LSHIFT) || SDLEvent.KeyState(SDL.SDL_Keycode.SDLK_RSHIFT))
                        {
                            actionTile = (x == startX || x == endX || y == startY || y == endY);
                        }

                        if (actionTile)
                        {
                            //if (_bmc.BuildMode == BuildMode.Furniture)
                            //{
                            //    ShowFurnitureSpriteAtTile(_bmc.BuildModeObjectType, t);
                            //}
                            //else
                            //{
                            var go = SimplePool.Spawn(_circleCursorPrefab, new Vector2 <float>(x, y), 0);
                            // go.transform.SetParent(this.transform, true);
                            _dragPreviewGameObjects.Add(go);
                            //}
                        }
                    }
                }
            }

            // End Drag
            if (_isDragging && SDLEvent.MouseButtonWentUp(SDL.SDL_BUTTON_LEFT))
            {
                _isDragging = false;
                for (var x = startX; x <= endX; x++)
                {
                    for (var y = startY; y <= endY; y++)
                    {
                        var actionTile = true;

                        // If shift is being held, just action the perimeter
                        if (SDLEvent.KeyState(SDL.SDL_Keycode.SDLK_LSHIFT) || SDLEvent.KeyState(SDL.SDL_Keycode.SDLK_RSHIFT))
                        {
                            actionTile = (x == startX || x == endX || y == startY || y == endY);
                        }

                        if (actionTile)
                        {
                            var t = World.Instance.GetTileAt(x, y);
                            if (t != null)
                            {
                                // _bmc.DoBuild(t);
                            }
                        }
                    }
                }
            }
        }