static void Main(string[] args) { var window = new ExampleWindow(); var dir = ContentSearchDirectoryAttribute.GetContentSearchDirectory(); var tileMap = new TileMap(dir + @"\Content\level.tmx"); var model = new Model(tileMap.ExtractStart(), tileMap.ExtractCollisionGrid()); var view = new View(window.ContentLoader, window.RenderContext.RenderState, tileMap.ExtractTileSprites(), tileMap.ExtractViewLayerGrids()); window.GameWindow.MouseWheel += (s, e) => view.Zoom *= (float)Math.Pow(1.05, 3 * e.DeltaPrecise); float MovementAxis(float dt, string keyMinus, string keyPlus) { return(window.Input.IsButtonDown(keyPlus) ? dt : window.Input.IsButtonDown(keyMinus) ? -dt : 0f); } window.Update += (dt) => { Console.WriteLine(string.Join("#", window.Input.PressedButtons)); float deltaX = MovementAxis(dt, "Left", "Right"); float deltaY = MovementAxis(dt, "Down", "Up"); model.Update(deltaX, deltaY); }; window.Render += () => { view.Draw(model.Player); }; window.Resize += view.Resize; window.Run(); }
private static void Main() { var window = new ExampleWindow(); var model = new Model(); var view = new View(); window.Update += (dt) => { // handle input var movementXAxis = Keyboard.GetState()[Key.Left] ? -1f : (Keyboard.GetState()[Key.Right] ? 1f : 0f); model.Update(movementXAxis, dt); }; window.Render += () => { view.ClearScreen(); view.DrawPlayer(model.playerBounds.CenterX, model.playerBounds.CenterY, model.playerBounds.Radius); foreach (var shape in model.ShapeBounds) { view.DrawAsteroids(shape); } }; window.Resize += view.Resize; window.Run(); }
private static void Main() { var window = new ExampleWindow(); var model = new Model(1000); var renderer = new Renderer(); void updateSourceLocation(MouseEventArgs e) { model.Emitter = window.GameWindow.ConvertWindowPixelCoords(e.X, e.Y); //convert pixel coordinates to [-1,1]² } //move the mouse to move the particle source(emitter) window.GameWindow.MouseMove += (s, a) => updateSourceLocation(a); window.GameWindow.MouseDown += (s, a) => updateSourceLocation(a); window.Update += (time) => model.Update(time); window.Resize += renderer.Resize; window.Render += () => { renderer.Clear(); foreach (var particle in model.Particles) { renderer.DrawPoint(particle.Location, particle.Age); } renderer.DrawPoint(model.Emitter, Color.Red); }; window.Run(); }
private static void Main() { var window = new ExampleWindow(); var model = new Model(); var view = new View(); window.Update += (dt) => { // handle input float axisLeftRight = window.Input.IsButtonDown("Left") ? -1f : window.Input.IsButtonDown("Right") ? 1f : 0f; model.Update(axisLeftRight, dt); }; window.Render += () => { view.ClearScreen(); foreach (var shape in model.ShapeBounds) { view.DrawShape(shape); } }; window.Resize += view.Resize; window.Run(); }
private static void Main() { var window = new ExampleWindow(); var model = new Model(); var visual = new MyVisual(window.RenderContext.RenderState, window.ContentLoader); var time = new GameTime(); window.Render += () => visual.Render(model.MovingObject); window.Update += (dt) => model.Update(time.AbsoluteTime); window.Run(); }
private static void Main() { var window = new ExampleWindow(); var model = new Model(1000); var renderer = new Renderer(window.RenderContext.RenderState, window.ContentLoader); window.Update += (time) => model.Update(time); window.Resize += renderer.Resize; window.Render += () => { renderer.Clear(); renderer.DrawElements(model.Elements); renderer.DrawPlayer(model.Player); }; window.Run(); }
static void Main(string[] args) { var window = new ExampleWindow(); var tileMap = new TileMap(); var model = new Model(tileMap.ExtractStart(), tileMap.ExtractCollisionGrid()); var view = new View(window.ContentLoader, window.RenderContext.RenderState, tileMap.ExtractTileSprites(), tileMap.ExtractViewLayerGrids()); window.GameWindow.MouseWheel += (s, e) => view.Zoom *= (float)Math.Pow(1.05, 3 * e.DeltaPrecise); window.Update += (dt) => { float deltaX = MovementAxis(dt, Key.Left, Key.Right); float deltaY = MovementAxis(dt, Key.Down, Key.Up); model.Update(deltaX, deltaY); }; window.Render += () => { view.Draw(model.Player); }; window.Resize += view.Resize; window.Run(); }