diff --git a/Ion.Examples/Ion.Examples.RedBox/Ion.Examples.RedBox.csproj b/Ion.Examples/Ion.Examples.RedBox/Ion.Examples.RedBox.csproj new file mode 100644 index 0000000..1c6d8ce --- /dev/null +++ b/Ion.Examples/Ion.Examples.RedBox/Ion.Examples.RedBox.csproj @@ -0,0 +1,18 @@ + + + Exe + net8.0 + enable + enable + Debug;Release;DebugGenerators + AnyCPU + + + + Always + + + + + + diff --git a/Ion.Examples/Ion.Examples.RedBox/Program.cs b/Ion.Examples/Ion.Examples.RedBox/Program.cs new file mode 100644 index 0000000..5cb9a31 --- /dev/null +++ b/Ion.Examples/Ion.Examples.RedBox/Program.cs @@ -0,0 +1,63 @@ +using Microsoft.Extensions.DependencyInjection; +using Ion; +using Ion.Extensions.Graphics; +using System.Numerics; + +var builder = IonApplication.CreateBuilder(args); + +builder.Services.AddIon(builder.Configuration, graphics => +{ + graphics.Output = GraphicsOutput.Window; + graphics.ClearColor = Color.Black; +}); + +builder.Services.AddSingleton(); + +var game = builder.Build(); +game.UseIon() + .UseSystem(); + +game.Run(); + +public class RedBoxSystem +{ + private RectangleF _box; + private Vector2 _velocity; + private readonly IInputState _input; + private readonly IWindow _window; + private readonly ISpriteBatch _spriteBatch; + + public RedBoxSystem(IInputState input, IWindow window, ISpriteBatch spriteBatch) + { + _box = new RectangleF(100, 100, 50, 50); + _velocity = Vector2.Zero; + _input = input; + _window = window; + _spriteBatch = spriteBatch; + } + + [Update] + public void Update(GameTime dt, GameLoopDelegate next) + { + _velocity = Vector2.Zero; + + if (_input.Down(Key.Left)) _velocity.X = -200; + if (_input.Down(Key.Right)) _velocity.X = 200; + if (_input.Down(Key.Up)) _velocity.Y = -200; + if (_input.Down(Key.Down)) _velocity.Y = 200; + + _box.Location += _velocity * dt.Delta; + + _box.X = Math.Clamp(_box.X, 0, _window.Width - _box.Width); + _box.Y = Math.Clamp(_box.Y, 0, _window.Height - _box.Height); + + next(dt); + } + + [Render] + public void Render(GameTime dt, GameLoopDelegate next) + { + _spriteBatch.DrawRect(Color.Red, _box); + next(dt); + } +} diff --git a/Ion.Examples/Ion.Examples.RedBox/appsettings.json b/Ion.Examples/Ion.Examples.RedBox/appsettings.json new file mode 100644 index 0000000..2c78652 --- /dev/null +++ b/Ion.Examples/Ion.Examples.RedBox/appsettings.json @@ -0,0 +1,19 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "Ion": "Debug" + } + }, + "Ion": { + "Title": "RedBoxDemo", + "MaxFPS": 60, + "Debug": { + "TraceEnabled": true + }, + "Window": { + "Width": 800, + "Height": 600 + } + } +} diff --git a/Ion.sln b/Ion.sln index 70a1c34..7163272 100644 --- a/Ion.sln +++ b/Ion.sln @@ -1,4 +1,3 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 @@ -9,7 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .gitignore = .gitignore .versionize = .versionize coverage.runsettings = coverage.runsettings - Directory.Build.targets = Directory.Build.targets + Directory.Build.targets = Directory.Build.targets .config\dotnet-tools.json = .config\dotnet-tools.json LICENSE = LICENSE README.md = README.md @@ -76,6 +75,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Extensions.Scenes.Gener EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Examples.Breakout.ECS", "Ion.Examples\Ion.Examples.Breakout.ECS\Ion.Examples.Breakout.ECS.csproj", "{0E168B0B-AED8-4170-8022-169990B9848A}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Examples.RedBox", "Ion.Examples\Ion.Examples.RedBox\Ion.Examples.RedBox.csproj", "{0E168B0B-AED8-4170-8022-169990B9848B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -233,6 +234,12 @@ Global {0E168B0B-AED8-4170-8022-169990B9848A}.DebugGenerators|Any CPU.Build.0 = DebugGenerators|Any CPU {0E168B0B-AED8-4170-8022-169990B9848A}.Release|Any CPU.ActiveCfg = Release|Any CPU {0E168B0B-AED8-4170-8022-169990B9848A}.Release|Any CPU.Build.0 = Release|Any CPU + {0E168B0B-AED8-4170-8022-169990B9848B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E168B0B-AED8-4170-8022-169990B9848B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E168B0B-AED8-4170-8022-169990B9848B}.DebugGenerators|Any CPU.ActiveCfg = DebugGenerators|Any CPU + {0E168B0B-AED8-4170-8022-169990B9848B}.DebugGenerators|Any CPU.Build.0 = DebugGenerators|Any CPU + {0E168B0B-AED8-4170-8022-169990B9848B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E168B0B-AED8-4170-8022-169990B9848B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -264,6 +271,7 @@ Global {2488F296-352B-4FE6-8040-1E39DAD95C4F} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} {B3E523F8-E19C-47EF-B344-74B736AEF1FA} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} {0E168B0B-AED8-4170-8022-169990B9848A} = {8FBD5536-6567-4933-BD14-4A1575F4EE43} + {0E168B0B-AED8-4170-8022-169990B9848B} = {8FBD5536-6567-4933-BD14-4A1575F4EE43} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {CCF839E2-AF6A-4444-95F2-76F60225DC55}