mirror of
https://github.com/tonytins/playbark.git
synced 2025-04-30 02:21:41 -04:00
Moved map generation to World3D
- Fixed an oversight where it ended 2D mode upon exit instead of 3D
This commit is contained in:
parent
49a336ea1f
commit
57736192c8
2 changed files with 29 additions and 8 deletions
13
Program.cs
13
Program.cs
|
@ -32,7 +32,7 @@ static Config Settings(string file)
|
|||
unsafe int Game()
|
||||
{
|
||||
var config = Settings("config.toml");
|
||||
InitWindow(config.Width, config.Height, $"PlayBark");
|
||||
InitWindow(config.Width, config.Height, "PlayBark");
|
||||
|
||||
var pos = new Vector3(0.2f, 0.4f, 0.2f);
|
||||
var target = new Vector3(0.0f, 0.0f, 0.0f);
|
||||
|
@ -41,13 +41,12 @@ unsafe int Game()
|
|||
|
||||
var imMap = LoadImage("resources/cubicmap.png");
|
||||
var cubicmap = LoadTextureFromImage(imMap);
|
||||
var mesh = GenMeshCubicmap(imMap, new Vector3(1.0f, 1.0f, 1.0f));
|
||||
var model = LoadModelFromMesh(mesh);
|
||||
var model = World3D.CubicMap(imMap);
|
||||
|
||||
var texture = LoadTexture("resources/cubicmap_atlas.png");
|
||||
|
||||
// Set map diffuse texture
|
||||
SetMaterialTexture(ref model, 0, MaterialMapIndex.Albedo, ref texture);
|
||||
Raylib.SetMaterialTexture(ref model, 0, MaterialMapIndex.Albedo, ref texture);
|
||||
|
||||
// Get image map data to be used for collission
|
||||
var mapPixels = LoadImageColors(imMap);
|
||||
|
@ -60,9 +59,7 @@ unsafe int Game()
|
|||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
BeginDrawing();
|
||||
ClearBackground(Color.White);
|
||||
|
||||
// Update
|
||||
var oldCamPos = camera.Position;
|
||||
UpdateCamera(ref camera, CameraMode.FirstPerson);
|
||||
|
||||
|
@ -117,7 +114,7 @@ unsafe int Game()
|
|||
ClearBackground(Color.RayWhite);
|
||||
BeginMode3D(camera);
|
||||
DrawModel(model, mapPosition, 1.0f, Color.White);
|
||||
EndMode2D();
|
||||
EndMode3D();
|
||||
|
||||
DrawTextureEx(cubicmap, new Vector2(GetScreenWidth() - cubicmap.Width * 4 - 20, 20), 0.0f, 4.0f, Color.White);
|
||||
DrawRectangleLines(GetScreenWidth() - cubicmap.Width * 4 - 20, 20, cubicmap.Width * 4, cubicmap.Height * 4, Color.Green);
|
||||
|
|
24
World3D.cs
24
World3D.cs
|
@ -1,8 +1,19 @@
|
|||
// I hereby waive this project under the public domain - see UNLICENSE for details.
|
||||
namespace PlayBark;
|
||||
|
||||
/// <summary>
|
||||
/// Provides utilities for creating and managing 3D world elements, including camera setup and map generation.
|
||||
/// </summary>
|
||||
internal static class World3D
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates and returns a configured Camera3D instance.
|
||||
/// </summary>
|
||||
/// <param name="pos">The position of the camera in 3D space.</param>
|
||||
/// <param name="target">The point the camera is looking at.</param>
|
||||
/// <param name="up">The up direction for the camera.</param>
|
||||
/// <param name="projection">The projection type of the camera.</param>
|
||||
/// <returns>A configured Camera3D instance.</returns>
|
||||
public static Camera3D Camera(Vector3 pos, Vector3 target, Vector3 up, CameraProjection projection)
|
||||
{
|
||||
var camera = new Camera3D();
|
||||
|
@ -14,4 +25,17 @@ internal static class World3D
|
|||
|
||||
return camera;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a 3D cubic map model from a given image map.
|
||||
/// </summary>
|
||||
/// <param name="imMap">The image used to generate the cubic map.</param>
|
||||
/// <returns>A Model representing the cubic map.</returns>
|
||||
public static Model CubicMap(Image imMap)
|
||||
{
|
||||
var mesh = GenMeshCubicmap(imMap, new Vector3(1.0f, 1.0f, 1.0f));
|
||||
var model = LoadModelFromMesh(mesh);
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue