示例#1
0
    // Load a ship hull animation set
    // Note: this is the only LoadXYZ function that does NOT do the internal group type check
    private BaseShip_Hull LoadHullType(ConfigFile Info, String GroupName)
    {
        // Alloc a new hull
        BaseShip_Hull Hull = new BaseShip_Hull();

        // Load the animation basics
        Hull.Pos = Info.GetKey_Vector2(GroupName, "Pos");
        Hull.Size = Info.GetKey_Vector2(GroupName, "Size");
        Hull.FrameCount = Info.GetKey_Int(GroupName, "Count");
        Hull.FrameTime = Info.GetKey_Float(GroupName, "Time");

        // All done!
        return Hull;
    }
示例#2
0
    /*** Public ***/
    // Standard constructor: needs to have a paried config file name
    // which should implement all of the groups and key-value pairs
    // found in the ship demo config file
    public BaseShip(String ConfigFileName)
    {
        // Load the ship's properties
        this.ConfigFileName = ConfigFileName;
        ConfigFile Info = new ConfigFile(ConfigFileName);

        /*** General Init. ***/

        // Save the health components
        ShieldHealth = ShieldMaxHealth = Info.GetKey_Int("General", "Shield");
        HullHealth = HullMaxHealth = Info.GetKey_Int("General", "Hull");

        // Save velicity limit and default pos to center
        MaxVelocity = Info.GetKey_Vector2("General", "MaxVelocity");
        ShipAcceleration = new Vector2();
        ShipVelocity = new Vector2();
        ShipPosition = new Vector3();

        // Get all group names to load up specialty geometry
        String TextureName = Info.GetKey_String("General", "Texture");
        String[] GroupNames = Info.GetGroupNames();

        /*** Frame, Shield & Hull ***/

        // For each group, look just for "Frame" and "Shield"
        foreach(String GroupName in GroupNames)
        {
            // If shield
            if(GroupName.ToLower().StartsWith("shield") == true)
            {
                // Get animation / frame info
                ShieldAnimation = LoadHullType(Info, GroupName);

                // Register the sprite with the sprite manager
                ShieldSprite = new Sprite("Textures/" + TextureName);
                ShieldSprite.SetAnimation(ShieldAnimation.Pos, ShieldAnimation.Size, ShieldAnimation.FrameCount, ShieldAnimation.FrameTime);
                ShieldSprite.SetGeometrySize(ShieldSprite.GetSpriteSize());
                ShieldSprite.SetRotationCenter(ShieldSprite.GetGeometrySize() / 2.0f);
                ShieldSprite.SetDepth(Globals.ShieldDepth);
                Globals.WorldView.SManager.AddSprite(ShieldSprite);
            }
            // Elif base frame
            else if(GroupName.ToLower().StartsWith("frame") == true)
            {
                // Get animation / frame info
                FrameAnimation = LoadHullType(Info, GroupName);

                // Register the sprite with the sprite manager
                FrameSprite = new Sprite("Textures/" + TextureName);
                FrameSprite.SetAnimation(FrameAnimation.Pos, FrameAnimation.Size, FrameAnimation.FrameCount, FrameAnimation.FrameTime);
                FrameSprite.SetGeometrySize(FrameSprite.GetSpriteSize());
                FrameSprite.SetRotationCenter(FrameSprite.GetGeometrySize() / 2.0f);
                FrameSprite.SetDepth(Globals.FrameDepth);
                Globals.WorldView.SManager.AddSprite(FrameSprite);
            }
        }

        // Load all the hulls
        HullList = new List<BaseShip_Hull>();
        foreach(String GroupName in GroupNames)
        {
            if(GroupName.ToLower().StartsWith("hull") == true)
            {
                BaseShip_Hull Hull = LoadHullType(Info, GroupName);
                HullList.Add(Hull);
            }
        }

        // Default to initial hull
        HullSprite = new Sprite("Textures/" + TextureName);
        HullSkinIndex = 0; // Index grows while health goes down
        BaseShip_Hull HullAnimation = HullList[HullSkinIndex];

        HullSprite.SetAnimation(HullAnimation.Pos, HullAnimation.Size, HullAnimation.FrameCount, HullAnimation.FrameTime);
        HullSprite.SetGeometrySize(HullSprite.GetSpriteSize());
        HullSprite.SetRotationCenter(HullSprite.GetGeometrySize() / 2.0f);
        HullSprite.SetDepth(Globals.HullDepth);
        Globals.WorldView.SManager.AddSprite(HullSprite);

        /*** Contrails ***/

        // Load all contrails
        ContrailList = new List<BaseShip_Contrail>();
        foreach(String GroupName in GroupNames)
        {
            BaseShip_Contrail NewContrail = LoadContrail(Info, GroupName);
            if(NewContrail != null)
                ContrailList.Add(NewContrail);
        }

        /*** Weapons ***/

        // Load all weapons
        WeaponsList = new List<BaseShip_Weapon>();
        foreach(String GroupName in GroupNames)
        {
            BaseShip_Weapon NewWeapon = LoadWeapon(Info, GroupName);
            if(NewWeapon != null)
                WeaponsList.Add(NewWeapon);
        }

        /*** Animation Entities ***/

        // Load all animations
        DetailsList = new List<BaseShip_Detail>();
        foreach(String GroupName in GroupNames)
        {
            BaseShip_Detail Detail = LoadDetail(Info, GroupName);
            if(Detail != null)
                DetailsList.Add(Detail);
        }

        /*** Misc. ***/

        // Chunk count
        foreach(String GroupName in GroupNames)
        {
            if(GroupName.ToLower().StartsWith("chunk"))
                ChunkCount++;
        }

        // Generate unique ship name
        NameGenerator NameGen = new NameGenerator();
        ShipName = NameGen.generateName();
    }