コード例 #1
0
ファイル: GLUtils.cs プロジェクト: tzachshabtay/MonoAGS
        public void RefreshViewport(IGameSettings settings, IGameWindow gameWindow)
        { 
            if (settings.PreserveAspectRatio) //http://www.david-amador.com/2013/04/opengl-2d-independent-resolution-rendering/
            {
                float targetAspectRatio = (float)settings.VirtualResolution.Width / settings.VirtualResolution.Height;
                Size screen = new Size(gameWindow.Width, gameWindow.Height);
                int width = screen.Width;
                int height = (int)(width / targetAspectRatio + 0.5f);
                if (height > screen.Height)
                {
                    //It doesn't fit our height, we must switch to pillarbox then
                    height = screen.Height;
                    width = (int)(height * targetAspectRatio + 0.5f);
                }

                // set up the new viewport centered in the backbuffer
                int viewX = (screen.Width / 2) - (width / 2);
                int viewY = (screen.Height / 2) - (height / 2);

                _graphics.Viewport(viewX, viewY, width, height);
            }
            else
            {
                _graphics.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
            }
        }
コード例 #2
0
        public static void Run()
        {
            FakeAGSTestGameStarter starter = new FakeAGSTestGameStarter();
            var game = AGSGame.CreateEmpty();

            _gameDebugView = new Lazy <GameDebugView>(() =>
            {
                var gameDebugView = new GameDebugView(game, new KeyboardBindings(game.Input));
                gameDebugView.Load();
                return(gameDebugView);
            });

            starter.StartGame(game);

            Size screenSize = new AGS.API.Size(320, 200);
            int  factor     = 2;

            AGSGameSettings settings = new AGSGameSettings(
                "Demo Game",
                screenSize,
                windowSize: new AGS.API.Size(screenSize.Width * factor, screenSize.Height * factor),
                windowState: WindowState.Normal);

            game.Start(settings);
        }
コード例 #3
0
 public AGSGameLoop(IGameState gameState, AGS.API.Size virtualResolution,
                    IDisplayList displayList, IInput input)
 {
     _displayList       = displayList;
     _gameState         = gameState;
     _virtualResolution = virtualResolution;
     _input             = input;
 }
コード例 #4
0
ファイル: AGSGameLoop.cs プロジェクト: saizant/MonoAGS
 public AGSGameLoop(IGameState gameState, AGS.API.Size virtualResolution,
                    IAGSRoomTransitions roomTransitions, IGameEvents events)
 {
     _gameState         = gameState;
     _events            = events;
     _virtualResolution = virtualResolution;
     _roomTransitions   = roomTransitions;
 }
コード例 #5
0
ファイル: AndroidInput.cs プロジェクト: saizant/MonoAGS
        public AndroidInput(AndroidSimpleGestures gestures, AGS.API.Size virtualResolution,
                            IGameState state, IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize)
        {
            MousePosition     = new MousePosition(0f, 0f, state.Viewport);
            _shouldBlockInput = shouldBlockInput;
            _windowSize       = windowSize;
            _state            = state;
            API.MousePosition.VirtualResolution = virtualResolution;
            float density = Resources.System.DisplayMetrics.Density;

            API.MousePosition.GetWindowWidth  = () => (int)(_windowSize.GetWidth(null) - ((GLUtils.ScreenViewport.X * 2) / density));
            API.MousePosition.GetWindowHeight = () => (int)(_windowSize.GetHeight(null) - ((GLUtils.ScreenViewport.Y * 2) / density));
            MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp   = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent <MousePositionEventArgs>();
            KeyDown   = new AGSEvent <KeyboardEventArgs>();
            KeyUp     = new AGSEvent <KeyboardEventArgs>();

            gestures.OnUserDrag += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                DateTime now = DateTime.Now;
                _lastDrag   = now;
                IsTouchDrag = true;
                setMousePosition(e);
                await MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition));

                await Task.Delay(300);

                if (_lastDrag <= now)
                {
                    IsTouchDrag = false;
                }
            };
            gestures.OnUserSingleTap += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                setMousePosition(e);
                LeftMouseButtonDown = true;
                await MouseDown.InvokeAsync(new MouseButtonEventArgs(null, MouseButton.Left, MousePosition));

                await Task.Delay(250);

                await MouseUp.InvokeAsync(new MouseButtonEventArgs(null, MouseButton.Left, MousePosition));

                LeftMouseButtonDown = false;
            };
            AndroidGameWindow.Instance.OnNewView += onViewChanged;
            onViewChanged(null, AndroidGameWindow.Instance.View);
        }
コード例 #6
0
ファイル: GLFrameBuffer.cs プロジェクト: tzachshabtay/MonoAGS
        public GLFrameBuffer(Size size, IGraphicsBackend graphics)
		{
            _width = size.Width;
            _height = size.Height;
            Texture = new GLTexture(null, graphics);
            _graphics = graphics;
            _graphics.TexImage2D(_width, _height, IntPtr.Zero);

			_fbo = _graphics.GenFrameBuffer();
		}
