Esempio n. 1
0
        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);
        }