initial commit
This commit is contained in:
36
Shared/.config/dotnet-tools.json
Normal file
36
Shared/.config/dotnet-tools.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-mgcb": {
|
||||
"version": "3.8.2.1105",
|
||||
"commands": [
|
||||
"mgcb"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor": {
|
||||
"version": "3.8.2.1105",
|
||||
"commands": [
|
||||
"mgcb-editor"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-linux": {
|
||||
"version": "3.8.2.1105",
|
||||
"commands": [
|
||||
"mgcb-editor-linux"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-windows": {
|
||||
"version": "3.8.2.1105",
|
||||
"commands": [
|
||||
"mgcb-editor-windows"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-mac": {
|
||||
"version": "3.8.2.1105",
|
||||
"commands": [
|
||||
"mgcb-editor-mac"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
27
Shared/Behaviours/ExampleBehaviour.cs
Normal file
27
Shared/Behaviours/ExampleBehaviour.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
using Engine.Core;
|
||||
using Engine.Core.Debug;
|
||||
|
||||
namespace MyUniverse.Shared.Behaviours;
|
||||
|
||||
public class ExampleBehaviour : Behaviour, IFirstFrameUpdate, ILastFrameUpdate, IUpdate
|
||||
{
|
||||
private ILogger logger = null!;
|
||||
|
||||
public void FirstActiveFrame()
|
||||
{
|
||||
logger = Universe.FindRequiredBehaviour<ILogger>();
|
||||
|
||||
logger.Log(this, "First Frame");
|
||||
}
|
||||
|
||||
public void LastActiveFrame()
|
||||
{
|
||||
logger.Log(this, $"Last Frame");
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
logger.Log(this, "Frame");
|
||||
}
|
||||
}
|
5
Shared/Behaviours/IRotator.cs
Normal file
5
Shared/Behaviours/IRotator.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using Engine.Core;
|
||||
|
||||
namespace MyUniverse.Shared.Behaviours;
|
||||
|
||||
public interface IRotator : IBehaviour;
|
13
Shared/Behaviours/LinearRotator.cs
Normal file
13
Shared/Behaviours/LinearRotator.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Engine.Core;
|
||||
|
||||
namespace MyUniverse.Shared.Behaviours;
|
||||
|
||||
public class LinearRotator : Behaviour2D, IRotator, IUpdate
|
||||
{
|
||||
private float speed = 20f;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
Transform.Rotation += Universe.Time.DeltaTime * speed;
|
||||
}
|
||||
}
|
31
Shared/Behaviours/RotatorToggler.cs
Normal file
31
Shared/Behaviours/RotatorToggler.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using Engine.Core;
|
||||
using Engine.Integration.MonoGame;
|
||||
using Engine.Systems.Input;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace MyUniverse.Shared.Behaviours;
|
||||
|
||||
public class RotatorToggler : Behaviour2D, IFirstFrameUpdate, ILastFrameUpdate
|
||||
{
|
||||
private IRotator rotator = null!;
|
||||
private KeyboardInputs inputs = null!;
|
||||
|
||||
public void FirstActiveFrame()
|
||||
{
|
||||
rotator = BehaviourController.GetRequiredBehaviour<IRotator>();
|
||||
inputs = Universe.FindRequiredBehaviour<KeyboardInputs>();
|
||||
|
||||
inputs.RegisterOnPress(Keys.Space, ToggleRotator);
|
||||
}
|
||||
|
||||
private void ToggleRotator(IButtonInputs<Keys> sender, IButtonInputs<Keys>.ButtonCallbackArguments args)
|
||||
{
|
||||
rotator.StateEnable.Enabled = !rotator.StateEnable.Enabled;
|
||||
}
|
||||
|
||||
public void LastActiveFrame()
|
||||
{
|
||||
inputs.UnregisterOnPress(Keys.Space, ToggleRotator);
|
||||
}
|
||||
}
|
35
Shared/Behaviours/TweenRotator.cs
Normal file
35
Shared/Behaviours/TweenRotator.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Engine.Core;
|
||||
using Engine.Systems.Tween;
|
||||
|
||||
namespace MyUniverse.Shared.Behaviours;
|
||||
|
||||
public class TweenRotator : Behaviour2D, IRotator, IFirstFrameUpdate, ILastFrameUpdate
|
||||
{
|
||||
private float duration = 5f;
|
||||
private float angle = 180;
|
||||
private IEasing easeMethod = EaseInOutQuad.Instance;
|
||||
private ITweenManager tweenManager = null!;
|
||||
private ITween tween = null!;
|
||||
|
||||
public void FirstActiveFrame()
|
||||
{
|
||||
tweenManager = Universe.FindRequiredBehaviour<ITweenManager>();
|
||||
|
||||
TweenRotation();
|
||||
}
|
||||
|
||||
private void TweenRotation()
|
||||
{
|
||||
if (Transform.Rotation >= 360f)
|
||||
Transform.Rotation -= 360f;
|
||||
|
||||
tween = Transform.TweenRotation(tweenManager, duration, Transform.Rotation + angle)
|
||||
.Ease(easeMethod)
|
||||
.OnComplete(TweenRotation);
|
||||
}
|
||||
|
||||
public void LastActiveFrame()
|
||||
{
|
||||
tweenManager.CancelTween(tween);
|
||||
}
|
||||
}
|
15
Shared/Content/Content.mgcb
Normal file
15
Shared/Content/Content.mgcb
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#----------------------------- Global Properties ----------------------------#
|
||||
|
||||
/outputDir:bin/$(Platform)
|
||||
/intermediateDir:obj/$(Platform)
|
||||
/platform:DesktopGL
|
||||
/config:
|
||||
/profile:Reach
|
||||
/compress:False
|
||||
|
||||
#-------------------------------- References --------------------------------#
|
||||
|
||||
|
||||
#---------------------------------- Content ---------------------------------#
|
||||
|
17
Shared/Shared.csproj
Normal file
17
Shared/Shared.csproj
Normal file
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>MyUniverse.Shared</RootNamespace>
|
||||
<AssemblyName>MyUniverse.Shared</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.2.1105">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../Engine/Engine/Engine.csproj" />
|
||||
<ProjectReference Include="../Engine/Engine.Integration/Engine.Integration.MonoGame/Engine.Integration.MonoGame.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
61
Shared/UniverseSource.cs
Normal file
61
Shared/UniverseSource.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
using MyUniverse.Shared.Behaviours;
|
||||
|
||||
using Engine.Core;
|
||||
using Engine.Integration.MonoGame;
|
||||
using Engine.Systems.Tween;
|
||||
|
||||
namespace MyUniverse.Shared;
|
||||
|
||||
public static class UniverseSource
|
||||
{
|
||||
public static void ApplyCore(IUniverse universe)
|
||||
{
|
||||
universe.InstantiateUniverseObject().SetUniverseObject("Core Managers")
|
||||
.BehaviourController.AddBehaviour<UpdateManager>()
|
||||
.BehaviourController.AddBehaviour<CoroutineManager>()
|
||||
.BehaviourController.AddBehaviour<TweenManager>()
|
||||
.BehaviourController.AddBehaviour<TriangleBatcher>()
|
||||
.BehaviourController.AddBehaviour<SpriteBatcher>()
|
||||
.BehaviourController.AddBehaviour<UniverseEntranceManager>();
|
||||
|
||||
MonoGameCamera2D camera = universe.InstantiateUniverseObject().SetUniverseObject("Camera")
|
||||
.BehaviourController.AddBehaviour<Transform2D>()
|
||||
.BehaviourController.AddBehaviour<MonoGameCamera2D>();
|
||||
|
||||
camera.Zoom = 20f;
|
||||
}
|
||||
|
||||
public static void ApplyUniverse(IUniverse universe)
|
||||
{
|
||||
ApplyCore(universe);
|
||||
|
||||
IUniverseObject exampleObject = universe.InstantiateUniverseObject().SetUniverseObject("Example Object");
|
||||
ExampleBehaviour exampleBehaviour = exampleObject.BehaviourController.AddBehaviour<ExampleBehaviour>();
|
||||
|
||||
universe.InstantiateUniverseObject()
|
||||
.SetUniverseObject("Rotating Triangle")
|
||||
.BehaviourController.AddBehaviour<Transform2D>().SetTransform(position: new(10f, 6f), scale: Vector2D.One * 5)
|
||||
.BehaviourController.AddBehaviour<DrawableShape>(Shape2D.Triangle, new ColorRGB(0, 128, 128))
|
||||
.BehaviourController.AddBehaviour<LinearRotator>();
|
||||
|
||||
universe.InstantiateUniverseObject()
|
||||
.SetUniverseObject("Rotating Pentagon")
|
||||
.BehaviourController.AddBehaviour<Transform2D>().SetTransform(position: new(10f, -6f), scale: Vector2D.One * 5)
|
||||
.BehaviourController.AddBehaviour<DrawableShape>(Shape2D.Pentagon, new ColorRGB(128, 0, 128))
|
||||
.BehaviourController.AddBehaviour<TweenRotator>();
|
||||
universe.InstantiateUniverseObject()
|
||||
.SetUniverseObject("Rotating Triangle")
|
||||
.BehaviourController.AddBehaviour<Transform2D>().SetTransform(position: new(-10f, 6f), scale: Vector2D.One * 5)
|
||||
.BehaviourController.AddBehaviour<DrawableShape>(Shape2D.Triangle, new ColorRGB(0, 128, 128))
|
||||
.BehaviourController.AddBehaviour<LinearRotator>()
|
||||
.BehaviourController.AddBehaviour<RotatorToggler>();
|
||||
|
||||
universe.InstantiateUniverseObject()
|
||||
.SetUniverseObject("Rotating Pentagon")
|
||||
.BehaviourController.AddBehaviour<Transform2D>().SetTransform(position: new(-10f, -6f), scale: Vector2D.One * 5)
|
||||
.BehaviourController.AddBehaviour<DrawableShape>(Shape2D.Pentagon, new ColorRGB(128, 0, 128))
|
||||
.BehaviourController.AddBehaviour<TweenRotator>()
|
||||
.BehaviourController.AddBehaviour<RotatorToggler>();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user