Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Ion.Examples/Ion.Examples.RedBox/Ion.Examples.RedBox.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;DebugGenerators</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Ion\Ion\Ion.csproj" />
</ItemGroup>
</Project>
63 changes: 63 additions & 0 deletions Ion.Examples/Ion.Examples.RedBox/Program.cs
Original file line number Diff line number Diff line change
@@ -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<RedBoxSystem>();

var game = builder.Build();
game.UseIon()
.UseSystem<RedBoxSystem>();

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);
}
}
19 changes: 19 additions & 0 deletions Ion.Examples/Ion.Examples.RedBox/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Ion": "Debug"
}
},
"Ion": {
"Title": "RedBoxDemo",
"MaxFPS": 60,
"Debug": {
"TraceEnabled": true
},
"Window": {
"Width": 800,
"Height": 600
}
}
}
12 changes: 10 additions & 2 deletions Ion.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
Loading