mirror of
https://github.com/tonytins/playbark.git
synced 2025-04-30 02:21:41 -04:00
Remove Init() function
- Renamed ReadConfig() to Settings() - Made Game() function unsafe - Removed Init from Camera() in World3D class - Allow for unsafe blocks
This commit is contained in:
parent
b8cd12302e
commit
85a0e2eda1
4 changed files with 34 additions and 13 deletions
|
@ -4,6 +4,7 @@
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
42
Program.cs
42
Program.cs
|
@ -5,7 +5,7 @@
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file">The name of the configuration file (defaults to "config.toml").</param>
|
/// <param name="file">The name of the configuration file (defaults to "config.toml").</param>
|
||||||
/// <returns>A Config object populated with values from the file, or a default Config instance if the file is not found.</returns>
|
/// <returns>A Config object populated with values from the file, or a default Config instance if the file is not found.</returns>
|
||||||
static Config ReadConfig(string file)
|
static Config Settings(string file)
|
||||||
{
|
{
|
||||||
var cfgPath = Path.Combine(Tracer.AppDirectory, file);
|
var cfgPath = Path.Combine(Tracer.AppDirectory, file);
|
||||||
|
|
||||||
|
@ -28,35 +28,55 @@ static Config ReadConfig(string file)
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init(int screenWidth, int screenHeight, int fps)
|
// Update and Draw
|
||||||
|
unsafe int Game()
|
||||||
{
|
{
|
||||||
|
var config = Settings("config.toml");
|
||||||
|
InitWindow(config.Width, config.Height, $"PlayBark");
|
||||||
|
|
||||||
var pos = new Vector3(0.2f, 0.4f, 0.2f);
|
var pos = new Vector3(0.2f, 0.4f, 0.2f);
|
||||||
var target = new Vector3(0.0f, 0.0f, 0.0f);
|
var target = new Vector3(0.0f, 0.0f, 0.0f);
|
||||||
var up = new Vector3(0.0f, 1.0f, 0.0f);
|
var up = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
|
var camera = World3D.Camera(pos, target, up, CameraProjection.Perspective);
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, $"PlayBark");
|
var imMap = LoadImage("resources/cubicmap.png");
|
||||||
World3D.InitCamera(pos, target, up, CameraProjection.Perspective);
|
var cubicMap = LoadTextureFromImage(imMap);
|
||||||
SetTargetFPS(fps);
|
var mesh = GenMeshCubicmap(imMap, new Vector3(1.0f, 1.0f, 1.0f));
|
||||||
}
|
var model = LoadModelFromMesh(mesh);
|
||||||
|
|
||||||
int GameLoop()
|
var texture = LoadTexture("resources/cubicmap_atlas.png");
|
||||||
{
|
|
||||||
var config = ReadConfig("config.toml");
|
|
||||||
Init(config.Width, config.Height, 60);
|
|
||||||
|
|
||||||
|
// Set map diffuse texture
|
||||||
|
SetMaterialTexture(ref model, 0, MaterialMapIndex.Albedo, ref texture);
|
||||||
|
|
||||||
|
// Get image map data to be used for collission
|
||||||
|
var mapPixels = LoadImageColors(imMap);
|
||||||
|
UnloadImage(imMap);
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(Color.White);
|
ClearBackground(Color.White);
|
||||||
|
|
||||||
|
var oldCamPos = camera.Position;
|
||||||
|
UpdateCamera(ref camera, CameraMode.FirstPerson);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UnloadImageColors(mapPixels);
|
||||||
|
|
||||||
|
UnloadTexture(cubicMap);
|
||||||
|
UnloadTexture(texture);
|
||||||
|
UnloadModel(model);
|
||||||
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLoop();
|
// Entry point
|
||||||
|
Game();
|
||||||
|
|
|
@ -3,9 +3,9 @@ namespace PlayBark;
|
||||||
|
|
||||||
internal static class World3D
|
internal static class World3D
|
||||||
{
|
{
|
||||||
public static Camera3D InitCamera(Vector3 pos, Vector3 target, Vector3 up, CameraProjection projection)
|
public static Camera3D Camera(Vector3 pos, Vector3 target, Vector3 up, CameraProjection projection)
|
||||||
{
|
{
|
||||||
Camera3D camera = new();
|
var camera = new Camera3D();
|
||||||
camera.Position = pos;
|
camera.Position = pos;
|
||||||
camera.Target = target;
|
camera.Target = target;
|
||||||
camera.Up = up;
|
camera.Up = up;
|
||||||
|
|
BIN
resources/cubicmap_atlas.png
Normal file
BIN
resources/cubicmap_atlas.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
Loading…
Add table
Reference in a new issue