public void Run(IGame game) { if (_game != null) throw new InvalidOperationException("A game is already running."); if (_device == null) throw new InvalidOperationException("Setup must be called before Run."); Current = this; Show(); _game = game; try { var sw = Stopwatch.StartNew(); _game.Setup(_device, this); while (_game != null) { Application.DoEvents(); if (!IsDeviceLost()) { var deltaTime = sw.Elapsed; sw.Restart(); if (game.Process(_device, deltaTime)) game.Paint(_device); else { Close(); break; } } } } catch { Close(); throw; } game.ShutDown(_device); Current = null; }
public Level(GameWindow window, Device device, int number) : base(device) { ClearColor = new Color(0x51, 0xa9, 0xf0); #if DEBUG _mapFile = "../../Assets/Maps/Level" + number + ".txt"; #else _mapFile = "Assets/Maps/Level" + number + ".txt"; #endif DisabledSet = new HashSet<GameObject>(); ReloadScene(device); if (_player != null) { _camera = new Camera { new LookAtObject(_player), new Follow(_player) { Speed = 40, SlowingDist = 5, Offset = new Vector3(0, 4, 0), Mask = new Vector3(1, 1, 0) }, new RigidBody { Friction = new Vector3(8, 20, 8), //MaxSpeed = new Vector3(5f) } }; _camera.Viewport = new SharpDX.Viewport(0, 0, window.Width, window.Height); _camera.SetPerspective(60, window.Width / (float)window.Height, 1, 5000); //camera.SetOrthographic(20, 20 * (window.Height / (float)window.Width), 1, 5000); MoveCameraToPlayer(); Add(_camera); } }
static void Main(string[] args) { using (var win = new GameWindow("Cubeecraft Mario", 800, 600, fullScreen: false, vsync: true, hardwareAccelerated: true)) using (var game = new MyGame()) win.Run(game); }
public void Setup(Device device, GameWindow window) { _scene = new Level(window, device, 1); _scene.Init(); }