public void OnPostRender() { // RENDER OPEN SPOTS for (int i = TileIndexMin; i <= TileIndexMax; i++) { for (int j = TileIndexMin; j <= TileIndexMax; j++) { DrawMeshOnGrid(Meshes["ArenaSquareMesh"], GameAssets.Material.ArenaGrid, new Vector2Int(i, j), Quaternion.identity); } } // RENDER SNAKES PlayerSnake.RenderSnake(); for (int i = 0; i < EnemySnakes.Count; i++) { EnemySnakes[i].RenderSnake(); } // RENDER THE FOOD foreach (Vector2Int FoodPosition in Food) { DrawMeshOnGrid(Meshes["EngorgedMesh"], GameAssets.Material.Food, FoodPosition, Quaternion.identity); } // RENDER THE EGGS if (Eggs.Count > 0) { foreach (KeyValuePair <Vector2Int, int> EggKeyPair in Eggs) { int Tier = EggKeyPair.Value; if (!Meshes.TryGetValue("SnakeBodyOutline", out Mesh mesh)) { Debug.LogError("Missing mesh"); } Material mat = GameAssets.GetTierMaterial(Tier); DrawMeshOnGrid(mesh, mat, EggKeyPair.Key, Quaternion.identity); DrawMeshOnGrid(mesh, mat, EggKeyPair.Key, Quaternion.Euler(0, 0, 90f)); DrawMeshOnGrid(mesh, mat, EggKeyPair.Key, Quaternion.Euler(0, 0, 180f)); DrawMeshOnGrid(mesh, mat, EggKeyPair.Key, Quaternion.Euler(0, 0, 270f)); } } // RENDER COLLISSION MAP if (RenderCollissionMapFlag) { for (int i = TileIndexMin; i <= TileIndexMax; i++) { for (int j = TileIndexMin; j <= TileIndexMax; j++) { if (CollisionMap[j, i]) { Vector2 GridCenterPosition = new Vector2(GridSize * i, GridSize * j) + RenderOffset; Debug.DrawRay(GridCenterPosition + new Vector2(-GridSize / 2, GridSize / 2), Vector2.right, Color.red); Debug.DrawRay(GridCenterPosition + new Vector2(GridSize / 2, GridSize / 2), Vector2.down, Color.red); Debug.DrawRay(GridCenterPosition + new Vector2(GridSize / 2, -GridSize / 2), Vector2.left, Color.red); Debug.DrawRay(GridCenterPosition + new Vector2(-GridSize / 2, -GridSize / 2), Vector2.up, Color.red); } } } } // RENDER WALLS // DRAW SNAKE BODY foreach (Vector2Int WallPosition in Walls) { DrawMeshOnGrid(Meshes["EngorgedMesh"], GameAssets.Material.Wall, WallPosition, Quaternion.identity); // DRAW WALL OUTLINE Material OutlineMaterial = GameAssets.Material.EnemyOutline; DrawMeshOnGrid(Meshes["SnakeEngorgedBodyOutline"], OutlineMaterial, WallPosition, Quaternion.Euler(0f, 0f, 0f)); DrawMeshOnGrid(Meshes["SnakeEngorgedBodyOutline"], OutlineMaterial, WallPosition, Quaternion.Euler(0f, 0f, 90f)); DrawMeshOnGrid(Meshes["SnakeEngorgedBodyOutline"], OutlineMaterial, WallPosition, Quaternion.Euler(0f, 0f, 180f)); DrawMeshOnGrid(Meshes["SnakeEngorgedBodyOutline"], OutlineMaterial, WallPosition, Quaternion.Euler(0f, 0f, 270f)); } }
public void RenderSnake() { if (Dead) { return; } // DRAW TAIL LinkedListNode <SnakeBody> node = Bodies.Last; Material mat = IsPlayer ? GameAssets.Material.Player : GameAssets.GetTierMaterial(Tier); Mesh mesh; Quaternion quat; if (node != null) { while (node != null) { // DRAW SNAKE TRAIL LINE switch (node.Value.FacingHead) { case MoveDir.Right: quat = Quaternion.identity; break; case MoveDir.Up: quat = Quaternion.Euler(0, 0, 90f); break; case MoveDir.Left: quat = Quaternion.Euler(0, 0, 180f); break; case MoveDir.Down: quat = Quaternion.Euler(0, 0, 270f); break; default: quat = Quaternion.identity; Debug.LogError("Drawing snake trace line: Invalid Facing direction detected"); break; } GameController.DrawMeshOnGrid(GameController.Meshes["SnakeLineMesh"], GameAssets.Material.Line, node.Value.Position, quat); // DRAW SNAKE BODY Mesh OutlineMesh; if (node.Value.Engorged) { mesh = GameController.Meshes["EngorgedMesh"]; OutlineMesh = GameController.Meshes["SnakeEngorgedBodyOutline"]; } else { mesh = GameController.Meshes["SnakeBody"]; OutlineMesh = GameController.Meshes["SnakeBodyOutline"]; } GameController.DrawMeshOnGrid(mesh, mat, node.Value.Position, Quaternion.identity); if (!IsPlayer) { // DRAW ENEMY SNAKE OUTLINE Material OutlineMaterial = GameAssets.Material.EnemyOutline; GameController.DrawMeshOnGrid(OutlineMesh, OutlineMaterial, node.Value.Position, Quaternion.Euler(0f, 0f, 0f)); GameController.DrawMeshOnGrid(OutlineMesh, OutlineMaterial, node.Value.Position, Quaternion.Euler(0f, 0f, 90f)); GameController.DrawMeshOnGrid(OutlineMesh, OutlineMaterial, node.Value.Position, Quaternion.Euler(0f, 0f, 180f)); GameController.DrawMeshOnGrid(OutlineMesh, OutlineMaterial, node.Value.Position, Quaternion.Euler(0f, 0f, 270f)); } if (node.Value.Engorged) { // DRAW EATEN MATERIAL Material EatenMat; if (node.Value.Digestion == SnakeBody.FoodType.Food) { EatenMat = GameAssets.Material.Food; } else { EatenMat = GameAssets.GetTierMaterial(node.Value.FoodTier); } GameController.DrawMeshOnGrid(GameController.Meshes["ArenaSquareMesh"], EatenMat, node.Value.Position, Quaternion.Euler(0f, 0f, 0f)); } node = node.Previous; } } switch (Facing) { case MoveDir.Right: quat = Quaternion.identity; break; case MoveDir.Up: quat = Quaternion.Euler(0, 0, 90f); break; case MoveDir.Left: quat = Quaternion.Euler(0, 0, 180f); break; case MoveDir.Down: quat = Quaternion.Euler(0, 0, 270f); break; default: quat = Quaternion.identity; Debug.LogError("Drawing snake trace line: Invalid Facing direction detected"); break; } // DRAW HEAD if (!Dying) { GameController.DrawMeshOnGrid(GameController.Meshes["SnakeHeadMesh"], mat, HeadPosition, quat); GameController.DrawMeshOnGrid(GameController.Meshes["SnakeSnoutOutline"], GameAssets.Material.EnemyOutline, HeadPosition, quat); } }