예제 #1
0
        public void OnAction(Entity entity)
        {
            if ((entity.Mask & MASK) == MASK)
            {
                ComponentGeometry geometryComponent = (ComponentGeometry)entity.FindComponent(ComponentTypes.COMPONENT_GEOMETRY);
                Geometry          geometry          = geometryComponent.Geometry();

                ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
                //Vector3 position = transformComponent.Position;
                //Vector3 scale = transformComponent.Scale;
                //Vector3 rotation = transformComponent.Rotation;

                //Matrix4 translateMatrix = Matrix4.CreateTranslation(position);
                //Matrix4 scaleMatrix = Matrix4.CreateScale(scale);
                //Matrix4 xRotMatrix = Matrix4.CreateRotationX(rotation.X);
                //Matrix4 yRotMatrix = Matrix4.CreateRotationY(rotation.Y);
                //Matrix4 zRotMatrix = Matrix4.CreateRotationZ(rotation.Z);
                //Matrix4 rotMatrix = xRotMatrix * yRotMatrix * zRotMatrix;

                //Matrix4 world = rotMatrix * scaleMatrix * translateMatrix;
                Matrix4 world = transformComponent.Transform;

                ComponentTexture textureComponent = (ComponentTexture)entity.FindComponent(ComponentTypes.COMPONENT_TEXTURE);
                int texture = textureComponent.Texture;

                Draw(world, geometry, texture);
            }
        }
예제 #2
0
        public void OnAction(Entity entity)
        {
            if (camera == null)
            {
                return;
            }

            if ((entity.Mask & MASK) == MASK)
            {
                ComponentGeometry  geometryComponent = entity.GetComponent <ComponentGeometry>();
                ComponentTransform transform         = entity.transform;
                ComponentMaterial  materialComponent = entity.GetComponent <ComponentMaterial>();
                ComponentSound     sound             = entity.GetComponent <ComponentSound>();
                if (sound != null)
                {
                    AL.Source(sound.souce[0], ALSource3f.Position, ref transform.position);
                    //sound.playsoundonce(1);
                }


                Draw(transform.GetTransformMatrix(), geometryComponent.Geometry(), materialComponent);
            }
        }
