mirror of
https://github.com/UOH-CS-Level5/551455-graphics-programming-2526-the-repo-Zyb3rWolfi.git
synced 2025-11-29 00:43:08 +00:00
64 lines
2.1 KiB
C#
64 lines
2.1 KiB
C#
using Assimp;
|
|
using LearnOpenTK.Common;
|
|
using OpenTK.Mathematics;
|
|
|
|
namespace TheLabs;
|
|
|
|
public class LevelLoader
|
|
{
|
|
|
|
private Shader _shader;
|
|
private Texture _texture;
|
|
private Texture _normalTexture;
|
|
private Material _material;
|
|
private Lighting _lighting;
|
|
|
|
|
|
public LevelLoader(Shader shader, Texture texture, Texture normalTexture, Material material, Lighting lighting)
|
|
{
|
|
_shader = shader;
|
|
_texture = texture;
|
|
_normalTexture = normalTexture;
|
|
_material = material;
|
|
_lighting = lighting;
|
|
}
|
|
|
|
public void LoadLevel(string filepath, SceneNode rootenode, List<BoxCollider> colliders)
|
|
{
|
|
Mesh _mesh = ShapeFactory.CreateTexturedCube();
|
|
RenderObject renderObject = new RenderObject(_mesh, _shader, _texture, _material, _lighting);
|
|
renderObject.NormalMap = _normalTexture;
|
|
renderObject.UseTexture = true;
|
|
|
|
if (!File.Exists(filepath))
|
|
{
|
|
throw new FileNotFoundException("The specified level file was not found.", filepath);
|
|
}
|
|
string[] lines = File.ReadAllLines(filepath);
|
|
float spacing = 1.0f;
|
|
|
|
for (int z = 0; z < lines.Length; z++)
|
|
{
|
|
string line = lines[z];
|
|
for (int x = 0; x < line.Length; x++)
|
|
{
|
|
char tile = line[x];
|
|
|
|
SceneNode floorNode = new SceneNode(renderObject);
|
|
floorNode.Position = new Vector3(x * spacing, -0.5f, z * spacing);
|
|
floorNode.Scale = new Vector3(1.0f, 0.1f, 1.0f);
|
|
rootenode.AddChild(floorNode);
|
|
|
|
if (tile == '1')
|
|
{
|
|
BoxCollider wallCollider = new BoxCollider(new Vector3(x, 0, z), new Vector3(1, 1, 1));
|
|
colliders.Add(wallCollider);
|
|
SceneNode wallNode = new SceneNode(renderObject);
|
|
wallNode.Position = new Vector3(x * spacing, 0.0f, z * spacing);
|
|
|
|
rootenode.AddChild(wallNode);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |