Esempio n. 1
0
        /// <summary>Runs the game.</summary>
        public void Run()
        {
            string[] commandLineArguments = Environment.GetCommandLineArgs();

            _sys = new OpenTKSys(commandLineArguments);

            DisplayDevice displayDevice = DisplayDevice.Default;

            bool windowed = _sys.GameConfig.VideoWindowed;
            int width, height;
            if(windowed)
            {
                width = _sys.GameConfig.VideoWindowWidth(displayDevice.Width);
                height = _sys.GameConfig.VideoWindowHeight(displayDevice.Height);
            }
            else
            {
                width = displayDevice.Width;
                height = displayDevice.Height;
            }

            GameWindowFlags gameWindowFlags = (windowed ? GameWindowFlags.FixedWindow : GameWindowFlags.Fullscreen);
            using(_gameWindow = new GameWindow(width, height, GraphicsMode.Default, "Hovertank3DdotNet (OpenTK)", gameWindowFlags))
            {
                _gameWindow.VSync = (_sys.GameConfig.VideoVSync ? VSyncMode.On : VSyncMode.Off);

                if(windowed)
                {
                    int left, top;
                    if(_sys.GameConfig.VideoWindowCenter)
                    {
                        left = (displayDevice.Width - _gameWindow.Width) / 2;
                        top = (displayDevice.Height - _gameWindow.Height) / 2;
                    }
                    else
                    {
                        left = _sys.GameConfig.VideoWindowLeft(displayDevice.Width);
                        top = _sys.GameConfig.VideoWindowTop(displayDevice.Height);
                    }

                    _gameWindow.Location = new Point(left, top);
                }

                _viewportSize = new Size(_gameWindow.Width, _gameWindow.Height);

                _gameWindow.Load += gameWindow_Load;
                _gameWindow.Resize += gameWindow_Resize;
                _gameWindow.UpdateFrame += gameWindow_UpdateFrame;
                _gameWindow.RenderFrame += gameWindow_RenderFrame;
                _gameWindow.Unload += gameWindow_Unload;

                // This can fail if OpenAL isn't installed
                SoundSystem soundSystem = new OpenTKSoundSystem();
                _sys.InitialiseSound(soundSystem);

                _input = new OpenTKInputSystem(_gameWindow);
                _disposableObjects.Add(_input);
                _sys.InitialiseInput(_input);

                _hovertank = new Hovertank(_sys);
                _hovertank.StateInitialise();

                // Dispose sound system after sounds
                _disposableObjects.Add(soundSystem);

                _gameWindow.Run(70.0);
            }
        }
Esempio n. 2
0
        /// <summary>Creates a new FormGame.</summary>
        public FormGame()
        {
            _sys = new WinFormsSys(Program.CommandLineArguments);

            if(_sys.GameConfig.VideoWindowed)
            {
                Screen screen = Screen.FromHandle(Handle);

                int width = _sys.GameConfig.VideoWindowWidth(screen.Bounds.Width);
                int height = _sys.GameConfig.VideoWindowHeight(screen.Bounds.Height);

                FormBorderStyle = FormBorderStyle.FixedSingle;
                StartPosition = FormStartPosition.Manual;
                WindowState = FormWindowState.Normal;

                ClientSize = new Size(width, height);

                int left, top;
                if(_sys.GameConfig.VideoWindowCenter)
                {
                    left = (screen.Bounds.Width - Size.Width) / 2;
                    top = (screen.Bounds.Height - Size.Height) / 2;
                }
                else
                {
                    left = _sys.GameConfig.VideoWindowLeft(screen.Bounds.Width);
                    top = _sys.GameConfig.VideoWindowTop(screen.Bounds.Height);
                }
                Location = new Point(left, top);
            }
            else
            {
                FormBorderStyle = FormBorderStyle.None;
                StartPosition = FormStartPosition.CenterScreen;
                WindowState = FormWindowState.Maximized;
                MaximizeBox = false;
            }

            InitializeComponent();

            _sys.InitialiseSound(new WinFormsSoundSystem());

            WinFormsInputSystem input = new WinFormsInputSystem(this);
            _sys.InitialiseInput(input);

            BackColor = Color.Black;

            _imageView = new ImageView();
            _imageView.Location = new Point();
            _imageView.Size = ClientSize;
            _imageView.LinearFilter = _sys.GameConfig.VideoFilter;
            Controls.Add(_imageView);

            _hovertank = new Hovertank(_sys);
            _hovertank.StateInitialise();

            backgroundWorker.DoWork += backgroundWorker_DoWork;
            backgroundWorker.ProgressChanged += backgroundWorker_ProgressChanged;
            backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;

            backgroundWorker.RunWorkerAsync();
        }
