diff --git a/Config.cs b/Config.cs deleted file mode 100644 index 9e05381..0000000 --- a/Config.cs +++ /dev/null @@ -1,8 +0,0 @@ -// I hereby waive this project under the public domain - see UNLICENSE for details. -namespace PlayBark; - -internal class Config -{ - public int Width { get; set; } - public int Height { get; set; } -} \ No newline at end of file diff --git a/GlobalUsings.cs b/GlobalUsings.cs index 22016e3..2674d67 100644 --- a/GlobalUsings.cs +++ b/GlobalUsings.cs @@ -1,7 +1,2 @@ -global using System.Diagnostics; global using System.Numerics; -global using Tomlyn; -global using Tomlyn.Model; -global using static Raylib_cs.Raylib; global using Raylib_cs; -global using PlayBark; \ No newline at end of file diff --git a/PlayBark.csproj b/PlayBark.csproj index 8ae31a4..c99d292 100644 --- a/PlayBark.csproj +++ b/PlayBark.csproj @@ -9,7 +9,6 @@ - diff --git a/Program.cs b/Program.cs index b87b1e4..1ecd9e0 100644 --- a/Program.cs +++ b/Program.cs @@ -1,62 +1,73 @@ // I hereby waive this project under the public domain - see UNLICENSE for details. -/// -/// Retrieves configuration settings from a TOML file if it exists; otherwise, returns a default configuration. -/// -/// The name of the configuration file (defaults to "config.toml"). -/// A Config object populated with values from the file, or a default Config instance if the file is not found. -static Config ReadConfig(string file) -{ - var cfgPath = Path.Combine(Tracer.AppDirectory, file); +// Initialization +//-------------------------------------------------------------------------------------- +const int screenWidth = 600; +const int screenHeight = 450; +Raylib.InitWindow(screenWidth, screenHeight, "PlayBark"); - if (!File.Exists(cfgPath)) +// Based on WavingCube example: +// https://github.com/raylib-cs/raylib-cs/blob/master/Examples/Models/WavingCubes.cs + +// Initialize the camera +var camera = new Camera3D(); +camera.Position = new Vector3(30.0f, 20.0f, 30.0f); +camera.Target = new Vector3(0.0f, 0.0f, 0.0f); +camera.Up = new Vector3(0.0f, 1.0f, 0.0f); +camera.FovY = 70.0f; +camera.Projection = CameraProjection.Perspective; + +const int numBlocks = 15; + +Raylib.SetTargetFPS(60); + +// Main game loop +while (!Raylib.WindowShouldClose()) +{ + var time = Raylib.GetTime(); + var scale = (2.0f + (float)Math.Sin(time)) * 0.7f; + + var cameraTime = time * 0.3; + + camera.Position.X = (float)Math.Cos(cameraTime) * 40.0f; + camera.Position.Z = (float)Math.Cos(cameraTime) * 40.0f; + + Raylib.BeginDrawing(); + Raylib.ClearBackground(Color.RayWhite); + + Raylib.BeginMode3D(camera); + + Raylib.DrawGrid(10, 5.0f); + + for (int x = 0; x < numBlocks; x++) { - Tracer.WriteLine("Config file not found. Switching to defaults."); - var config = new Config + for (int y = 0; y < numBlocks; y++) { - Width = 600, - Height = 450 - }; + for (int z = 0; z < numBlocks; z++) + { + var blockScale = (x + y + z) / 30.0f; + var scatter = (float)Math.Sin(blockScale * 20.0f + (float)(time * 4.0f)); - return config; + var cubePos = new Vector3( + (float)(x - numBlocks / 2) * (scale * 3.0f) + scatter, + (float)(x - numBlocks / 2) * (scale * 2.0f) + scatter, + (float)(x - numBlocks / 2) * (scale * 3.0f) + scatter + ); + + var cubeColor = Raylib.ColorFromHSV((float)(((x + y + z) * 18) % 360), 0.75f, 0.9f); + + var cubeSize = (2.4f - scale) * blockScale; + + Raylib.DrawCube(cubePos, cubeSize, cubeSize, cubeSize, cubeColor); + } + } } - Tracer.WriteLine($"Discovered config file: {cfgPath}"); - var toml = File.ReadAllText(cfgPath); - var model = Toml.ToModel(toml); + Raylib.EndMode3D(); - return model; + Raylib.DrawFPS(10, 10); + + Raylib.EndDrawing(); } -void Init(int screenWidth, int screenHeight, int fps) -{ - var pos = new Vector3(0.2f, 0.4f, 0.2f); - var target = new Vector3(0.0f, 0.0f, 0.0f); - var up = new Vector3(0.0f, 1.0f, 0.0f); - - InitWindow(screenWidth, screenHeight, $"PlayBark"); - World3D.InitCamera(pos, target, up, CameraProjection.Perspective); - SetTargetFPS(fps); -} - -int GameLoop() -{ - var config = ReadConfig("config.toml"); - Init(config.Width, config.Height, 60); - - while (!WindowShouldClose()) - { - BeginDrawing(); - ClearBackground(Color.White); - - DrawFPS(10, 10); - - EndDrawing(); - } - - CloseWindow(); - - return 0; -} - -GameLoop(); +Raylib.CloseWindow(); diff --git a/Tracer.cs b/Tracer.cs deleted file mode 100644 index 78116e7..0000000 --- a/Tracer.cs +++ /dev/null @@ -1,66 +0,0 @@ -// I hereby waive this project under the public domain - see UNLICENSE for details. -namespace PlayBark; - -/// -/// Provides debug-only console output methods. -/// These methods are only executed when the application is compiled in DEBUG mode. -/// -internal static class Tracer -{ - /// - /// Writes a line of text to the console, but only when in DEBUG mode. - /// - /// The text to write to the console. - [Conditional("DEBUG")] - internal static void WriteLine(string content) => - Console.WriteLine(content); - - /// - /// Writes text to the console without a newline, but only when in DEBUG mode. - /// - /// The text to write to the console. - [Conditional("DEBUG")] - internal static void Write(string content) => - Console.Write(content); - - /// - /// Writes multiple lines of text to the console, but only when in DEBUG mode. - /// - /// A collection of text lines to write to the console. - [Conditional("DEBUG")] - internal static void WriteLine(IEnumerable contents) - { - foreach (var content in contents) - { - Console.WriteLine(content); - } - } - - /// - /// Writes multiple text entries to the console without newlines, but only when in DEBUG mode. - /// - /// A collection of text entries to write to the console. - [Conditional("DEBUG")] - internal static void Write(IEnumerable contents) - { - foreach (var content in contents) - { - Console.Write(content); - } - } - - /// - /// Gets the current working directory in DEBUG mode or the application's base directory in release mode. - /// - internal static string AppDirectory - { - get - { -#if DEBUG - return Directory.GetCurrentDirectory(); -#else - return AppDomain.CurrentDomain.BaseDirectory; -#endif - } - } -} diff --git a/World3D.cs b/World3D.cs deleted file mode 100644 index 7932cd9..0000000 --- a/World3D.cs +++ /dev/null @@ -1,17 +0,0 @@ -// I hereby waive this project under the public domain - see UNLICENSE for details. -namespace PlayBark; - -internal static class World3D -{ - public static Camera3D InitCamera(Vector3 pos, Vector3 target, Vector3 up, CameraProjection projection) - { - Camera3D camera = new(); - camera.Position = pos; - camera.Target = target; - camera.Up = up; - camera.FovY = 45.0f; - camera.Projection = projection; - - return camera; - } -} \ No newline at end of file diff --git a/resources/cubicmap.png b/resources/cubicmap.png deleted file mode 100644 index 392dbf2..0000000 Binary files a/resources/cubicmap.png and /dev/null differ