diff options
Diffstat (limited to 'client/Root.cs')
| -rw-r--r-- | client/Root.cs | 87 |
1 files changed, 0 insertions, 87 deletions
diff --git a/client/Root.cs b/client/Root.cs deleted file mode 100644 index dfbf0da..0000000 --- a/client/Root.cs +++ /dev/null @@ -1,87 +0,0 @@ -using Godot; -using System; -using Djup.Native; - -public partial class Root : Node2D -{ - private IntPtr native_world; - private int[] balls = new int[100]; - private Random rng = new(); - private const double Tps = 1d/60d; - - // Called when the node enters the scene tree for the first time. - public unsafe override void _Ready() - { - RenderingServer.SetDefaultClearColor(Colors.LightGray); - LibDjup.log_set_output((level, source, line, msg) => { - string level_name = level switch - { - LogLevel.Trace => "trace", - LogLevel.Debug => "debug", - LogLevel.Info => "info", - LogLevel.Warn => "warn", - LogLevel.Error => "error", - LogLevel.Fatal => "fatal" - }; - GD.Print($"libdjup {source}:{line} {level_name.PadLeft(5, ' ')}: {msg}"); - }); - - native_world = LibDjup.world_create(); - for (int i = 0; i < balls.Length; i++) - { - int id = LibDjup.world_create_entity(native_world, EntityKind.Ball); - if (id < 0) - { - throw new Exception("Failed to create entity"); - } - balls[i] = id; - Entity *ent; - var pos = new Vec2(5f * rng.Next(10), 5f * rng.Next(20)); - var vel = LibDjup.vec2_mul(LibDjup.vec2_normal(new Vec2(50f + 5f * rng.Next(10), 50f)), 25.0f); - GD.Print(vel, " --> ", LibDjup.vec2_length(vel)); - ent = LibDjup.world_find_entity(native_world, balls[i]); - ent->ball.Position = pos; - ent->ball.Velocity = vel; - } - } - - public override void _ExitTree() - { - LibDjup.world_free(native_world); - } - - private void DrawBall(Ball ball) - { - //Color color = rng.Next(5) switch - //{ - //0 => Colors.Black, - //1 => Colors.Blue, - //2 => Colors.Red, - //3 => Colors.Green, - //4 => Colors.Pink - //}; - Color color = Colors.Blue; - this.DrawCircle(new Vector2(ball.Position.X, ball.Position.Y), 5f, color, antialiased: true); - } - - public unsafe override void _Draw() - { - for (int i = 0; i < balls.Length; i++) - { - DrawBall(LibDjup.world_find_entity(native_world, balls[i])->ball); - } - } - - public override void _Process(double delta) - { - this.QueueRedraw(); - } - - public override void _PhysicsProcess(double delta) - { - if (LibDjup.world_tick(native_world, Tps) != 0) - { - GD.Print("world_tick failed"); - } - } -} |
