예제 #1
0
    /*** Public Methods ***/
    // Add new mineral
    public void AddMineral(Vector2 Position, float Radius, int MineralCount)
    {
        SceneryManager_Scenery SceneryItem = new SceneryManager_Scenery();

        SceneryItem.Type = SceneryType.Mineral;
        SceneryItem.Radius = Radius;
        SceneryItem.MineralPos = Position;
        SceneryItem.Minerals = SceneryItem.MaxMinerals = MineralCount;

        SceneryList.Add(SceneryItem);
    }
예제 #2
0
    public void AddScenery(String ConfigFileName, String GroupName, Vector3 Position, Vector3 Velocity)
    {
        // Load the config file name
        ConfigFile Info = new ConfigFile(ConfigFileName);
        String TypeString = Info.GetKey_String(GroupName, "Type");

        if(TypeString == null)
            TypeString = "hull"; // Force hull usage
        else
            TypeString = TypeString.ToLower();

        // Get texture name from group, if it does not exist in the group, get it from the general:texture tag
        String TextureName = Info.GetKey_String(GroupName, "Texture");
        if(TextureName == null)
            TextureName = Info.GetKey_String("General", "Texture");

        // If no texture name, complete failure
        if(TextureName == null)
            Debug.LogError("Unable to load texture for given scenery item");

        // Set common properties
        SceneryManager_Scenery SceneryItem = new SceneryManager_Scenery();
        SceneryItem.ScenerySprite = new Sprite("Textures/" + TextureName);

        SceneryItem.ScenerySprite.SetSpritePos(Info.GetKey_Vector2(GroupName, "Pos"));
        SceneryItem.ScenerySprite.SetSpriteSize(Info.GetKey_Vector2(GroupName, "Size"));
        SceneryItem.ScenerySprite.SetGeometrySize(SceneryItem.ScenerySprite.GetSpriteSize());
        SceneryItem.ScenerySprite.SetRotationCenter(SceneryItem.ScenerySprite.GetGeometrySize() / 2.0f);
        SceneryItem.ScenerySprite.SetPosition(Position);
        SceneryItem.ScenerySprite.SetRotation(Position.z);
        SceneryItem.ScenerySprite.SetDepth(Globals.JunkDepth);

        // If mineral
        if(TypeString.CompareTo("mineral") == 0)
        {
            SceneryItem.Type = SceneryType.Mineral;

            SceneryItem.Minerals = SceneryItem.MaxMinerals = Info.GetKey_Int(GroupName, "Resources");
            SceneryItem.Radius = Info.GetKey_Float(GroupName, "Radius");

            // No rotation for minerals
            SceneryItem.Velocity = new Vector3(0, 0, Velocity.z);
        }
        // Else, junk
        else if(TypeString.CompareTo("junk") == 0)
        {
            SceneryItem.Type = SceneryType.Junk;

            SceneryItem.Velocity = Velocity;
        }
        // Else, hull
        else if(TypeString.CompareTo("hull") == 0)
        {
            SceneryItem.Type = SceneryType.Hull;

            SceneryItem.Age = 0.0f;
            SceneryItem.MaxAge = 3.0f;

            SceneryItem.Velocity = Velocity;
        }

        // Add scenery
        SceneryList.Add(SceneryItem);
        Globals.WorldView.SManager.AddSprite(SceneryItem.ScenerySprite);
    }
예제 #3
0
    // Ship logic
    public override void Update(float dT)
    {
        // Call the base implementation first
        base.Update(dT);

        // Grow our internal timer
        TotalTime += dT;

        // If we have no target resource and we are looking for minerals,
        // find the closest to the base's position
        if(TargetResource == null && MineralCount < MaxMineralCount)
            TargetResource = Globals.WorldView.SceneManager.GetClosestScenery(GetPosition(), SceneryType.Mineral);

        // If we do have a resource we can go to, move towards it
        if(TargetResource != null)
        {
            // Move towards resource if we are empty / collecting
            if(MineralCount < MaxMineralCount)
            {
                // Target position & radius
                Vector2 TargetPos = TargetResource.ScenerySprite.GetPosition();
                float Radius = TargetResource.Radius;

                // We want the ship to rotate over time, so move the target
                // very slowely around the target. Also note we make this radius
                // a bit smaller to allow the ship to be within the radius to allow mining
                const float RotSpeed = 0.3f;
                const float RotDist = 0.6f;
                TargetPos += new Vector2(Radius * Mathf.Cos(TotalTime * RotSpeed) * RotDist, Radius * Mathf.Sin(TotalTime * RotSpeed) * RotDist);
                UpdateBeam(true, TargetPos);

                // Tell the ship to move towards taget position over time
                MoveTowards(TargetPos, dT);

                // Are we close enough to collect resources?
                float Dist = (TargetPos - GetPosition()).magnitude;
                if(Dist <= Radius)
                {
                    // Grow collection timer, and increase resource when appropriate
                    // Updates every second
                    CollectionTimer += dT;
                    if(CollectionTimer > 1.0f)
                    {
                        // Reset timer, add resource
                        CollectionTimer -= 1.0f;
                        MineralCount += CollectionRate;

                        // Remove that much from resource
                        TargetResource.Minerals -= CollectionRate;

                        // Min/max the values
                        if(TargetResource.Minerals < 0)
                            TargetResource.Minerals = 0;
                        if(MineralCount > MaxMineralCount)
                            MineralCount = MaxMineralCount;
                    }
                }
            }
            // Else, we are full, so move back home
            else
                MoveTowards(HomeBase.Position, dT);
        }
        // Else, move back home
        else
            MoveTowards(HomeBase.Position, dT);

        // TODO: If at home, off-load all the minerals
        float HomeDistance = (HomeBase.Position - new Vector2(GetPosition().x, GetPosition().y)).magnitude;
        if(HomeDistance < 50)
        {
            Globals.WorldView.ResManager.AddResources(MineralCount);
            MineralCount = 0;
        }
    }