private void LoadGame() { GameLoaded = true;//let this on the top SplashScreen.SetState("Starting SoundEngine...", SplashScreenStatus.Loading); _soundSystem = new SoundSystem(); SplashScreen.SetState("Loading Assets...", SplashScreenStatus.Loading); _assetsManager = new AssetsManager(); SplashScreen.SetState("Starting Physics", SplashScreenStatus.Loading); _physics = new Physics(); SplashScreen.SetState("Starting GUI", SplashScreenStatus.Loading); _GUIRender = new GUI(); SplashScreen.SetState("Starting Frustum", SplashScreenStatus.Loading); frustum = new Frustum(); SplashScreen.SetState("Starting Client", SplashScreenStatus.Loading); OGame = new Client(); SplashScreen.SetState("Setting-Up OpenGL", SplashScreenStatus.Loading); SplashScreen.SetState("Finished Loading. We Good to Go (:", SplashScreenStatus.finished); EngineIsReady = true; }
private void SMakeMesh() { if (ChunkMesh != null) { if (_meshCollider != null) { _meshCollider.UpdateCollider(transform, ChunkMesh); } else { _meshCollider = new MeshCollider(transform, ChunkMesh._vertices, ChunkMesh._indices); } if (_meshRender != null) { _meshRender.UpdateMeshRender(ChunkMesh); } else { _meshRender = new ChunkMeshRender(transform, ChunkMesh, AssetsManager.GetShader("TerrainDefault"), AssetsManager.GetTexture("TileAtlas")); _meshRender.ViewBoxWitdh = 10; _meshRender.ViewBoxHeight = 1000; } } if (WaterMesh != null) { if (_waterMeshRender != null) { //_meshRender.UpdateMeshRender(ChunkMesh); } else { _waterMeshRender = new WaterMeshRender(transform, WaterMesh, AssetsManager.GetShader("Water"), AssetsManager.GetTexture("Water"), AssetsManager.GetTexture("Water2")); _waterMeshRender.Transparency = true; _waterMeshRender.ViewBoxWitdh = 10; _waterMeshRender.ViewBoxHeight = 1000; } } for (int i = 0; i < _trees.Count; i++) { _trees[i].OnDestroy(); } _trees.Clear(); for (int x = 0; x < MidleWorld.ChunkSize; x++) { for (int z = 0; z < MidleWorld.ChunkSize; z++) { if (blocks[x, z].treeType != TreeType.none) { _trees.Add(new Tree(new Vector3(blocks[x, z].x, blocks[x, z].height, blocks[x, z].z), blocks[x, z].treeType)); } } } }
public MeshRender AddMeshRender() { MeshRender meshrender = new MeshRender(this, AssetsManager.LoadModel("Assets/Models/", "Cube"), new Shader(AssetsManager.instance.GetShader("Default"))); meshrender._shader.AddTexture(new Texture(AssetsManager.instance.GetTexture("NewGrassTeste", "png"))); _MeshRender = meshrender; return(_MeshRender); }
public VoxelMesh MakeWaterMesh(Block[,] tile) { Vector3[] vertices; List <Vector2> uvs = new List <Vector2>(); int[] triangles; List <Color4> colors = new List <Color4>(); VoxelMesh mesh = new VoxelMesh(); int widh = MidleWorld.ChunkSize + 1; vertices = new Vector3[widh * widh]; for (int y = 0; y < widh; y++) { for (int x = 0; x < widh; x++) { vertices[x + y * widh] = new Vector3(x, 0.0f, y); colors.Add(new Color4(1, 1, 1, 1)); uvs.AddRange(AssetsManager.GetTileUV("Water")); } } triangles = new int[3 * 2 * (widh * widh - widh - widh + 1)]; int triangleVertexCount = 0; for (int vertex = 0; vertex < widh * widh - widh; vertex++) { if (vertex % widh != (widh - 1)) { // First triangle int A = vertex; int B = A + widh; int C = B + 1; triangles[triangleVertexCount] = A; triangles[triangleVertexCount + 1] = B; triangles[triangleVertexCount + 2] = C; //Second triangle B += 1; C = A + 1; triangles[triangleVertexCount + 3] = A; triangles[triangleVertexCount + 4] = B; triangles[triangleVertexCount + 5] = C; triangleVertexCount += 6; } } mesh.verts = vertices; mesh.uvs = uvs.ToArray(); mesh.indices = triangles; mesh.colors = colors.ToArray(); return(mesh); }
public VoxelMesh MakeWatersMehs(Block[,] tile) { _vertices = new List <Vector3>(); _UVs = new List <Vector2>(); _triangles = new List <int>(); _colors = new List <Color4>(); VoxelMesh mesh = new VoxelMesh(); int verticesNum = 0; for (int x = 0; x < MidleWorld.ChunkSize; x++) { for (int z = 0; z < MidleWorld.ChunkSize; z++) { if (tile[x, z].Type == TypeBlock.Sand) { _vertices.Add(new Vector3(x, -1f, z)); _vertices.Add(new Vector3(x + 1, -1, z)); _vertices.Add(new Vector3(x, -1, z + 1)); _vertices.Add(new Vector3(x + 1, -1, z + 1)); _triangles.Add(0 + verticesNum); _triangles.Add(1 + verticesNum); _triangles.Add(2 + verticesNum); _triangles.Add(2 + verticesNum); _triangles.Add(1 + verticesNum); _triangles.Add(3 + verticesNum); verticesNum += 4; _colors.Add(new Color4(1, 1, 1, 1)); _colors.Add(new Color4(1, 1, 1, 1)); _colors.Add(new Color4(1, 1, 1, 1)); _colors.Add(new Color4(1, 1, 1, 1)); _UVs.AddRange(AssetsManager.GetTileUV("Water")); } } } mesh.verts = _vertices.ToArray(); mesh.uvs = _UVs.ToArray(); mesh.indices = _triangles.ToArray(); mesh.colors = _colors.ToArray(); return(mesh); }
public AssetsManager() { instance = this; _Textures = new Dictionary <string, Texture>(); _CubeTextures = new Dictionary <string, CubeMapTexture>(); _Shaders = new Dictionary <string, Shader>(); _Models = new Dictionary <string, Mesh>(); _Sounds = new Dictionary <string, AudioClip>(); _Fonts = new Dictionary <string, FontType>(); _Tiles = new Dictionary <string, Vector2[]>(); LoadAssets(); }
public MeshData(Block[,] tile) { _vertices = new List <Vector3>(); _UVs = new List <Vector2>(); _triangles = new List <int>(); _colors = new List <Color4>(); int verticesNum = 0; for (int x = 0; x < MidleWorld.ChunkSize; x++) { for (int z = 0; z < MidleWorld.ChunkSize; z++) { if (tile[x, z].Type != TypeBlock.Air) { int xB = tile[x, z].x; int zB = tile[x, z].z; float Right = GetTile(xB + 1, zB, tile[x, z].height, tile); float FrenteRight = GetTile(xB, zB + 1, tile[x, z].height, tile); float FrenteLeft = GetTile(xB + 1, zB + 1, tile[x, z].height, tile); _vertices.Add(new Vector3(x, tile[x, z].height, z)); _vertices.Add(new Vector3(x + 1, Right, z)); _vertices.Add(new Vector3(x, FrenteRight, z + 1)); _vertices.Add(new Vector3(x + 1, FrenteLeft, z + 1)); _triangles.Add(0 + verticesNum); _triangles.Add(1 + verticesNum); _triangles.Add(2 + verticesNum); _triangles.Add(2 + verticesNum); _triangles.Add(1 + verticesNum); _triangles.Add(3 + verticesNum); verticesNum += 4; _colors.Add(Get.TileColors(tile[x, z].TileBiome)); _colors.Add(Get.TileColors(tile[x, z].TileBiome)); _colors.Add(Get.TileColors(tile[x, z].TileBiome)); _colors.Add(Get.TileColors(tile[x, z].TileBiome)); _UVs.AddRange(AssetsManager.GetTileUV(tile[x, z].Type.ToString())); } } } }
public Tree(Vector3 position, TreeType treeType) { HP = 100; MaxHP = 100; transform = new Transform(); System.Random rand = new System.Random(); float a = (float)rand.NextDouble(); float b = (float)rand.NextDouble(); float ChunkSeed = position.X * a + position.Z * b; transform.Position = position; transform.Rotation = new Quaternion(MathHelper.DegreesToRadians((float)new System.Random((int)ChunkSeed).Next(-10, 10)), MathHelper.DegreesToRadians((float)new System.Random((int)ChunkSeed).Next(0, 90)), MathHelper.DegreesToRadians((float)new System.Random((int)ChunkSeed).Next(-10, 10))); float size = ProjectEvlly.src.Utility.Random.Range(1.5f, 2f, (int)ChunkSeed); transform.Size = new Vector3(1, 1, 1); switch (treeType) { case TreeType.Oak: _meshRender = new MeshRender(transform, AssetsManager.GetMesh("oak"), AssetsManager.GetShader("Default"), AssetsManager.GetTexture("SpritesTreeHigt")); break; case TreeType.Pine: _meshRender = new MeshRender(transform, AssetsManager.GetMesh("Pine01"), AssetsManager.GetShader("Default"), AssetsManager.GetTexture("SpritesTreeHigt")); break; case TreeType.PineSnow: _meshRender = new MeshRender(transform, AssetsManager.GetMesh("Pine01"), AssetsManager.GetShader("Default"), AssetsManager.GetTexture("SpritesTreeHigt_Snow")); break; } _meshRender.ViewBoxWitdh = 3; _meshRender.ViewBoxHeight = 5; //_meshRender.Transparency = true; _meshRender._cullType = OpenTK.Graphics.OpenGL.CullFaceMode.FrontAndBack; _boxCollider = new BoxCollider(transform, new Vector3(0.7f, 5, 0.7f)); }
/// <summary> /// This is gona disconnect/quit you from any world or server etc. and unload assets, and other things, this is for reload the game, like the firts time /// </summary> public void ReloadGame() { Network.Disconnect();//Disconnect you from any server you are in, or if you is the host closing the server if (OGame != null) { OGame.Dispose(); OGame = null; } if (_physics != null) { _physics.Dispose(); _physics = null; } /*if (_GUI != null) * { * _GUI.Dispose(); * _GUI = null; * }*/ if (_GUIRender != null) { _GUIRender.Dispose(); _GUIRender = null; } _assetsManager.Dispose(); _assetsManager = null; _soundSystem.Dispose(); GameLoaded = false; EngineIsReady = false; }
public AssetsManager() { instance = this; Engine_Error = LoadModel("Assets/Models/", "error"); }
protected override void OnLoad(EventArgs e) { //Load the Window/pre Graphics Stuff// VSync = VSyncMode.Off; WindowBorder = WindowBorder.Fixed; GL.ClearColor(Color4.DeepSkyBlue); GL.Enable(EnableCap.DepthTest); GL.CullFace(CullFaceMode.Front); GL.Viewport(0, 0, Width, Height); //Load the Engine Stuff// _assetsManager = new AssetsManager(); _UIManager = new UIManager(); _physics = new Physics(); SceneManager.LoadDontDestroyScene(); SceneManager.LoadDefaultScene(); GameObject Player = GameObject.Instantiate("Player", 1); Player._transform.Position = new Vector3(0, 50, 0); Player.AddRigidBody(); Player.AddScript(new PlayerEntity()); GameObject camobj = GameObject.Instantiate("Camera", 1); camobj._transform.Position = new Vector3(0, 1, 0); camobj.AddCamera(); camobj._transform.SetChild(Player._transform); GameObject World = GameObject.Instantiate(new Vector3(0, 0, 0), new Quaternion(0, 0, 0, 0), 1); World.AddScript(new World()); for (int x = 0; x < 2; x++) { if (x == 0) { GameObject obj = GameObject.Instantiate(new Vector3(x, 0, 0), Quaternion.Identity, 1); MeshRender mesh = obj.AddMeshRender(new MeshRender(obj, AssetsManager.instance.GetMesh("Cube"), new Shader(AssetsManager.instance.GetShader("Default")))); //obj.AddBoxCollider(new BoxCollider(obj, new Vector3(100,1,100))); obj.AddMeshCollider(); mesh._shader.AddTexture(new Texture(AssetsManager.instance.GetTexture("NewGrassTeste", "png"))); } else { GameObject obj = GameObject.Instantiate(new Vector3(x, 0.01f, 0), Quaternion.Identity, 1); MeshRender meshh = obj.AddMeshRender(new MeshRender(obj, AssetsManager.instance.GetMesh("Cube2"), new Shader(AssetsManager.instance.GetShader("Default")))); meshh._shader.AddTexture(new Texture(AssetsManager.instance.GetTexture("RockBrick_01", "png"))); obj.AddMeshCollider(); } } for (int i = 0; i < 1; i++) { GameObject wall = GameObject.Instantiate(new Vector3(0, 0, -100), new Quaternion(90, 0, 0, 0), 1); MeshRender mesh = wall.AddMeshRender(new MeshRender(wall, AssetsManager.instance.GetMesh("Cube"), new Shader(AssetsManager.instance.GetShader("Default")))); wall.AddBoxCollider(new BoxCollider(wall, new Vector3(100, 1, 100))); mesh._shader.AddTexture(new Texture(AssetsManager.instance.GetTexture("NewGrassTeste", "png"))); } GameObject obj2 = GameObject.Instantiate(new Vector3(0, 20, 0), new Quaternion(-90, 0, 0, 0), 1); MeshRender mesh2 = obj2.AddMeshRender(new MeshRender(obj2, _assetsManager.GetErrorMesh, new Shader(AssetsManager.instance.GetShader("Default")))); mesh2._shader.AddTexture(new Texture(AssetsManager.instance.GetTexture("RedTexture", "png"))); LaucherPed = GameObject.Instantiate(new Vector3(50, 1, 0), new Quaternion(0, 0, 0, 0), 1); LaucherPed.AddScript(new ScriptTest()); MeshRender meshLaucherPed = LaucherPed.AddMeshRender(new MeshRender(LaucherPed, new Mesh(AssetsManager.instance.GetMesh("Monkey")), new Shader(AssetsManager.instance.GetShader("Default")))); meshLaucherPed._shader.AddTexture(new Texture(AssetsManager.instance.GetTexture("woodplank01", "png"))); LaucherPed.AddRigidBody(); meshLaucherPed.Transparency = true; EngineReady = true; base.OnLoad(e); }