Example #1
0
    // Add an explosion into the list (will remove self once complete)
    public void AddExplosion(Vector2 Position)
    {
        // Allocate and register the new sprite, starting with the explosion
        // Note: slight randomization to add effect
        Sprite Explosion = new Sprite("Textures/ExplosionSprite" + UnityEngine.Random.Range(0, 2)); // [0, 1]
        Explosion.SetPosition(Position);
        Explosion.SetAnimation(Vector2.zero, new Vector2(20, 20), 7, 0.06f + UnityEngine.Random.Range(-0.01f, 0.05f));
        Explosion.SetGeometrySize(Explosion.GetSpriteSize() * (0.6f + UnityEngine.Random.Range(-0.2f, 0.2f)));
        Explosion.SetRotationCenter(Explosion.GetGeometrySize() / UnityEngine.Random.Range (1.0f, 2.0f));
        Explosion.SetRotation(UnityEngine.Random.Range(0.0f, 2.0f * Mathf.PI));
        Explosion.SetDepth(Globals.ExplosionDepth);

        // Register to renderer and list
        Globals.WorldView.SManager.AddSprite(Explosion);
        Explosions.Add(Explosion);

        // Add explosion audio
        int Index = UnityEngine.Random.Range(1, 4); // [1, 4)
        Globals.WorldView.AManager.PlayAudio(Position, "Explosion" + Index);
    }
Example #2
0
    public BaseBuilding(string configFilename)
    {
        ConfigFile config = new ConfigFile(configFilename);

        m_Name = config.GetKey_String("General", "Name");
        m_MaxHealth = m_Health = config.GetKey_Int("General", "Health");
        m_Armor = config.GetKey_Int("General", "Armor");
        m_ConsumptionRate = config.GetKey_Float("General", "ConsumptionRate");
        m_MaxUpgradeLevels = config.GetKey_Int("General", "MaxUpgradeLevels");
        m_UpgradeMagnitude = config.GetKey_Int("General", "UpgradeMagnitude");
        m_MaxConnDist = config.GetKey_Float("General", "MaxConnDist");
        m_MinConnDist = config.GetKey_Float("General", "MinConnDist");

        Vector2 tempPrice = config.GetKey_Vector2("General", "Price");
        m_MineralPrice = (int)tempPrice.x;
        m_GasPrice = (int)tempPrice.y;

        m_Sprite = new Sprite("Textures/" + config.GetKey_String("General", "Texture"));
        m_Sprite.SetGeometrySize(config.GetKey_Vector2("General", "Size"));
        m_Sprite.SetRotationCenter(m_Sprite.GetGeometrySize() / 2);

        Globals.WorldView.SManager.AddSprite(m_Sprite);
    }
Example #3
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();
    }
Example #4
0
    // Given a sprite model, generate the internal VBO mesh
    private __SpriteModel GenerateMesh(Sprite SpriteObj)
    {
        // A square mesh should always be defined in this way:
        //  ^  2 ___ 3     Triangle 1: 0, 2, 1 (turns into the screen)
        //  |   |\  |      Triangle 2: 2, 3, 1
        // y+  0|_\|1
        // x+ ----->
        __SpriteModel Model = new __SpriteModel();

        // 0. Get default color
        Model.UniformColor = SpriteObj.GetColor();

        // 1. Apply size (so we can scale first)
        Model.Vertices[0] = new Vector2(0, 0);
        Model.Vertices[1] = new Vector2(SpriteObj.GetGeometrySize().x, 0);
        Model.Vertices[2] = new Vector2(0, SpriteObj.GetGeometrySize().y);
        Model.Vertices[3] = new Vector2(SpriteObj.GetGeometrySize().x, SpriteObj.GetGeometrySize().y);

        // 2. Rotate
        float Theta = SpriteObj.GetRotation();
        for(int i = 0; i < 4; i++)
        {
            Vector2 Point = new Vector2(Model.Vertices[i].x, Model.Vertices[i].y);
            Point -= SpriteObj.GetRotationCenter();
            Model.Vertices[i].x = Point.x * Mathf.Cos(Theta) - Point.y * Mathf.Sin(Theta);
            Model.Vertices[i].y = Point.y * Mathf.Cos(Theta) + Point.x * Mathf.Sin(Theta);
        }

        // 3. Translate to position
        for(int i = 0; i < 4; i++)
            Model.Vertices[i] += new Vector3(SpriteObj.GetPosition().x, SpriteObj.GetPosition().y, SpriteObj.GetDepth());

        // 4. Copy over the UV values
        // Normalize the frame and offset values
        Vector2 TextureSize = SpriteObj.GetTextureSize();
        Vector2 NormalizedFrame = new Vector2(SpriteObj.GetSpriteSize().x / TextureSize.x, SpriteObj.GetSpriteSize().y / TextureSize.y);
        Vector2 NormalizedPos = new Vector2(SpriteObj.GetSpritePos().x / TextureSize.x, SpriteObj.GetSpritePos().y / TextureSize.y);

        // ***We need to take image coordinaes (top-left origin) and transform them to bottom-left origin

        // UV origin is from the bottom-left
        NormalizedPos.y = 1 - NormalizedPos.y;
        NormalizedPos.y -= NormalizedFrame.y;

        // Compute final UVs
        Model.UVs[0] = new Vector2(NormalizedPos.x, NormalizedPos.y);
        Model.UVs[1] = new Vector2(NormalizedPos.x + NormalizedFrame.x, NormalizedPos.y);
        Model.UVs[2] = new Vector2(NormalizedPos.x, NormalizedPos.y + NormalizedFrame.y);
        Model.UVs[3] = new Vector2(NormalizedPos.x + NormalizedFrame.x, NormalizedPos.y + NormalizedFrame.y);

        // If the texture is flipped, just swap 0 <-> 1 and 2 <-> 3
        if(SpriteObj.GetFlipped())
        {
            Vector2 temp = Model.UVs[0];
            Model.UVs[0] = Model.UVs[1];
            Model.UVs[1] = temp;

            temp = Model.UVs[2];
            Model.UVs[2] = Model.UVs[3];
            Model.UVs[3] = temp;
        }

        // Done!
        return Model;
    }
Example #5
0
    // Add glow ontop of what is being fired
    public void AddGlow(Vector2 Position)
    {
        // Sprite info
        Vector2 GlowPos = ProjectileInfo.GetKey_Vector2("Glow", "Pos");
        Vector2 GlowSize = ProjectileInfo.GetKey_Vector2("Glow", "Size");

        // Allocate and register the new sprite
        // Note: slight randomization to add effect
        Sprite Explosion = new Sprite("Textures/Projectiles");
        Explosion.SetAnimation(GlowPos, GlowSize, 1, 1.0f);

        // Set in-world properties
        Explosion.SetPosition(Position);
        Explosion.SetGeometrySize(Explosion.GetSpriteSize() * (0.6f + UnityEngine.Random.Range(-0.2f, 0.2f)));
        Explosion.SetRotationCenter(Explosion.GetGeometrySize() / 2.0f);
        Explosion.SetRotation(UnityEngine.Random.Range(0.0f, 2.0f * Mathf.PI));
        Explosion.SetDepth(Globals.ExplosionDepth);

        // Register to renderer and list
        Globals.WorldView.SManager.AddSprite(Explosion);
        Glow.Add(Explosion);
    }