Beispiel #1
0
    string ConvertLevelToString()
    {
        LevelDataWrite levelData = new LevelDataWrite();

        //TODO: Write level data to levelData

        // 1) Write version
        levelData.WriteString("v0.1");

        // Find all TerrainGrounds
        TerrainGround[] grounds = GameObject.FindObjectsOfType(typeof(TerrainGround)) as TerrainGround[];

        // 2) Write how many grounds there are
        levelData.WriteInt(grounds.Length);

        foreach (TerrainGround ground in grounds)
        {
            // Loop through each ground
            TerrainBlueprintType type = ground.groundPart.blueprintPart.GetTerrainBlueprintType();
            levelData.WriteInt((int)type);

            levelData.WriteInt((int)ground.style);

            // Write segment length
            levelData.WriteFloat(ground.groundPart.blueprintPart.GetSegmentLength());

            // Write points
            for (int i = 0; i < ground.groundPart.blueprintPart.GetNodeAmount(); i++)
            {
                levelData.WriteVector2((Vector2)ground.groundPart.blueprintPart.GetNodePosition(i));
            }
        }

        // Find all TerrainRollers
        TerrainRoller[] rollers = GameObject.FindObjectsOfType(typeof(TerrainRoller)) as TerrainRoller[];

        // 3) Write how many rollers there are
        levelData.WriteInt(rollers.Length);

        foreach (TerrainRoller roller in rollers)
        {
            // Loop through each roller
            TerrainBlueprintType type = roller.rollerPart.blueprintPart.GetTerrainBlueprintType();
            levelData.WriteInt((int)type);

            levelData.WriteInt((int)roller.style);
            levelData.WriteFloat(roller.spacing);
            levelData.WriteBool(roller.isFixed);
            levelData.WriteFloat(roller.speed * (int)roller.direction);              //NOTE: Multiply speed by direction to give it a sign

            // Write points
            for (int i = 0; i < roller.rollerPart.blueprintPart.GetNodeAmount(); i++)
            {
                levelData.WriteVector2((Vector2)roller.rollerPart.blueprintPart.GetNodePosition(i));
            }
        }

        return(levelData.ReadAll());
    }
Beispiel #2
0
    public TerrainInfo(TerrainBlueprintType terrainBlueprintType, TerrainGroundStyle terrainGroundStyle, float terrainGroundSegmentLength)
    {
        this.terrainBlueprintType = terrainBlueprintType;

        this.terrainType = TerrainType.Ground;

        this.terrainGroundStyle         = terrainGroundStyle;
        this.terrainGroundSegmentLength = terrainGroundSegmentLength;
    }
Beispiel #3
0
    public TerrainInfo(TerrainBlueprintType terrainBlueprintType, TerrainRollerStyle terrainRollerStyle, float terrainRollerSpacing, bool terrainRollerFixed, float terrainRollerSpeed)
    {
        this.terrainBlueprintType = terrainBlueprintType;

        this.terrainType = TerrainType.Roller;

        this.terrainRollerStyle   = terrainRollerStyle;
        this.terrainRollerSpacing = terrainRollerSpacing;
        this.terrainRollerFixed   = terrainRollerFixed;
        this.terrainRollerSpeed   = terrainRollerSpeed;
    }
