public static void SpawnEntities(int id, Vector3 corigin, int index) { CampaignSection csection = new CampaignSection(index, corigin); Texture2D t = AssetLoader.tex_section_ent[id]; Color[] colours = new Color[96*96]; t.GetData<Color>(colours); for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; x++) { int pixelX = x * 3; int pixelY = y * 3; int pixelIndex = pixelY * 96 + pixelX; Color c = colours[pixelIndex]; Vector3 center = corigin + new Vector3(0.5f + x, 0, 0.5f + y); if (c == Color.Black || c == Color.Blue) { Globals.gameInstance.cellCollider.SetCollision(center.X, center.Z, true); } else if (c == Color.Yellow) { csection.AddOverheadLight(SpawnOverheadLight(center)); } else if (c == Color.Red) { SpawnFilingCabinet(center, colours, pixelX, pixelY); } else if (c == PureGreen) { int pi2 = (pixelY+1) * 96 + pixelX+1; Color cc = colours[pi2]; if (cc == PureGreen) { csection.SetDoor(new Door(center)); } } else if (c == Color.DarkMagenta) { int pi2 = (pixelY + 2) * 96 + pixelX + 1; if (colours[pi2] != Color.DarkMagenta) { Mesh m = new Mesh(); m.Model = AssetLoader.mdl_desk; m.SetInstancingEnabled(true); m.Transform = Matrix.CreateRotationY(MathHelper.ToRadians(0)) * Matrix.CreateTranslation(center + new Vector3(0,0,0.5f)); Globals.gameInstance.cellCollider.SetCollision(center.X, center.Z, true); Globals.gameInstance.cellCollider.SetCollision(center.X, center.Z + 1, true); Globals.gameInstance.sceneGraph.Setup(m); Globals.gameInstance.sceneGraph.Add(m); } int pi3 = (pixelY + 1) * 96 + pixelX + 2; if (colours[pi3] != Color.DarkMagenta) { Mesh m = new Mesh(); m.Model = AssetLoader.mdl_desk; m.SetInstancingEnabled(true); m.Transform = Matrix.CreateRotationY(MathHelper.ToRadians(90)) * Matrix.CreateTranslation(center + new Vector3(0.5f, 0, 0)); Globals.gameInstance.cellCollider.SetCollision(center.X, center.Z, true); Globals.gameInstance.cellCollider.SetCollision(center.X, center.Z + 1, true); Globals.gameInstance.sceneGraph.Setup(m); Globals.gameInstance.sceneGraph.Add(m); } } else if (c == Color.Turquoise) { float a = GetAngleToAWall(colours, pixelX, pixelY); Mesh m = new Mesh(); m.Model = AssetLoader.mdl_pipe; m.SetInstancingEnabled(true); m.Transform = Matrix.CreateRotationY(MathHelper.ToRadians(a)) * Matrix.CreateTranslation(center); Globals.gameInstance.cellCollider.SetCollision(center.X, center.Z, true); Globals.gameInstance.sceneGraph.Setup(m); Globals.gameInstance.sceneGraph.Add(m); } else if (c == Color.Tan) { csection.SetWeaponDepot(new WeaponDepot(center, Globals.random.Next(3)+1)); } else if (c == Color.SteelBlue) { Globals.gameInstance.campaignManager.SetTeleport(new Teleporter(center)); } } } Globals.gameInstance.campaignManager.AddSection(csection); }
public static void SpawnFilingCabinet(Vector3 center, Color[] data, int x, int y) { Globals.gameInstance.cellCollider.SetCollision(center.X, center.Z, true); Color u = data[y * 96 + x+1]; Color d = data[(y + 2) * 96 + x+1]; Color l = data[(y+1) * 96 + x]; Color r = data[(y+1) * 96 + x + 2]; float angle_d = 0; if (u != Color.Red) { angle_d = 0; } else if (d != Color.Red) { angle_d = 180; } else if (l != Color.Red) { angle_d = 90; } else if (r != Color.Red) { angle_d = -90; } Mesh m = new Mesh(); m.Model = AssetLoader.mdl_filingcabinet; m.SetInstancingEnabled(true); m.Transform = Matrix.CreateRotationY(MathHelper.ToRadians(angle_d)) * Matrix.CreateTranslation(center); Globals.gameInstance.sceneGraph.Setup(m); Globals.gameInstance.sceneGraph.Add(m); }