LevelModelComponent createLevelComponent(CreateLevelComponent createLevel)
    {
        LevelModelComponent component = getLevelModelIfExists(createLevel.level);
        if (component == null)
        {
            component = Utils.Deserialize<LevelModelComponent>(createLevel.level.ToString());
            pool.CreateEntity()
                .AddComponent(ComponentIds.LevelModel, component);
        }
        component.enemyIndex = 0;
        component.waveIndex = 0;

        pool.CreateEntity()
            .AddEnemySpawner(component);
        return component;
    }
示例#2
0
    public void Execute(List <Entity> entities)
    {
        Entity e = entities.SingleEntity();

        CreateLevelComponent createLevel = e.createLevel;
        XmlNode node = Utils.LoadXml(createLevel.level.ToString());

        XmlNode enemyNode = node.FirstChild;

        _pool.CreateEntity()
        .AddEnemySpawner(createLevel.level, false, enemyNode.FirstChild);

        XmlNode sizeNode = enemyNode.NextSibling;
        XmlAttributeCollection attributes = sizeNode.Attributes;

        float x = (float)Convert.ToDouble(attributes[0].Value);
        float y = (float)Convert.ToDouble(attributes[1].Value);

        Entity cameraEntity = _cameras.GetSingleEntity();

        if (!cameraEntity.hasSnapPosition)
        {
            float width  = (float)Convert.ToDouble(attributes [2].Value);
            float height = (float)Convert.ToDouble(attributes [3].Value);
            cameraEntity.AddSnapPosition(x, y, width, height, false);
        }

        Entity player = _players.GetSingleEntity();

        if (!player.hasSnapPosition)
        {
            Camera camera       = cameraEntity.camera.camera;
            float  screenWidth  = camera.orthographicSize * camera.aspect * 2.0f;
            float  screenHeight = camera.orthographicSize * 2.0f;
            player.AddSnapPosition(x, y, screenWidth, screenHeight, true);
        }

        createBonuses(sizeNode.NextSibling);
    }