Ejemplo n.º 1
0
        private static void AddTile(int x, int y, int tileSize, PCNComponent blueprint, EntityLayer entities, string blueprintName)
        {
            Vector2 position = new Vector2((x + 0.5f) * tileSize, (y + 0.5f) * tileSize);
            Entity  entity   = EntityFactory.AssembleEntity(blueprint, blueprintName);

            entity.Position = position;
            entity.Properties.Ints["isTile"] = 1;
            entities.AddComponent(entity);
        }
Ejemplo n.º 2
0
        private static void SpawnEntity(EntityLayer layer, int entityIndex, int x, int y)
        {
            if (entityIndex < 0 || entityIndex >= classes.Length || classes[entityIndex] == null)
            {
                return;
            }
            Vector2 position = new Vector2((x + 0.5f) * tileSize, (y + 0.5f) * tileSize);
            Entity  entity   = (Entity)Activator.CreateInstance(classes[entityIndex], position);

            layer.AddComponent(entity);
        }
Ejemplo n.º 3
0
        private static void ParseEntity(string description, EntityLayer entities)
        {
            string       listName  = entities.Properties.GetString("entityList", "");
            PCNComponent instance  = new PCNComponent(description);
            PCNComponent blueprint = EntityLists[listName][instance.Name];
            Entity       entity    = EntityFactory.BuildInstance(blueprint, instance, instance.Name);

            if (entity.Properties.GetBoolean("use_blueprint", false))
            {
                entity.Properties.SetBoolean("use_blueprint", false);
            }
            entities.AddComponent(entity);
        }
Ejemplo n.º 4
0
        private void MouseLeftDownTiles()
        {
            EntityLayer entities = layers[currentLayer].Layer as EntityLayer;

            if (entities != null)
            {
                int x     = (int)Math.Floor(mousePosition.X / layers[currentLayer].TileSize);
                int y     = (int)Math.Floor(mousePosition.Y / layers[currentLayer].TileSize);
                int index = x + y * tilesX;
                if (index >= 0 && index < tileMap.Length)
                {
                    if (drawingType != null)
                    {
                        if (tileMap[index] != null && tileMap[index].GetType() != drawingType.GetType())
                        {
                            tileMap[index].Destroyed = true;
                            entities.RemoveComponent(tileMap[index]);
                            tileMap[index] = null;
                        }

                        if (tileMap[index] == null)
                        {
                            Entity entity = EntityFactory.AssembleEntity(drawingType, drawingEntity.Properties.GetString(EntityFactory.PROPERTY_NAME_BLUEPRINT, ""));
                            entity.Position = SnapPosition(mousePosition);
                            entity.Properties.Ints["isTile"] = 1;
                            entities.AddComponent(entity);
                            tileMap[index] = entity;
                        }
                    }
                    else
                    {
                        if (tileMap[index] != null)
                        {
                            tileMap[index].Destroyed = true;
                            entities.RemoveComponent(tileMap[index]);
                            tileMap[index] = null;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
 private void MouseLeftDownEntities()
 {
     if (hoveringEntity != null) //Selecting
     {
         mouseOffset    = hoveringEntity.Position - mousePosition;
         selectedEntity = hoveringEntity;
         string blueprintName = selectedEntity.Properties.GetString(EntityFactory.PROPERTY_NAME_BLUEPRINT, "");
         drawingType            = layers[currentLayer].EntityList[blueprintName];
         drawingEntity          = EntityFactory.AssembleEntity(drawingType, blueprintName);
         drawingEntity.Position = mousePosition;
         CopyProperties(selectedEntity, drawingEntity);
         //Randomize the seed if there is any
         if (drawingEntity.Properties.GetInt("Seed", -1) > 0)
         {
             drawingEntity.Properties.Ints["Seed"] = PhantomGame.Randy.Next(int.MaxValue);
             drawingEntity.HandleMessage(Messages.PropertiesChanged, null);
         }
     }
     else if (drawingType != null) //Drawing
     {
         EntityLayer entities      = layers[currentLayer].Layer as EntityLayer;
         string      blueprintName = drawingEntity.Properties.GetString(EntityFactory.PROPERTY_NAME_BLUEPRINT, "");
         selectedEntity          = EntityFactory.AssembleEntity(drawingType, blueprintName);
         selectedEntity.Position = mousePosition;
         entities.AddComponent(selectedEntity);
         hoveringEntity = selectedEntity;
         CopyProperties(drawingEntity, selectedEntity);
         mouseOffset *= 0;
         //Randomize the seed if there is any
         if (drawingEntity.Properties.GetInt("Seed", -1) > 0)
         {
             drawingEntity.Properties.Ints["Seed"] = PhantomGame.Randy.Next(int.MaxValue);
             drawingEntity.HandleMessage(Messages.PropertiesChanged, null);
         }
     }
 }