mirror of
https://github.com/tonytins/playbark.git
synced 2025-05-31 16:56:26 -04:00
Compare commits
No commits in common. "b8cd12302e00f661d9d5a37a0a0393b630ce8603" and "ccfe5193c1171b481acd8f6649e83381de6f7e33" have entirely different histories.
b8cd12302e
...
ccfe5193c1
7 changed files with 62 additions and 148 deletions
|
@ -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; }
|
|
||||||
}
|
|
|
@ -1,7 +1,2 @@
|
||||||
global using System.Diagnostics;
|
|
||||||
global using System.Numerics;
|
global using System.Numerics;
|
||||||
global using Tomlyn;
|
|
||||||
global using Tomlyn.Model;
|
|
||||||
global using static Raylib_cs.Raylib;
|
|
||||||
global using Raylib_cs;
|
global using Raylib_cs;
|
||||||
global using PlayBark;
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Raylib-cs" Version="7.0.1" />
|
<PackageReference Include="Raylib-cs" Version="7.0.1" />
|
||||||
<PackageReference Include="Tomlyn" Version="0.19.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
113
Program.cs
113
Program.cs
|
@ -1,62 +1,73 @@
|
||||||
// I hereby waive this project under the public domain - see UNLICENSE for details.
|
// I hereby waive this project under the public domain - see UNLICENSE for details.
|
||||||
|
|
||||||
/// <summary>
|
// Initialization
|
||||||
/// Retrieves configuration settings from a TOML file if it exists; otherwise, returns a default configuration.
|
//--------------------------------------------------------------------------------------
|
||||||
/// </summary>
|
const int screenWidth = 600;
|
||||||
/// <param name="file">The name of the configuration file (defaults to "config.toml").</param>
|
const int screenHeight = 450;
|
||||||
/// <returns>A Config object populated with values from the file, or a default Config instance if the file is not found.</returns>
|
Raylib.InitWindow(screenWidth, screenHeight, "PlayBark");
|
||||||
static Config ReadConfig(string file)
|
|
||||||
{
|
|
||||||
var cfgPath = Path.Combine(Tracer.AppDirectory, file);
|
|
||||||
|
|
||||||
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.");
|
for (int y = 0; y < numBlocks; y++)
|
||||||
var config = new Config
|
|
||||||
{
|
{
|
||||||
Width = 600,
|
for (int z = 0; z < numBlocks; z++)
|
||||||
Height = 450
|
{
|
||||||
};
|
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}");
|
Raylib.EndMode3D();
|
||||||
var toml = File.ReadAllText(cfgPath);
|
|
||||||
var model = Toml.ToModel<Config>(toml);
|
|
||||||
|
|
||||||
return model;
|
Raylib.DrawFPS(10, 10);
|
||||||
|
|
||||||
|
Raylib.EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init(int screenWidth, int screenHeight, int fps)
|
Raylib.CloseWindow();
|
||||||
{
|
|
||||||
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();
|
|
||||||
|
|
66
Tracer.cs
66
Tracer.cs
|
@ -1,66 +0,0 @@
|
||||||
// I hereby waive this project under the public domain - see UNLICENSE for details.
|
|
||||||
namespace PlayBark;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides debug-only console output methods.
|
|
||||||
/// These methods are only executed when the application is compiled in DEBUG mode.
|
|
||||||
/// </summary>
|
|
||||||
internal static class Tracer
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Writes a line of text to the console, but only when in DEBUG mode.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="content">The text to write to the console.</param>
|
|
||||||
[Conditional("DEBUG")]
|
|
||||||
internal static void WriteLine(string content) =>
|
|
||||||
Console.WriteLine(content);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Writes text to the console without a newline, but only when in DEBUG mode.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="content">The text to write to the console.</param>
|
|
||||||
[Conditional("DEBUG")]
|
|
||||||
internal static void Write(string content) =>
|
|
||||||
Console.Write(content);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Writes multiple lines of text to the console, but only when in DEBUG mode.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="contents">A collection of text lines to write to the console.</param>
|
|
||||||
[Conditional("DEBUG")]
|
|
||||||
internal static void WriteLine(IEnumerable<string> contents)
|
|
||||||
{
|
|
||||||
foreach (var content in contents)
|
|
||||||
{
|
|
||||||
Console.WriteLine(content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Writes multiple text entries to the console without newlines, but only when in DEBUG mode.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="contents">A collection of text entries to write to the console.</param>
|
|
||||||
[Conditional("DEBUG")]
|
|
||||||
internal static void Write(IEnumerable<string> contents)
|
|
||||||
{
|
|
||||||
foreach (var content in contents)
|
|
||||||
{
|
|
||||||
Console.Write(content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the current working directory in DEBUG mode or the application's base directory in release mode.
|
|
||||||
/// </summary>
|
|
||||||
internal static string AppDirectory
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
#if DEBUG
|
|
||||||
return Directory.GetCurrentDirectory();
|
|
||||||
#else
|
|
||||||
return AppDomain.CurrentDomain.BaseDirectory;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
17
World3D.cs
17
World3D.cs
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
Before Width: | Height: | Size: 164 B |
Loading…
Add table
Reference in a new issue