Esempio n. 3
0
        /// <summary>Initialises the game.</summary>
        public void InitialiseGame()
        {
            _sys = new SharpDXSys(Program.CommandLineArguments);

            bool windowed = _sys.GameConfig.VideoWindowed;

            Screen screen = Screen.FromHandle(Handle);
            int width, height;

            StartPosition = FormStartPosition.Manual;
            WindowState = FormWindowState.Normal;
            if(windowed)
            {
                width = _sys.GameConfig.VideoWindowWidth(screen.Bounds.Width);
                height = _sys.GameConfig.VideoWindowHeight(screen.Bounds.Height);
                FormBorderStyle = FormBorderStyle.FixedSingle;
            }
            else
            {
                width = screen.Bounds.Width;
                height = screen.Bounds.Height;
                FormBorderStyle = FormBorderStyle.None;
            }

            ClientSize = new Size(width, height);

            if(windowed)
            {
                int left, top;
                if(_sys.GameConfig.VideoWindowCenter)
                {
                    left = (screen.Bounds.Width - Size.Width) / 2;
                    top = (screen.Bounds.Height - Size.Height) / 2;
                }
                else
                {
                    left = _sys.GameConfig.VideoWindowLeft(screen.Bounds.Right - 32);
                    top = _sys.GameConfig.VideoWindowTop(screen.Bounds.Bottom - 32);
                }
                Location = new System.Drawing.Point(left, top);
            }

            bool vsync = _sys.GameConfig.VideoVSync;

            InitialiseDirect3D(windowed, vsync);

            _renderer = new DX9SoftwareRenderer();
            _renderer.Initialise(_device, 320, 200);
            _renderer.UseLinearFiltering = _sys.GameConfig.VideoFilter;
            AddResource(_renderer);

            _stopwatch = new Stopwatch();

            _hovertank = new Hovertank(_sys);
            _hovertank.StateInitialise();
            _disposableResources.Add(_sys);

            SoundSystem soundSystem = new SharpDXSoundSystem(this);
            _sys.InitialiseSound(soundSystem);
            _disposableResources.Add(soundSystem); // Note: The sound system needs to be disposed after sys

            _input = new SharpDXInputSystem(this);
            _sys.InitialiseInput(_input);
            _disposableResources.Add(_input);

            _stopwatch.Start();
        }
Esempio n. 4
0
        /// <summary>Updates the view.</summary>
        /// <param name="hovertank">The hovertank game engine.</param>
        public void UpdateView(Hovertank hovertank)
        {
            // Convert display to RGB with emulation of some EGA features
            byte[] videoBuffer = hovertank.Display.VideoBuffer;
            int[] palette = hovertank.Display.Palette;

            int srcIndex = hovertank.Display.ScreenStartIndex + hovertank.Display.PixelOffset;
            int dstIndex = 0;
            for(int y = 0; y < 200; y++)
            {
                if(y == hovertank.Display.SplitScreenLines)
                    srcIndex = 0;

                for(int x = 0; x < 320; x++)
                    _rgb[dstIndex++] = palette[videoBuffer[srcIndex++]];

                srcIndex += hovertank.Display.Stride - 320;
            }

            Bitmap bitmap = _bitmaps[_bitmapIndex++];
            _bitmapIndex %= NumBitmaps;

            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, 320, 200), ImageLockMode.WriteOnly, _pixelFormat);
            Marshal.Copy(_rgb, 0, bitmapData.Scan0, _rgb.Length);
            bitmap.UnlockBits(bitmapData);

            _paintBitmap = bitmap;

            Invalidate();
        }