public override void OnGameLoad(GameSpecification specification, MachinaRuntime runtime) { var gameScene = SceneLayers.AddNewScene(); var platform = gameScene.AddActor("Platform", new Vector2(200, 300)); new BoundingRect(platform, new Point(300, 32)) .SetOffsetToCenter(); new BoundingRectFill(platform, Color.White); var playerActor = gameScene.AddActor("Player", new Vector2(200, 200)); var playerSprites = MachinaClient.Assets.GetMachinaAsset <GridBasedSpriteSheet>("player"); new BoundingRect(playerActor, new Point(64, 32)); new SpriteRenderer(playerActor, playerSprites) .SetupBoundingRect(); // new PlayerController(playerActor); var uiScene = SceneLayers.AddNewScene(); var healthActor = uiScene.AddActor("Healthbar", new Vector2(10, 10)); new BoundingRect(healthActor, new Point(200, 20)); // new HealthbarRenderer(healthActor); }
public override void OnGameLoad(GameSpecification specification, MachinaRuntime runtime) { SceneLayers.BackgroundColor = Color.Maroon; var scene = SceneLayers.AddNewScene(); var rootActor = scene.AddActor("Main"); var errorText = this.exception.Message + "\n\n" + this.exception.StackTrace; var filePath = $"{Path.Join(MachinaClient.FileSystem.AppDataPath, $"crashdump-{DateTime.Now.ToFileTime()}.txt")}"; MachinaClient.FileSystem.WriteStringToAppData(errorText, filePath, true); var titleText = "Game Crashed, sorry about that :("; var contactInfoText = $"You can also get this message in text form at:\n{filePath}\nReach out to @NotExplosive on Twitter so I can fix it"; new BoundingRect(rootActor, Point.Zero); new BoundingRectToViewportSize(rootActor); new LayoutGroup(rootActor, Orientation.Vertical) .AddHorizontallyStretchedElement("title", 64, titleActor => { new BoundedTextRenderer(titleActor, titleText, MachinaClient.DefaultStyle.uiElementFont); }) .AddHorizontallyStretchedElement("contact-info", 80, contactInfoActor => { new BoundedTextRenderer(contactInfoActor, contactInfoText, MachinaClient.DefaultStyle.uiElementFont, Color.White, Alignment.TopLeft, Overflow.Ignore); }) .AddBothStretchedElement("content", contentActor => { new BoundedTextRenderer(contentActor, errorText, MachinaClient.DefaultStyle.uiElementFont); }); }
public void test_hoverables_in_a_single_scene() { var sceneLayers = new SceneLayers(new GameViewport(new Point(800, 600), ResizeBehavior.FreeAspectRatio)); var scene = sceneLayers.AddNewScene(); var mousePoint = new Point(200, 200); var mouseState = new MouseState(mousePoint.X, mousePoint.Y, 0, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released); var unreachedHoverable = BuildHoverable(scene, Point.Zero, "Hoverable that is too far to be hovered", new Depth(5)); var onPointHoverable = BuildHoverable(scene, mousePoint, "Hoverable that is exactly were the mouse is", new Depth(5)); var behindHoverable = BuildHoverable(scene, mousePoint, "Hoverable that is exactly were the mouse is, but farther back", new Depth(6)); // Need to update to push created interables into main iterable list scene.Update(0f); sceneLayers.Update(0, Matrix.Identity, new InputFrameState(KeyboardFrameState.Empty, new MouseFrameState(MouseButtonList.None, MouseButtonList.None, mousePoint, Vector2.Zero, 0))); Assert.Equal(new Depth(5), scene.hitTester.Candidate.depth); Assert.False(unreachedHoverable.IsHovered); Assert.False(unreachedHoverable.IsSoftHovered); Assert.False(behindHoverable.IsHovered); Assert.True(behindHoverable.IsSoftHovered); Assert.True(onPointHoverable.IsHovered); Assert.True(onPointHoverable.IsSoftHovered); }
public static LoggerComponent BuildOutputConsole(SceneLayers sceneLayers) { var consoleFont = MachinaClient.Assets.GetSpriteFont("DefaultFont"); var debugActor = sceneLayers.DebugScene.AddActor("DebugActor", depthAsInt: 100); new EnableDebugOnHotkey(debugActor, new KeyCombination(Keys.OemTilde, new ModifierKeys(true, false, true))); return(new LoggerComponent(debugActor, new ConsoleOverlay(debugActor, consoleFont))); }
public FrameStepRenderer(Actor actor, IFrameStep frameStep, SceneLayers sceneLayers, InvokableDebugTool tool) : base(actor) { tool.onToolToggle += OnToggle; this.frameStep = frameStep; this.sceneLayers = sceneLayers; this.actor.transform.Position = new Vector2(-64, 32); }
public void scaled_position_assignment() { var gameCanvas = new GameViewport(new Point(800, 600), ResizeBehavior.KeepAspectRatio); var sceneLayers = new SceneLayers(gameCanvas); var scene = sceneLayers.AddNewScene(); scene.camera.Zoom = 2.6f; scene.camera.ScaledPosition = new Point(scene.camera.ScaledPosition.X, 237); scene.camera.ScaledPosition.Y.Should().Be(237); }
public override void OnGameLoad(GameSpecification specification, MachinaRuntime runtime) { var introScene = SceneLayers.AddNewScene(); var textActor = introScene.AddActor("text"); new BoundingRect(textActor, 20, 20); new BoundingRectToViewportSize(textActor); new BoundedTextRenderer(textActor, "", MachinaClient.Assets.GetSpriteFont("LogoFont"), Color.White, Alignment.Center); new IntroTextAnimation(textActor); new CallbackOnDestroy(textActor, onEnd); }
public static void CreateFramestep(SceneLayers sceneLayers) { var frameStepActor = sceneLayers.DebugScene.AddActor("FrameStepActor"); var tool = new InvokableDebugTool(frameStepActor, new KeyCombination(Keys.Space, new ModifierKeys(true, false, false))); new FrameStepRenderer(frameStepActor, MachinaClient.GlobalFrameStep, sceneLayers, tool); new BoundingRect(frameStepActor, new Point(64, 64)); new Hoverable(frameStepActor); new Draggable(frameStepActor); new MoveOnDrag(frameStepActor); }
public void Should_Add_VisualNode() { var parent = new VisualNode(new TestRoot(), null); var child = new VisualNode(Mock.Of <IVisual>(), null); var layers = new SceneLayers(parent.Visual); var target = new DeferredDrawingContextImpl(null, layers); target.BeginUpdate(parent); target.BeginUpdate(child); Assert.Equal(1, parent.Children.Count); Assert.Same(child, parent.Children[0]); }
public SceneRenderer(Actor actor) : base(actor) { this.canvas = RequireComponent <BoundedCanvas>(); this.boundingRect = RequireComponent <BoundingRect>(); this.hoverable = RequireComponent <Hoverable>(); SceneLayers = new SceneLayers(this, Runtime); // SceneLayers should be provided as a constructor arg this.canvas.DrawAdditionalContent += DrawInnerScene; this.hoverable.OnHoverEnd += ClearHitTesters; this.PrimaryScene = SceneLayers.AddNewScene(); this.shouldAllowKeyboardEvents = () => false; this.bypassHoverConstraint = () => false; }
public void PrepareLoadingScreen(GameCartridge gameCartridge, MachinaRuntime runtime, AssetLibrary assets, WindowInterface machinaWindow, Action <GameCartridge> onFinished) { var loader = assets.GetStaticAssetLoadTree(); LoadDefaultStyle(loader, assets, runtime.Painter); gameCartridge.PrepareDynamicAssets(loader, runtime); var loadingScreen = new LoadingScreen(loader); var introScene = SceneLayers.AddNewScene(); var loaderActor = introScene.AddActor("Loader"); var adHoc = new AdHoc(loaderActor); adHoc.onPreDraw += (spriteBatch) => { if (!loadingScreen.IsDoneUpdateLoading()) { // Waiting for this to complete before draw loading } else if (!loadingScreen.IsDoneDrawLoading()) { loadingScreen.IncrementDrawLoopLoad(assets, spriteBatch); } }; adHoc.onDraw += (spriteBatch) => { loadingScreen.Draw(spriteBatch, machinaWindow.CurrentWindowSize); }; adHoc.onUpdate += (dt) => { if (!loadingScreen.IsDoneUpdateLoading()) { var increment = 3; for (var i = 0; i < increment; i++) { loadingScreen.Update(dt / increment); } } if (loadingScreen.IsDoneDrawLoading() && loadingScreen.IsDoneUpdateLoading()) { onFinished(gameCartridge); } }; }
public void Should_Update_DirtyRects() { var node = new VisualNode(new TestRoot(), null); var operation = new RectangleNode(Matrix.Identity, Brushes.Red, null, new Rect(0, 0, 100, 100), 0); var layers = new SceneLayers(node.Visual); var target = new DeferredDrawingContextImpl(null, layers); node.LayerRoot = node.Visual; using (target.BeginUpdate(node)) { target.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100)); } Assert.Equal(new Rect(0, 0, 100, 100), layers.Single().Dirty.Single()); }
public void Should_Add_DrawOperations() { var node = new VisualNode(new TestRoot(), null); var layers = new SceneLayers(node.Visual); var target = new DeferredDrawingContextImpl(null, layers); node.LayerRoot = node.Visual; using (target.BeginUpdate(node)) { target.DrawRectangle(Brushes.Red, new Pen(Brushes.Green, 1), new Rect(0, 0, 100, 100)); } Assert.Equal(1, node.DrawOperations.Count); Assert.IsType <RectangleNode>(node.DrawOperations[0].Item); }
public static DebugDock CreateDebugDock(SceneLayers sceneLayers) { var dockActor = sceneLayers.DebugScene.AddActor("Debug Dock"); new InvokableDebugTool(dockActor, new KeyCombination(Keys.Tab, new ModifierKeys(true, false, false))); new BoundingRect(dockActor, Point.Zero); new Hoverable(dockActor); new Draggable(dockActor); new MoveOnDrag(dockActor); new BoundingRectFill(dockActor, Color.Black.WithMultipliedOpacity(0.5f)); new LayoutGroup(dockActor, Orientation.Vertical); var dock = new DebugDock(dockActor); dock.AddApp(new App("Scene Graph", true, new WindowBuilder(new Point(300, 300)) .CanBeScrolled(900) .CanBeResized(new Point(300, 300), new Point(1920, 1080)) .Title("Scene Graph") .DestroyViaCloseButton() .OnLaunch(window => { var sceneGraphActor = window.PrimaryScene.AddActor("SceneGraphActor"); new BoundingRect(sceneGraphActor, Point.Zero); new SceneGraphData(sceneGraphActor, sceneLayers); new Hoverable(sceneGraphActor); new SceneGraphUI(sceneGraphActor, dock.windowManager, sceneLayers.DebugScene); new SceneGraphRenderer(sceneGraphActor, window.Scrollbar); }))); dock.AddApp(new App("Console", true, new WindowBuilder(new Point(600, 300)) .CanBeScrolled(900) .CanBeResized(new Point(300, 300), new Point(1920, 1080)) .DestroyViaCloseButton() .Title("Machina Console") .OnLaunch(window => { var consoleActor = window.PrimaryScene.AddActor("StaticConsole"); new WindowedConsoleRenderer(consoleActor, window.Scrollbar); }))); return(dock); }
public void Should_Not_Replace_Identical_DrawOperation() { var node = new VisualNode(new TestRoot(), null); var operation = RefCountable.Create(new RectangleNode(Matrix.Identity, Brushes.Red, null, new Rect(0, 0, 100, 100), 0)); var layers = new SceneLayers(node.Visual); var target = new DeferredDrawingContextImpl(null, layers); node.LayerRoot = node.Visual; node.AddDrawOperation(operation); using (target.BeginUpdate(node)) { target.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100)); } Assert.Equal(1, node.DrawOperations.Count); Assert.Same(operation.Item, node.DrawOperations.Single().Item); Assert.IsType <RectangleNode>(node.DrawOperations[0].Item); }
public void Should_Trim_DrawOperations() { var node = new VisualNode(new TestRoot(), null); node.LayerRoot = node.Visual; node.AddDrawOperation(new RectangleNode(Matrix.Identity, Brushes.Red, null, new Rect(0, 0, 10, 100), 0)); node.AddDrawOperation(new RectangleNode(Matrix.Identity, Brushes.Red, null, new Rect(0, 0, 20, 100), 0)); node.AddDrawOperation(new RectangleNode(Matrix.Identity, Brushes.Red, null, new Rect(0, 0, 30, 100), 0)); node.AddDrawOperation(new RectangleNode(Matrix.Identity, Brushes.Red, null, new Rect(0, 0, 40, 100), 0)); var layers = new SceneLayers(node.Visual); var target = new DeferredDrawingContextImpl(null, layers); using (target.BeginUpdate(node)) { target.FillRectangle(Brushes.Green, new Rect(0, 0, 10, 100)); target.FillRectangle(Brushes.Blue, new Rect(0, 0, 20, 100)); } Assert.Equal(2, node.DrawOperations.Count); }
public void Layers_Should_Be_Ordered() { Border border; Decorator decorator; var root = new TestRoot { Child = border = new Border { Child = decorator = new Decorator(), } }; var target = new SceneLayers(root); target.Add(root); target.Add(decorator); target.Add(border); var result = target.Select(x => x.LayerRoot).ToArray(); Assert.Equal(new IVisual[] { root, border, decorator }, result); }
public void mouse_position_transform_integration() { var gameCanvas = new GameViewport(new Point(800, 600), ResizeBehavior.KeepAspectRatio); var sceneLayers = new SceneLayers(gameCanvas); var scene = sceneLayers.AddNewScene(); scene.camera.ScaledPosition = new Point(120, 240); scene.camera.Zoom = 2.6f; var savedPosition = Vector2.Zero; var savedPositionDelta = Vector2.Zero; var savedRawDelta = Vector2.Zero; new MouseHarnessComponent(scene.AddActor("Mouse Harness"), (currentPosition, positionDelta, rawDelta) => { savedPosition = currentPosition; savedPositionDelta = positionDelta; savedRawDelta = rawDelta; }); // Resize to a huge resolution that's a different aspect ratio so we can get a worst-case transform scenario gameCanvas.SetWindowSize(new Point(1920, 1080)); var prevPos = new Point(200, 200); var newPos = new Point(220, 250); var mouseDelta = (newPos - prevPos).ToVector2(); sceneLayers.Update(0, Matrix.Identity, new InputFrameState(KeyboardFrameState.Empty, new MouseFrameState(MouseButtonList.None, MouseButtonList.None, new Point(200, 200), Vector2.Zero, 0))); sceneLayers.Update(0, Matrix.Identity, new InputFrameState(KeyboardFrameState.Empty, new MouseFrameState(MouseButtonList.None, MouseButtonList.None, new Point(220, 250), mouseDelta, 0))); Assert.Equal(new Point(115, 292), savedPosition.ToPoint()); // Mouse Position, this used to be (361, 478), but after I made the zoom/pan change it changed. I think that's on purpose Assert.Equal(new Vector2(4.2735047f, 10.683762f), savedPositionDelta); // Mouse Position Delta Assert.Equal(new Vector2(20, 50), savedRawDelta); // Mouse raw delta }
public void test_hoverables_across_multiple_scenes() { var sceneLayers = new SceneLayers(new GameViewport(new Point(800, 600), ResizeBehavior.FreeAspectRatio)); var lowerScene = sceneLayers.AddNewScene(); var upperScene = sceneLayers.AddNewScene(); var mousePoint = new Point(200, 200); var mouseState = new MouseState(mousePoint.X, mousePoint.Y, 0, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released); var onPointHoverable = BuildHoverable(upperScene, mousePoint, "Hoverable in upper scene", new Depth(5)); var behindHoverable = BuildHoverable(lowerScene, mousePoint, "Hoverable in lower scene but closer depth", new Depth(1)); // Push created iterables sceneLayers.UpdateWithNoInput(0f); sceneLayers.Update(0, new InputFrameState(KeyboardFrameState.Empty, new MouseFrameState(MouseButtonList.None, MouseButtonList.None, mousePoint, Vector2.Zero, 0))); Assert.True(onPointHoverable.IsHovered); Assert.False(behindHoverable.IsHovered); Assert.True(behindHoverable.IsSoftHovered); }
protected override void OnGameLoad() { MachinaGame.Fullscreen = true; var bgScene = SceneLayers.AddNewScene(); var bgScene2 = SceneLayers.AddNewScene(); var bgScene3 = SceneLayers.AddNewScene(); var gameScene = SceneLayers.AddNewScene(); var uiScene = SceneLayers.AddNewScene(); // SceneLayers.BackgroundColor = Color.Black; var bgActor = bgScene.AddActor("Background"); new BackgroundRenderer(bgActor, gameScene.camera, 0.6f); var bgActor2 = bgScene2.AddActor("Background"); new BackgroundRenderer(bgActor2, gameScene.camera, 1f); void StartGame() { var harness = gameScene.AddActor("Harness", new Vector2(gameScene.camera.ViewportCenter.X, -256)); var levelIndex = 0; var levelTransition = new LevelTransition(harness, levelIndex); var player = new Player(harness); new BubbleSpawner(harness, new MinMax <int>(3, 7)); new Harness(harness); var eye = harness.transform.AddActorAsChild("Eye"); var eyeRenderer = new EyeRenderer(eye, player, levelTransition); var targetReticalActor = gameScene.AddActor("Redical"); targetReticalActor.transform.Depth -= 20; new TargetRedical(targetReticalActor, player); { var groupActor = uiScene.AddActor("UI Parent Group"); new BoundingRect(groupActor, uiScene.camera.ViewportWidth, uiScene.camera.ViewportHeight); var grp = new LayoutGroup(groupActor, Orientation.Vertical); grp.PixelSpacer(32, (int)(uiScene.camera.ViewportHeight * 9f / 12f)); grp.AddBothStretchedElement("TextGroupParent", act => { var textGroup = new LayoutGroup(act, Orientation.Horizontal); textGroup.HorizontallyStretchedSpacer(); textGroup.AddVerticallyStretchedElement("Text", 900, act => { new BoundedTextRenderer(act, "", MachinaGame.Assets.GetSpriteFont("Roboto"), Color.White, HorizontalAlignment.Left, VerticalAlignment.Top, Overflow.Ignore).EnableDropShadow(Color.Black); new TextCrawlRenderer(act, levelTransition); }); textGroup.HorizontallyStretchedSpacer(); }); grp.PixelSpacer(32, 32); } } var world = gameScene.AddActor("World"); new WorldStuff(world); var menu = gameScene.AddActor("Main Menu"); new BoundingRect(menu, gameScene.camera.ViewportWidth, gameScene.camera.ViewportHeight); var menuLayout = new LayoutGroup(menu, Orientation.Horizontal); menuLayout.PixelSpacer(400); menuLayout.AddBothStretchedElement("Menu Inner", innerGroupActor => { var innerGroup = new LayoutGroup(innerGroupActor, Orientation.Vertical); innerGroup.PixelSpacer(250); var titleActGroup = innerGroup.AddHorizontallyStretchedElement("Title", 100, titleAct => { new BoundedTextRenderer(titleAct, "Oculus Leviathan", MachinaGame.Assets.GetSpriteFont("Roboto-Big")); }); innerGroup.AddHorizontallyStretchedElement("Subtitle", 64, subtitleAct => { // This was written hours before the deadline, it's spaghetti new BoundedTextRenderer(subtitleAct, "By NotExplosive\n\nThis game is played entirely with the mouse\nPress F4 to toggle fullscreen\n\nMade for Ludum Dare 48 in 72 hours\nHOLD Left Mouse Button to begin", MachinaGame.Assets.GetSpriteFont("Roboto")); float mouseHeldTimer = 0; var mouseHeld = false; var totalTimer = 0f; var thresholdMet = false; var hoc = new AdHoc(subtitleAct); hoc.onMouseButton += (MouseButton button, Vector2 pos, ButtonState state) => { mouseHeld = button == MouseButton.Left && state == ButtonState.Pressed; }; hoc.onUpdate += (float dt) => { if (!thresholdMet) { if (mouseHeld) { mouseHeldTimer += dt; } else { if (mouseHeldTimer > 0) { mouseHeldTimer -= dt; } } gameScene.camera.Position = new Vector2(0, MathF.Sin(totalTimer) * 32); if (mouseHeldTimer > 1f) { subtitleAct.RemoveComponent <BoundedTextRenderer>(); titleActGroup.actor.Destroy(); thresholdMet = true; } } else { // if thresholdMet: mouseHeldTimer -= dt; if (mouseHeldTimer < 0) { menu.Destroy(); StartGame(); } } if (mouseHeldTimer > 0) { gameScene.camera.Zoom = 1 + EaseFuncs.CubicEaseOut(mouseHeldTimer) / 3; } totalTimer += dt; }; }); }); menuLayout.PixelSpacer(100); CommandLineArgs.RegisterFlagArg("edit", () => { var curveBrush = gameScene.AddActor("CurveBrush", gameScene.camera.ViewportCenter); new CurveEditor(curveBrush); }); if (DebugLevel >= DebugLevel.Passive) { var debug = gameScene.AddActor("Debug"); new PanAndZoomCamera(debug, Keys.LeftControl); } }
public static void CreateFramerateCounter(SceneLayers sceneLayers) { var framerateCounterActor = sceneLayers.DebugScene.AddActor("FramerateCounter"); new FrameRateCounter(framerateCounterActor); }
public SceneGraphData(Actor actor, SceneLayers sceneLayers) : base(actor) { this.sceneLayers = sceneLayers; }