Exemple #1
0
 public StructureType(string name, int typeid, string path, GridVector size)
 {
     SName     = name;
     TypeID    = typeid;
     ScenePath = path;
     Size      = size;
 }
Exemple #2
0
        public void FinalizeNodeCreation(StructureType type, GridVector position)
        {
            //Node size
            float posmultiplier = 16;

            //Position multiplier, 1 node = 16 units;
            SName     = type.SName;
            TypeID    = type.TypeID;
            GSize     = type.Size;
            GPosition = position;
            Vector2 newPosition = new Vector2(GPosition.x * posmultiplier, GPosition.y * posmultiplier);

            SetPosition(newPosition);
        }
Exemple #3
0
        public bool CanFitStructureHere(StructureType type, GridVector position)
        {
            bool Result = true;

            for (int y = position.y; y < position.y + type.Size.y; y++)
            {
                for (int x = position.x; x < position.x + type.Size.x; x++)
                {
                    if (TypeIdMap[x, y] != 0)
                    {
                        Result = false;
                    }
                }
            }
            return(Result);
        }
Exemple #4
0
        //Create structure with a type at coordinates
        public void CreateStructure(GridVector position, StructureType type)
        {
            if (CurrentSMap.CanFitStructureHere(type, position))
            {
                //Creating structure
                //Packing structure scene
                var packedStructure = (PackedScene)ResourceLoader.Load(type.ScenePath);
                //Instansing
                var instancedNode = packedStructure.Instance();
                //Adding structure node to the StructManager
                AddChild(instancedNode, true);

                var structure = (Structure)(instancedNode.GetNode(""));
                structure.FinalizeNodeCreation(type, position);
                CurrentSMap.AddStructure(structure);
            }
            else
            {
                GD.Print("SManager: i cant fit structure here, thats strange!");
            }
        }