Update test game to showcase camera system.

This commit is contained in:
2023-09-25 18:54:17 +02:00
parent 8aab1132b6
commit 092d01dcae
4 changed files with 55 additions and 13 deletions

View File

@@ -25,6 +25,14 @@ namespace DaggerFramework
return new Vector2(x, y); return new Vector2(x, y);
} }
public static Vector2 RandomVector2(Vector2 min, Vector2 max)
{
var x = _random.NextDouble(min.X, max.X);
var y = _random.NextDouble(min.Y, max.Y);
return new Vector2((float)x, (float)y);
}
public static float EaseOutBack(float x) public static float EaseOutBack(float x)
{ {
var c1 = 1.70158f; var c1 = 1.70158f;
@@ -43,5 +51,7 @@ namespace DaggerFramework
? 1 ? 1
: (float)Math.Pow(2, -10 * x) * (float)Math.Sin((x * 10 - 0.75f) * c4) + 1; : (float)Math.Pow(2, -10 * x) * (float)Math.Sin((x * 10 - 0.75f) * c4) + 1;
} }
private static LehmerRandom _random = new();
} }
} }

View File

@@ -62,6 +62,8 @@ public class TestGame : Game
_scene.AddLayer("World", _worldLayer); _scene.AddLayer("World", _worldLayer);
_scene.AddLayer("UI", _uiLayer); _scene.AddLayer("UI", _uiLayer);
_worldLayer.AddEntity(new World());
_worldLayer.AddEntity(new TestPlayer()); _worldLayer.AddEntity(new TestPlayer());
_scene.Start(); _scene.Start();

View File

@@ -10,29 +10,29 @@ public class TestPlayer : RectangleShape2d
Color = Color.Cyan; Color = Color.Cyan;
_logger.Echo("OnStart"); _logger.Echo("OnStart");
// _camera = new Camera2d() _camera = new Camera2d()
// { {
// Current = true, Current = true,
// }; };
// Layer.AddEntity(_camera); Layer.AddEntity(_camera);
} }
protected override void OnUpdate(double dt) protected override void OnUpdate(double dt)
{ {
base.OnUpdate(dt); base.OnUpdate(dt);
// var sprinting = Input.IsActionDown("sprint"); var sprinting = Input.IsActionDown("sprint");
// _speed = sprinting ? 400f : 200f; _speed = sprinting ? 400f : 200f;
// var velocity = Input.GetInputDirection("left", "right", "up", "down") * _speed; var velocity = Input.GetInputDirection("left", "right", "up", "down") * _speed;
// Position += velocity * (float)dt; Position += velocity * (float)dt;
// _camera.Position = MathUtils.LerpVector2(_camera.Position, Position, dt * 5f); _camera.Position = MathUtils.LerpVector2(_camera.Position, Position, dt * 5f);
var mousePos = Input.GetMousePosition(); // var mousePos = Input.GetMousePosition();
Position = MathUtils.LerpVector2(Position, mousePos, dt * 5f); // Position = MathUtils.LerpVector2(Position, mousePos, dt * 5f);
Rotation += (float)dt * 100f; // Rotation += (float)dt * 100f;
} }
private Logger _logger = new(nameof(TestPlayer)); private Logger _logger = new(nameof(TestPlayer));

30
TestGame/World.cs Normal file
View File

@@ -0,0 +1,30 @@
using System.Numerics;
using DaggerFramework;
using DaggerFramework.Rendering;
using DaggerFramework.SceneGraph;
public class World : Drawable2d
{
protected override void OnStart()
{
base.OnStart();
_randomPositions = new Vector2[_rectangleAmount];
for (int i = 0; i < _rectangleAmount - 1; i++)
{
_randomPositions[i] = MathUtils.RandomVector2(Position, Vector2.One * 2048f);
}
}
public override void OnDraw(Renderer renderer)
{
for (int i = 0; i < _rectangleAmount; i++)
{
renderer.SetTransform(_randomPositions[i], PivotOffset, 0);
renderer.DrawRectangle(Vector2.One * 16f, _rectangleColor);
}
}
private Color _rectangleColor = new Color(0.25f, 0.25f, 0.25f, 1.0f);
private int _rectangleAmount = 6000;
private Vector2[] _randomPositions;
}