コード例 #7
0
        public IOSInput(IOSGestures gestures, AGS.API.Size virtualResolution,
                        IGameState state, IShouldBlockInput shouldBlockInput, IGameWindow gameWindow)
        {
            MousePosition     = new MousePosition(0f, 0f, state.Viewport);
            _shouldBlockInput = shouldBlockInput;
            _gameWindow       = gameWindow;
            _state            = state;
            API.MousePosition.VirtualResolution = virtualResolution;
            updateWindowSizeFunctions();

            MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp   = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent <MousePositionEventArgs>();
            KeyDown   = new AGSEvent <KeyboardEventArgs>();
            KeyUp     = new AGSEvent <KeyboardEventArgs>();

            IOSGameWindow.Instance.View.OnInsertText     += onInsertText;
            IOSGameWindow.Instance.View.OnDeleteBackward += onDeleteBackwards;

            gestures.OnUserDrag += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                DateTime now = DateTime.Now;
                _lastDrag   = now;
                IsTouchDrag = true;
                setMousePosition(e);
                await MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition));

                await Task.Delay(300);

                if (_lastDrag <= now)
                {
                    IsTouchDrag = false;
                }
            };
            gestures.OnUserSingleTap += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                setMousePosition(e);
                LeftMouseButtonDown = true;
                await MouseDown.InvokeAsync(new MouseButtonEventArgs(null, MouseButton.Left, MousePosition));

                await Task.Delay(250);

                await MouseUp.InvokeAsync(new MouseButtonEventArgs(null, MouseButton.Left, MousePosition));

                LeftMouseButtonDown = false;
            };
        }
コード例 #8
0
ファイル: AGSGameLoop.cs プロジェクト: jeancallisti/MonoAGS
 public AGSGameLoop(IGameState gameState, AGS.API.Size virtualResolution,
                    IAGSRoomTransitions roomTransitions, IGameEvents events,
                    IDisplayList displayList, IInput input)
 {
     _displayList       = displayList;
     _gameState         = gameState;
     _events            = events;
     _virtualResolution = virtualResolution;
     _roomTransitions   = roomTransitions;
     _input             = input;
 }
コード例 #9
0
ファイル: AGSGameSettings.cs プロジェクト: saizant/MonoAGS
 public AGSGameSettings(string title, AGS.API.Size virtualResolution, WindowState windowState = WindowState.Maximized,
                        AGS.API.Size?windowSize   = null, VsyncMode vsync = VsyncMode.Adaptive, bool preserveAspectRatio = true,
                        WindowBorder windowBorder = WindowBorder.Resizable)
 {
     Title               = title;
     VirtualResolution   = virtualResolution;
     WindowState         = windowState;
     WindowSize          = windowSize.HasValue ? windowSize.Value : virtualResolution;
     Vsync               = vsync;
     PreserveAspectRatio = preserveAspectRatio;
     WindowBorder        = windowBorder;
 }
コード例 #10
0
ファイル: AndroidInput.cs プロジェクト: ebrucucen/MonoAGS
        public AndroidInput(AndroidSimpleGestures gestures, AGS.API.Size virtualResolution,
                            IGameState state, IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize)
        {
            _shouldBlockInput   = shouldBlockInput;
            _windowSize         = windowSize;
            _state              = state;
            this._virtualWidth  = virtualResolution.Width;
            this._virtualHeight = virtualResolution.Height;
            MouseDown           = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp             = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove           = new AGSEvent <MousePositionEventArgs>();
            KeyDown             = new AGSEvent <KeyboardEventArgs>();
            KeyUp = new AGSEvent <KeyboardEventArgs>();

            gestures.OnUserDrag += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                DateTime now = DateTime.Now;
                _lastDrag   = now;
                IsTouchDrag = true;
                setMousePosition(e);
                await MouseMove.InvokeAsync(sender, new MousePositionEventArgs(MouseX, MouseY));

                await Task.Delay(300);

                if (_lastDrag <= now)
                {
                    IsTouchDrag = false;
                }
            };
            gestures.OnUserSingleTap += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                setMousePosition(e);
                LeftMouseButtonDown = true;
                await MouseDown.InvokeAsync(sender, new MouseButtonEventArgs(MouseButton.Left, MouseX, MouseY));

                await Task.Delay(250);

                await MouseUp.InvokeAsync(sender, new MouseButtonEventArgs(MouseButton.Left, MouseX, MouseY));

                LeftMouseButtonDown = false;
            };
            AndroidGameWindow.Instance.OnNewView += onViewChanged;
            onViewChanged(null, AndroidGameWindow.Instance.View);
        }
コード例 #11
0
 public void SetSize(OpenTK.INativeWindow gameWindow, AGS.API.Size size)
 {
 }