Beispiel #4
0
    protected TerrainInfo InterfaceTerrainInfoToTerrainInfo(InterfaceTerrainInfo interfaceTerrainInfo)
    {
        TerrainInfo terrainInfo;

        TerrainBlueprintType terrainBlueprintType = InterfaceTerrainToolToTerrainBlueprintType(interfaceTerrainInfo.interfaceTerrainTool);

        switch (interfaceTerrainInfo.interfaceTerrainType)
        {
        case InterfaceTerrainType.Ground:

            // Ground
            TerrainGroundStyle terrainGroundStyle = InterfaceTerrainGroundStyleToTerrainGroundStyle(interfaceTerrainInfo.interfaceTerrainGroundStyle);
            float terrainGroundSegmentLength      = InterfaceTerrainGroundGrainToTerrainSegmentLength(interfaceTerrainInfo.interfaceTerrainGroundGrain);

            terrainInfo = new TerrainInfo(terrainBlueprintType, terrainGroundStyle, terrainGroundSegmentLength);

            break;

        case InterfaceTerrainType.Roller:

            //Roller
            TerrainRollerStyle terrainRollerStyle = InterfaceTerrainRollerStyleToTerrainRollerStyle(interfaceTerrainInfo.interfaceTerrainRollerStyle);
            float terrainRollerSpacing            = InterfaceTerrainRollerSpacingToTerrainRollerSpacing(interfaceTerrainInfo.interfaceTerrainRollerSpacing);
            bool  terrainRollerFixed = InterfaceTerrainRollerRotationSpeedToTerrainRollerFixed(interfaceTerrainInfo.interfaceTerrainRollerRotationSpeed);
            float terrainRollerSpeed = InterfaceTerrainRollerRotationSpeedAndInterfaceTerrainRollerRotationToTerrainRollerSpeed(interfaceTerrainInfo.interfaceTerrainRollerRotationSpeed, interfaceTerrainInfo.interfaceTerrainRollerRotationDirection);

            terrainInfo = new TerrainInfo(terrainBlueprintType, terrainRollerStyle, terrainRollerSpacing, terrainRollerFixed, terrainRollerSpeed);

            break;

        default:
            Debug.LogWarning("Invalid InterfaceTerrainType [" + interfaceTerrainInfo.interfaceTerrainType + "]. Defaulting to InterfaceTerrainType.Ground");
            goto case InterfaceTerrainType.Ground;
        }

        return(terrainInfo);
    }
Beispiel #5
0
    void GenerateLevelFromString(string levelString, bool edit)
    {
        Debug.Log("Generating level from levelString: " + levelString);

        LevelDataRead levelData = new LevelDataRead(levelString);

        //TODO: Generate level from levelData

        // 1) Read version

        string version = levelData.ReadString();

        Debug.Log("Version is: " + version);

        // 2) Read how many terrains there are
        int numTerrains = levelData.ReadInt();

        for (int t = 0; t < numTerrains; t++)
        {
            // Read type
            TerrainBlueprintType type = (TerrainBlueprintType)levelData.ReadInt();

            // Read style
            TerrainGroundStyle style = (TerrainGroundStyle)levelData.ReadInt();

            // Read segment length
            float segmentLength = levelData.ReadFloat();

            TerrainInfo        terrainInfo        = new TerrainInfo(type, style, segmentLength);
            TerrainObjectMaker terrainObjectMaker = new TerrainObjectMaker(terrainInfo);

            for (int i = 0; i < terrainObjectMaker.GetNodeAmount(); i++)
            {
                terrainObjectMaker.AddNode((Vector3)levelData.ReadVector2());
            }

            terrainObjectMaker.SetIsEditable(edit);
            terrainObjectMaker.CreateTerrain();
        }

        // 3) Read how many rollers there are
        int numRollers = levelData.ReadInt();

        for (int t = 0; t < numRollers; t++)
        {
            // Read type
            TerrainBlueprintType type = (TerrainBlueprintType)levelData.ReadInt();

            // Read style
            TerrainRollerStyle style = (TerrainRollerStyle)levelData.ReadInt();
            float spacing            = levelData.ReadFloat();
            bool  isFixed            = levelData.ReadBool();
            float speed = levelData.ReadFloat();

            TerrainInfo        terrainInfo        = new TerrainInfo(type, style, spacing, isFixed, speed);
            TerrainObjectMaker terrainObjectMaker = new TerrainObjectMaker(terrainInfo);

            for (int i = 0; i < terrainObjectMaker.GetNodeAmount(); i++)
            {
                terrainObjectMaker.AddNode((Vector3)levelData.ReadVector2());
            }

            terrainObjectMaker.SetIsEditable(edit);
            terrainObjectMaker.CreateTerrain();
        }
    }