Example #1
0
    public TurretBuilding(string configName)
        : base(configName)
    {
        ConfigFile config = new ConfigFile(configName);

        m_AlertRadius = config.GetKey_Float("Turret", "AlertRadius");
        m_FireRadius = config.GetKey_Float("Turret", "FireRadius");

        int numGuns = config.GetKey_Int("Turret", "NumGuns");
        BaseShip_Weapon currWeapon = null;
        string gunGroup = "Gun";
        string gunType = "";

        for(int i = 0; i < numGuns; ++i)
        {
            gunGroup += (i+1).ToString();
            gunType = config.GetKey_String(gunGroup, "Type");

            currWeapon = new BaseShip_Weapon();
            //currWeapon.CanRotate = ((config.GetKey_Int(gunGroup, "CanRotate") == 1) ? true : false);

            currWeapon.CoolDownRate = config.GetKey_Float(gunType , "CoolDown");;
            currWeapon.Position = config.GetKey_Vector2(gunGroup, "Pos");

            currWeapon.WeaponSprite = new Sprite("Textures/" + config.GetKey_String(gunType, "Texture"));
            currWeapon.WeaponSprite.SetSpriteSize(currWeapon.WeaponSprite.GetTextureSize());//config.GetKey_Vector2(gunGroup, "Size"));

            currWeapon.WeaponSprite.SetSpritePos(Position);
            currWeapon.WeaponSprite.SetGeometrySize(currWeapon.WeaponSprite.GetSpriteSize() / 2);
            currWeapon.WeaponSprite.SetRotationCenter(currWeapon.WeaponSprite.GetGeometrySize() / 2.0f);
            currWeapon.WeaponSprite.SetDepth(Globals.WeaponsDepth);

            Globals.WorldView.SManager.AddSprite(currWeapon.WeaponSprite);

            gunType.ToLower();
            if(gunType == "gatling")
                currWeapon.WeaponType = BaseShip_WeaponTypes.Gatling;
            else if(gunType == "rail")
                currWeapon.WeaponType = BaseShip_WeaponTypes.RailGun;
            else if(gunType == "missile")
                currWeapon.WeaponType = BaseShip_WeaponTypes.Missile;
            else
                currWeapon.WeaponType = BaseShip_WeaponTypes.Laser;

            m_Guns.Add(currWeapon);
        }

        Sprite.SetDepth(Globals.BuildingDepth);
    }
Example #2
0
    // Load a weapon based on the current group name (and does the internal sprite loading too)
    private BaseShip_Weapon LoadWeapon(ConfigFile Info, String GroupName)
    {
        // Ignore if not weapon
        if(GroupName.ToLower().StartsWith("weapon") == false)
            return null;

        // Load from config files
        BaseShip_Weapon Weapon = new BaseShip_Weapon();
        String Type = Info.GetKey_String(GroupName, "Type");
        Weapon.Position = Info.GetKey_Vector2(GroupName, "Pos");

        // Get sprite info
        ConfigFile SpriteInfo = new ConfigFile("Config/Weapons/WeaponsConfig");

        String TextureName = SpriteInfo.GetKey_String(Type, "Texture");
        Weapon.CoolDownRate = SpriteInfo.GetKey_Float(Type, "CoolDown");
        Vector2 SPos = SpriteInfo.GetKey_Vector2(Type, "Pos");
        Vector2 SSize = SpriteInfo.GetKey_Vector2(Type, "Size");
        //Vector2 SCenter = SpriteInfo.GetKey_Vector2(Type, "Center"); // Todo, so we rotate about a point, not center
        int SCount = SpriteInfo.GetKey_Int(Type, "Count");
        float STime = SpriteInfo.GetKey_Float(Type, "Time");

        // Load the sprite
        Weapon.WeaponSprite = new Sprite("Textures/" + TextureName);

        Weapon.WeaponSprite.SetSpritePos(SPos);
        Weapon.WeaponSprite.SetSpriteSize(SSize);
        Weapon.WeaponSprite.SetGeometrySize(Weapon.WeaponSprite.GetSpriteSize());

        Weapon.WeaponSprite.SetRotationCenter(Weapon.WeaponSprite.GetGeometrySize() / 2.0f);

        // Set animation (if any)
        Weapon.WeaponSprite.SetAnimation(SPos, SSize, SCount, STime);

        // Right above regular ships
        Weapon.WeaponSprite.SetDepth(Globals.WeaponsDepth);

        // Register with renderer
        Globals.WorldView.SManager.AddSprite(Weapon.WeaponSprite);

        // Weapon type
        String WeaponType = SpriteInfo.GetKey_String(Type, "Projectile");
        if(WeaponType.ToLower().CompareTo("gatling") == 0)
            Weapon.WeaponType = BaseShip_WeaponTypes.Gatling;
        else if(WeaponType.ToLower().CompareTo("laser") == 0)
            Weapon.WeaponType = BaseShip_WeaponTypes.Laser;
        else if(WeaponType.ToLower().CompareTo("missile") == 0)
            Weapon.WeaponType = BaseShip_WeaponTypes.Missile;
        else if(WeaponType.ToLower().CompareTo("railgun") == 0)
            Weapon.WeaponType = BaseShip_WeaponTypes.RailGun;

        // All done!
        return Weapon;
    }