예제 #3
0
        /// <summary>
        /// Procedually generates a building terrain using supplied values are lower and upper limits (for X and Y)
        /// </summary>
        /// <param name="pXmin">Thinest possible size for a building</param>
        /// <param name="pXmax">Tickest possible size for a building</param>
        /// <param name="pYmin">Lowest possible size for a building</param>
        /// <param name="pYmax">Highest possible size for a building</param>
        private void CreateSkyline(int pXmin, int pXmax, int pYmin, int pYmax)
        {
            // Creates the building prefab entities
            // Z pos = -25 from camera position to fill screen needs 50m long so 55-60m to cover
            float length = 27.5f;                       // center is 0 so far right is half the length
            float travel = -27.5f;                      // Starting point to spawn in building entities
            float Gorilla1_Y = 0.0f, Gorilla2_Y = 0.0f; // Gorilla 1 height position and horizontal position
            float Gorilla1_X = 0.0f, Gorilla2_X = 0.0f; // Gorilla 2 height position and horizontal position
            float WindowScaler = 0.5f;

            Random rnd = new Random();  // Used to find a random width and height of a building

            int EntityID = 1;

            SkylineLayout = new int[(int)pYmax * 2, 64];

            // Array to hold all textures for new building entities
            string[,] TexturesVarients = new string[, ] {
                { "building_red_off", "building_red_on" },
                { "building_blue_off", "building_blue_on" },
                { "building_gray_off", "building_gray_on" }
            };
            // Cycle through spawning in new buildings untill full screen width is filled with buildings
            while (travel < length)
            {
                float startY = -12.0f;
                // Randomise width and height of current prefab
                int width  = rnd.Next(pXmin, pXmax);
                int height = rnd.Next(pYmin, pYmax);
                // This spawn the building within the boundary using the random width (as pos is center of entity)
                //travel += (float)(width);
                // Finds a spot for the gorillas far enough in from the screen edge and finds the height to place them at later on
                if (travel > -21.0f && Gorilla1_Y == 0.0f)
                {
                    Gorilla1_Y = startY + (height * 2.0f); Gorilla1_X = travel + width;
                }
                else
                if (travel > 16.0f && Gorilla2_Y == 0.0f)
                {
                    Gorilla2_Y = startY + (height * 2.0f); Gorilla2_X = travel + width;;
                }

                float BuildingStickOut = (rnd.Next(1, 4) * 0.5f);
                int   WindowColour     = rnd.Next(3);

                /* Procedually Generate new building terrain
                 *
                 *  For every layer up (y)
                 *      For every block across the building (x)
                 *          For every block along the building (z)
                 *              Add new block cube in that spot then more over to next
                 *
                 *   This algorithm will work up layer by layer creating each floor of the building
                 *   for each floor it works across to the right 1m then through the building by 5m (z) (All buildings are 5m deep)
                 *   after all that it moves to the next one to the right and repeats above step
                 *   Once that layer is finished it moves up to the next until all upper limits are hit and a new building is made
                 *   It will then move to the next building and repeat until area is filled with buildings
                 */

                // Creates a holder variable which will be reused for each entity being created and overritten each time
                Entity newEntity;
                // These components are the same for every block in the terrain, therefore its not efficent to create new ones for each entity
                ComponentGeometry  Geo   = new ComponentGeometry("Geometry/CubeGeometry.txt");
                ComponentTransform Trans = new ComponentTransform(new Vector3(WindowScaler), new Vector3(0.0f));

                for (int y = 0; y < height / WindowScaler; y++)
                {
                    for (int x = 0; x < width / WindowScaler; x++)
                    {
                        for (int z = 0; z < 5; z++)
                        {
                            newEntity = new Entity("Building" + EntityID.ToString());
                            newEntity.AddComponent(new ComponentPosition(new Vector3(travel + x, startY + y, (-25.0f + z))));
                            newEntity.AddComponent(Trans);
                            newEntity.AddComponent(Geo);
                            // Collision detection looks at a two axis version of the map (X and Y) so adding this next line cuts out 4/5th of collision checking
                            if (z == 0)
                            {
                                newEntity.AddComponent(new ComponentCollider(false));
                            }

                            if ((z > 0 && z < 4) && (x > 0 && x < width / WindowScaler - 1))
                            {
                                newEntity.AddComponent(new ComponentTexture("Textures/" + "building_inside" + ".jpg"));
                            }
                            else
                            {
                                newEntity.AddComponent(new ComponentTexture("Textures/" + TexturesVarients[WindowColour, rnd.Next(2)] + ".jpg"));
                            }


                            entityManager.AddEntity(newEntity); // Adds new random generated entity to entitymanager
                            if (z == 0)
                            {
                                SkylineLayout[y, (int)((travel + length) + x)] = EntityID;
                            }
                            EntityID++;
                        }
                    }
                }

                travel += (float)width * 2;             // Readys position for next building
            }
            // The following code uses that found X and Y values to relocated the gorilla entities into a safe spot
            // This ensures they spawn ontop of a building at its height and are not floating or stuck inside a building
            ComponentPosition  pos;
            ComponentTransform trans;

            pos          = (ComponentPosition)entityManager.FindEntity("Gorilla1").FindComponent(ComponentTypes.COMPONENT_POSITION);
            trans        = (ComponentTransform)entityManager.FindEntity("Gorilla1").FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
            pos.Position = new Vector3(Gorilla1_X, Gorilla1_Y + trans.Transform.ExtractScale().Y - WindowScaler, pos.Position.Z);
            G1X          = Gorilla1_X;
            G1Y          = pos.Position.Y;
            pos          = (ComponentPosition)entityManager.FindEntity("Gorilla2").FindComponent(ComponentTypes.COMPONENT_POSITION);
            trans        = (ComponentTransform)entityManager.FindEntity("Gorilla2").FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
            pos.Position = new Vector3(Gorilla2_X, Gorilla2_Y + trans.Transform.ExtractScale().Y - WindowScaler, pos.Position.Z);
            G2X          = Gorilla2_X;
            G2Y          = pos.Position.Y;
        }
예제 #4
0
        private static XmlNode SaveComponentGeometry(XmlDocument file, ComponentGeometry component)
        {
            XmlNode componentNode = file.CreateElement("Geometry");

            return(null);
        }