public void Render(TimeSpan delta, RenderTarget target, UISceneManager ui) { ui.CurrentScene = scene; bg.Scale = new Vector2f(1280, 1); target.Draw(bg); bgBack.Position = new Vector2f(player.PhysObj.Position.X * 0.1f, 720); target.Draw(bgBack); bgFore.Position = new Vector2f(player.PhysObj.Position.X * 0.2f, 720); target.Draw(bgFore); if (settings.EnableClouds) { total += delta; if (total > TimeSpan.FromSeconds(0.1)) { t += 0.005f; GenerateClouds(); total = TimeSpan.Zero; } RenderUI(delta, target); } View v = target.GetView(); var vx = player.PhysObj.Position * 10; v.Center = new Vector2f(vx.X, vx.Y); v.Zoom(1.6f); target.SetView(v); world.Render(target); target.Draw(portal); player.Render(delta, target); View vi = target.GetView(); vi.Center = new Vector2f(640, 360); vi.Zoom(0.625f); target.SetView(vi); }
public void Render(TimeSpan delta, RenderTarget target, UISceneManager ui) { target.Clear(Colors.White); particles.Render(particleTexture, particle); bg.Texture = particleTexture.Texture; bg.Color = new Color(150, 150, 150, 150); target.Draw(bg); ui.CurrentScene = scene; }
public void Run() { window = new RenderWindow(new VideoMode(1280, 720), "DOX30 Editor", Styles.Titlebar | Styles.Close); window.Closed += window_Closed; window.Resized += window_Resized; window.MouseWheelMoved += window_MouseWheelMoved; window.MouseButtonPressed += window_MouseButtonPressed; window.MouseMoved += window_MouseMoved; window.MouseButtonReleased += window_MouseButtonReleased; window.KeyPressed += window_KeyPressed; window.KeyReleased += window_KeyReleased; world = new PhysicsWorld(true); ui = new UISceneManager(); ui.Init(window); Scene scene = new Scene(ScrollInputs.None); RectControl bg = new RectControl() { Position = new Vector2f(0, 0), Size = new Vector2f(1280, 50), Anchor = AnchorPoints.Left | AnchorPoints.Top | AnchorPoints.Right, BackgroundColor = Colors.WhiteSmoke }; FastButton runButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/playButton.png", "Content/playButton.png", "Content/playButton.png") { Position = new Vector2f(0, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top }; runButton.OnClick += (s, e) => { enabled = true; }; FastButton pauseButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/pauseButton.png", "Content/pauseButton.png", "Content/pauseButton.png") { Position = new Vector2f(50, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top }; pauseButton.OnClick += (s, e) => { enabled = false; }; FastButton saveButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/saveButton.png", "Content/saveButton.png", "Content/saveButton.png") { Position = new Vector2f(125, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top }; saveButton.OnClick += (s, e) => { Export(); }; FastButton loadButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/loadButton.png", "Content/loadButton.png", "Content/loadButton.png") { Position = new Vector2f(175, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top }; loadButton.OnClick += (s, e) => { var ofd = new System.Windows.Forms.OpenFileDialog(); ofd.Filter = "Level Files (*.json)|*.json"; ofd.InitialDirectory = Directory.GetCurrentDirectory(); var r = ofd.ShowDialog(); if (r == System.Windows.Forms.DialogResult.OK) { Import(ofd.FileName); } }; FastButton addBoxButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/boxButton.png", "Content/boxButton.png", "Content/boxButton.png") { Position = new Vector2f(250, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top }; addBoxButton.OnClick += (s, e) => { world.CreateBox(new Vector2f(10, 10), 4, BodyType.Static).Position = new Vector2(offset.X, offset.Y) * -0.1f; world.Step(0); }; FastButton addCircleButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/circleButton.png", "Content/circleButton.png", "Content/circleButton.png") { Position = new Vector2f(300, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top }; addCircleButton.OnClick += (s, e) => { world.CreateCircle(5, 5, BodyType.Static).Position = new Vector2(offset.X, offset.Y) * -0.1f; world.Step(0); }; scene.AddComponent(bg); scene.AddComponent(runButton); scene.AddComponent(pauseButton); scene.AddComponent(addBoxButton); scene.AddComponent(addCircleButton); scene.AddComponent(saveButton); scene.AddComponent(loadButton); // scene.AddComponent(new WorldHierachyRenderer(world) { Size = new Vector2f(300, 670), Position = new Vector2f(0, 50), BackgroundColor = Colors.Snow }); // Does not update on change dynamic/static ui.CurrentScene = scene; grid = new Sprite(new Texture("Content/grid.png")); grid.Origin = new Vector2f(512, 512); contextMenu = new ContextMenu(); contextMenu.Add(() => { selected.BodyType = BodyType.Dynamic; }, "Set Dynamic"); contextMenu.Add(() => { selected.BodyType = BodyType.Static; }, "Set Static"); contextMenu.Add(() => { world.FindBody(selected).GameDimension = Dimension.None; }, "Set No Dimension"); contextMenu.Add(() => { world.FindBody(selected).GameDimension = world.FindBody(selected).GameDimension == Dimension.OneO ? Dimension.TwoX : Dimension.OneO; }, "Switch Dimension"); contextMenu.Add(() => { selected.Rotation += 0.0872664626f; }, "+5 Rotation"); contextMenu.Add(() => { selected.Rotation += 0.785398163f; }, "+45 Rotation"); contextMenu.Add(() => { selected.Rotation -= 0.0872664626f; }, "-5 Rotation"); contextMenu.Add(() => { selected.Rotation -= 0.785398163f; }, "-45 Rotation"); contextMenu.Add(() => { world.Copy(selected, new Vector2(offset.X, offset.Y) * -0.1f); }, "Duplicate"); contextMenu.Add(() => { world.Remove(selected); }, "Remove"); messageScene = new Scene(ScrollInputs.None); Stopwatch sw = new Stopwatch(); TimeSpan elapsed = TimeSpan.Zero; TimeSpan secondCounter = TimeSpan.Zero; int frames = 0; world.Step(0); View v; Console.WriteLine(window.GetView().Center); while (window.IsOpen()) { sw.Start(); window.DispatchEvents(); window.Clear(); if (enabled) world.Step((float)elapsed.TotalSeconds); v = window.GetView(); v.Zoom(zoom); v.Center = (world.CamLock == null ? -offset : new Vector2f(world.CamLock.Position.X * 10, world.CamLock.Position.Y * 10)); if (world.CamLock != null) v.Rotation = world.CamLock.Rotation * 57.2957795f; else v.Rotation = 0; window.SetView(v); window.Draw(grid); world.Render(window); v = window.GetView(); v.Size = new Vector2f(1280, 720); v.Rotation = 0; v.Center = new Vector2f(640, 360); window.SetView(v); ui.Render(window); ui.CurrentScene = messageScene; ui.Render(window); ui.CurrentScene = scene; contextMenu.Render(window); window.Display(); sw.Stop(); elapsed = sw.Elapsed; secondCounter += elapsed; frames++; if (secondCounter >= TimeSpan.FromSeconds(1)) { Console.WriteLine(frames / secondCounter.TotalSeconds); secondCounter -= TimeSpan.FromSeconds(1); frames = 0; } sw.Reset(); } }
public void Render(TimeSpan delta, RenderTarget target, UISceneManager ui) { ui.CurrentScene = scene; }