Esempio n. 1
0
        /// <summary>
        /// Repaints the screen. This performs the following actions in order:
        /// - GlobalEvent.DrawBackground events are raised
        /// - OnDrawBackground is called for the current room
        /// - OnDraw is called for each object, sorted according to Depth descending
        /// - OnDrawForeground is called for the current room
        /// - GlobalEvent.DrawForeground events are raised
        /// </summary>
        public static void Render()
        {
            View.Validate();

            GlobalEvent.OnDrawBackground();

            foreach (var instance in Instance.All)
            {
                instance.OnDraw();
            }

            GlobalEvent.OnDrawForeground();
            Time.UpdateFps();
        }
Esempio n. 2
0
        /// <summary>
        /// Performs a game loop. This includes the following phases, in order:
        /// - Begin step
        /// - Handle queued asynchronous actions
        /// - Keyboard, key press, key release
        /// - Mouse, mouse press, mouse release
        /// - Step
        /// - Collision
        /// - End step
        /// </summary>
        public static void Loop()
        {
            Time.Loop();

            GlobalEvent.OnBeginStep();
            _do <GameObject>(obj => obj.OnBeginStep());

            Async.HandleEvents();

            _handleInput();

            GlobalEvent.OnStep();
            _do(obj => obj.OnStep());

            _detectCollisions();

            GlobalEvent.OnEndStep();
            _do <GameObject>(obj => obj.OnEndStep());

            Instance.Sort();
        }
Esempio n. 3
0
        private static void _handleInput()
        {
            foreach (var key in Keyboard.Down)
            {
                GlobalEvent.OnKey(key);
                _do <IKeyListener>(i => i.OnKey(key));
            }

            foreach (var key in Keyboard.Pressed)
            {
                GlobalEvent.OnKeyPressed(key);
                _do <IKeyPressListener>(i => i.OnKeyPress(key));
            }

            foreach (var key in Keyboard.Released)
            {
                GlobalEvent.OnKeyReleased(key);
                _do <IKeyReleaseListener>(i => i.OnKeyRelease(key));
            }

            foreach (var button in Mouse.Down)
            {
                _doMouseClick <IMouseListener>(i => i.OnMouse(button));
            }

            foreach (var button in Mouse.Pressed)
            {
                _doMouseClick <IMousePressListener>(i => i.OnMousePress(button));
            }

            foreach (var button in Mouse.Released)
            {
                _doMouseClick <IMouseReleaseListener>(i => i.OnMouseRelease(button));
            }

            if (Mouse.WheelDelta != 0)
            {
                _doMouseClick <IMouseWheelListener>(i => i.OnMouseWheel(Mouse.WheelDelta));
            }

            foreach (var button in Mouse.Down)
            {
                _do <IGlobalMouseListener>(i => i.OnGlobalMouse(button));
                GlobalEvent.OnMouse(button);
            }

            foreach (var button in Mouse.Pressed)
            {
                _do <IGlobalMousePressListener>(i => i.OnGlobalMousePress(button));
                GlobalEvent.OnMousePressed(button);
            }

            foreach (var button in Mouse.Released)
            {
                _do <IGlobalMouseReleaseListener>(i => i.OnGlobalMouseRelease(button));
                GlobalEvent.OnMouseReleased(button);
            }

            if (Mouse.WheelDelta != 0)
            {
                _do <IGlobalMouseWheelListener>(i => i.OnGlobalMouseWheel(Mouse.WheelDelta));
                GlobalEvent.OnMouseWheel(Mouse.WheelDelta);
            }

            Keyboard.Update();
            Mouse.Update();
        }