Пример #1
0
        public GameObject(string name, Texture2D texture, int rows, int columns)
        {
            _CommandQueue = new Dictionary <string, Command>();
            _Animations   = new Dictionary <string, Animation>();
            _Structure    = new DrawStructure
            {
                Name         = name,
                SpriteSheet  = new SpriteSheet(texture, rows, columns),
                Position     = Vector2.Zero,
                Scale        = Vector2.One,
                ScaleModifer = 1.0f,
                LayerDepth   = 0f,
                Tint         = Color.White,
                Effects      = SpriteEffects.None
            };

            _Motion = new MotionStructure
            {
                LinearVelocity     = Vector2.Zero,
                LinearForce        = 0f,
                Rotation           = 0f,
                RotationalVelocity = 0f,
                RotationalModifer  = 0f,
                RotationalForce    = 0f
            };
        }
Пример #2
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);

            GameServices.AddService <GraphicsDevice>(graphics.GraphicsDevice);
            GameServices.AddService <SpriteBatch>(spriteBatch);
            GameServices.AddService <ContentManager>(Content);

            SpriteSturcture spriteSturcture = new SpriteSturcture("player", "Player", 2, 3);
            MotionStructure motionStructure = new MotionStructure(Center, 300f);
            DrawStructure   drawStructure   = new DrawStructure(Vector2.One, 0f, Color.White, SpriteEffects.None, 1.0f);
            Animation       animation       = new Animation("Flash", new List <int> {
                1, 2, 3, 4, 5, 6
            }, 10);
            AnimationStructure animationStructure = new AnimationStructure(animation);

            GameObject gameObject = new GameObject(spriteSturcture, motionStructure, drawStructure, animationStructure);

            GameContent.AddObject(gameObject);
        }
Пример #3
0
    public void DrawStructure(DrawStructure choices, Structure structure, Vect3 structureMiddlePoint)
    {
        GameObject structureObject = new GameObject("Structure");

        for (int componentIndex = 0; componentIndex < structure.components.Count; componentIndex++)
        {
            GameObject componentObject = new GameObject(string.Format("Component {0}", componentIndex));
            componentObject.transform.parent = structureObject.transform;
            Nodegraph_Generator.Component component = structure.components[componentIndex];

            // To prepare color
            List <int>       floorFaces = ComponentGraphGenerator.GetFloorFaces(component);
            LinkedList <int> linkedList = ComponentGraphGenerator.GetShellVertices(component, floorFaces);
            (LinkedList <int>, LinkedList <int>)sidePair = ComponentGraphGenerator.SplitLinkedList(component, linkedList);

            if (choices.drawVertices)
            {
                GameObject verticesObject = new GameObject(string.Format("Component {0}, Vertices", componentIndex));
                verticesObject.transform.parent = componentObject.transform;
                for (int vertexIndex = 0; vertexIndex < component.vertices.Count; vertexIndex++)
                {
                    Vertex     vertex         = component.GetVertex(vertexIndex);
                    Vect3      vertexPosition = Utilities.GetScaledTransletedVect3(vertex.coordinate, structureMiddlePoint, scalingFactor);
                    GameObject vertexObject   = Utilities.DrawObject(vertexPrefab, vertexPosition, verticesObject);
                    vertexObject.name = string.Format("Vertex {0}", vertexIndex);
                    if (choices.colorFloor)
                    {
                        if (sidePair.Item1.Contains(vertexIndex))
                        {
                            Utilities.ColorObject(vertexObject, Color.blue);
                        }
                        else if (sidePair.Item2.Contains(vertexIndex))
                        {
                            Utilities.ColorObject(vertexObject, Color.red);
                        }
                    }
                }
            }

            if (choices.drawFaces)
            {
                var        drawnVertexPairs = new List <(int, int)>();
                var        drawnFaceSides   = new List <GameObject>();
                GameObject faces            = new GameObject(string.Format("Component {0}, Faces", componentIndex));
                faces.transform.parent = componentObject.transform;
                for (int faceIndex = 0; faceIndex < component.faces.Count; faceIndex++)
                {
                    Face face            = component.GetFace(faceIndex);
                    var  faceMiddlepoint = new Vect3();
                    for (int i = 0; i < face.vertexIndices.Length; i++)
                    {
                        int    firstVertexIndex = face.vertexIndices[i];
                        Vertex firstVertex      = component.GetVertex(firstVertexIndex);
                        faceMiddlepoint += firstVertex.coordinate;
                        for (int j = i + 1; j < face.vertexIndices.Length; j++)
                        {
                            int secondVertexIndex = face.vertexIndices[j];
                            if (!(drawnVertexPairs.Contains((firstVertexIndex, secondVertexIndex)) ||
                                  drawnVertexPairs.Contains((secondVertexIndex, firstVertexIndex))))
                            {
                                Vertex secondVertex = component.GetVertex(secondVertexIndex);
                                Vect3  startPos     = Utilities.GetScaledTransletedVect3(firstVertex.coordinate,
                                                                                         structureMiddlePoint, scalingFactor);
                                Vect3 endPos = Utilities.GetScaledTransletedVect3(secondVertex.coordinate,
                                                                                  structureMiddlePoint, scalingFactor);
                                GameObject faceSideObject = Utilities.DrawLine(startPos, endPos, faces);
                                faceSideObject.name = string.Format("Faceside to Face {0}", faceIndex);
                                Utilities.ColorObject(faceSideObject,
                                                      (choices.colorFloor && floorFaces.Contains(faceIndex)) ? Color.green : Color.black);
                                drawnVertexPairs.Add((secondVertexIndex, firstVertexIndex));
                                drawnFaceSides.Add(faceSideObject);
                            }
                            else
                            {
                                GameObject faceSideObject = drawnFaceSides[drawnVertexPairs.FindIndex(a =>
                                                                                                      (a.Item1 == firstVertexIndex && a.Item2 == secondVertexIndex) || (a.Item1 == secondVertexIndex && a.Item2 == firstVertexIndex))];
                                if (choices.colorFloor && floorFaces.Contains(faceIndex))
                                {
                                    Utilities.ColorObject(faceSideObject, Color.green);
                                }
                                faceSideObject.name += ", " + faceIndex;
                            }
                        }
                    }
Пример #4
0
 public GameObject(SpriteSturcture spriteSturcture, MotionStructure motionStructure, DrawStructure drawStructure, AnimationStructure animationStructure) : base(spriteSturcture, motionStructure, drawStructure, animationStructure)
 {
     Generic = (GameObject)base.MemberwiseClone();
 }