コード例 #12
0
ファイル: AGSInput.cs プロジェクト: ebrucucen/MonoAGS
        public AGSInput(GameWindow game, AGS.API.Size virtualResolution, IGameState state,
                        IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize)
        {
            _windowSize            = windowSize;
            this._shouldBlockInput = shouldBlockInput;
            this._virtualWidth     = virtualResolution.Width;
            this._virtualHeight    = virtualResolution.Height;
            this._state            = state;
            this._keysDown         = new AGSConcurrentHashSet <Key>();

            this._game             = game;
            this._originalOSCursor = _game.Cursor;

            MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp   = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent <MousePositionEventArgs>();
            KeyDown   = new AGSEvent <KeyboardEventArgs>();
            KeyUp     = new AGSEvent <KeyboardEventArgs>();

            game.MouseDown += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                var button = convert(e.Button);
                if (button == AGS.API.MouseButton.Left)
                {
                    LeftMouseButtonDown = true;
                }
                else if (button == AGS.API.MouseButton.Right)
                {
                    RightMouseButtonDown = true;
                }
                await MouseDown.InvokeAsync(sender, new AGS.API.MouseButtonEventArgs(button, convertX(e.X), convertY(e.Y)));
            };
            game.MouseUp += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                var button = convert(e.Button);
                if (button == AGS.API.MouseButton.Left)
                {
                    LeftMouseButtonDown = false;
                }
                else if (button == AGS.API.MouseButton.Right)
                {
                    RightMouseButtonDown = false;
                }
                await MouseUp.InvokeAsync(sender, new AGS.API.MouseButtonEventArgs(button, convertX(e.X), convertY(e.Y)));
            };
            game.MouseMove += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                await MouseMove.InvokeAsync(sender, new MousePositionEventArgs(convertX(e.X), convertY(e.Y)));
            };
            game.KeyDown += async(sender, e) =>
            {
                Key key = convert(e.Key);
                _keysDown.Add(key);
                if (isInputBlocked())
                {
                    return;
                }
                await KeyDown.InvokeAsync(sender, new KeyboardEventArgs(key));
            };
            game.KeyUp += async(sender, e) =>
            {
                Key key = convert(e.Key);
                _keysDown.Remove(key);
                if (isInputBlocked())
                {
                    return;
                }
                await KeyUp.InvokeAsync(sender, new KeyboardEventArgs(key));
            };
        }
コード例 #13
0
 public void SetSize(OpenTK.INativeWindow gameWindow, AGS.API.Size size)
 {
     gameWindow.Size = new System.Drawing.Size(size.Width, size.Height);
 }
コード例 #14
0
ファイル: AGSGameLoop.cs プロジェクト: tzachshabtay/MonoAGS
		public AGSGameLoop (IGameState gameState, AGS.API.Size virtualResolution, IAGSRoomTransitions roomTransitions)
		{
			this._gameState = gameState;
			this._virtualResolution = virtualResolution;
			this._roomTransitions = roomTransitions;
		}
コード例 #15
0
ファイル: BitmapPool.cs プロジェクト: ebrucucen/MonoAGS
 private ObjectPool <IBitmap> getPool(int width, int height)
 {
     AGS.API.Size size = new AGS.API.Size(width, height);
     return(_bitmaps.GetOrAdd(size, _ => new ObjectPool <IBitmap> (() => _bitmapLoader.Load(width, height), 3,
                                                                   bitmap => bitmap.Clear())));
 }
コード例 #16
0
		public AGSRenderLayer(int z, PointF? parallaxSpeed = null, Size? independentResolution = null)
		{
			Z = z;
            ParallaxSpeed = parallaxSpeed ?? new PointF(1f, 1f);
            IndependentResolution = independentResolution;
		}
コード例 #17
0
ファイル: BitmapPool.cs プロジェクト: tzachshabtay/MonoAGS
		private ObjectPool<IBitmap> getPool(int width, int height)
		{
			AGS.API.Size size = new AGS.API.Size (width, height);
			return _bitmaps.GetOrAdd(size, _ => new ObjectPool<IBitmap> (() => Hooks.BitmapLoader.Load(width, height), 3,
				bitmap => bitmap.Clear()));
		}
コード例 #18
0
ファイル: AGSGameLoop.cs プロジェクト: ebrucucen/MonoAGS
 public AGSGameLoop(IGameState gameState, AGS.API.Size virtualResolution, IAGSRoomTransitions roomTransitions)
 {
     this._gameState         = gameState;
     this._virtualResolution = virtualResolution;
     this._roomTransitions   = roomTransitions;
 }
コード例 #19
0
 public void Init(AGS.API.Size virtualResolution)
 {
     API.MousePosition.VirtualResolution = virtualResolution;
 }
コード例 #20
0
ファイル: Size.cs プロジェクト: tzachshabtay/MonoAGS
 public bool Equals(Size other) => (Width == other.Width) && (Height == other.Height);