private void CreateGrid()
        {
            for (int i = 0; i < width; i++)
            {
                List <ResourceCell> gridColumn = new List <ResourceCell>();
                for (int j = 0; j < height; j++)
                {
                    float dx = i * scale * delta;
                    float dy = j * scale * delta;

                    Vector3 cellPosition = new Vector3(transform.position.x + dx, transform.position.y + dy, transform.position.z);

                    float startingSugar = 0.1f + ResourceCell.maxResource * Mathf.Sin((float)i * Mathf.PI / (float)width) * Mathf.Cos((float)j * 0.5f * Mathf.PI / (float)width);
                    startingSugar = (startingSugar > 0.0f) ? startingSugar : 0.0f;

                    float startingSpice = 0.1f + ResourceCell.maxResource * Mathf.Sin((float)i * Mathf.PI / (float)width) * Mathf.Sin((float)j * 0.5f * Mathf.PI / (float)width);
                    startingSpice = (startingSpice > 0.0f) ? startingSpice : 0.0f;

                    ResourceCell singleCell = new ResourceCell((int)startingSugar, (int)startingSugar, (int)startingSpice, (int)startingSpice, 1, Instantiate(cellPrefab, cellPosition, transform.rotation), cellPosition);

                    singleCell.cellObject.transform.localScale = new Vector3(scale, scale, 1.0f);

                    gridColumn.Add(singleCell);
                }
                grid.Add(gridColumn);
            }
        }
    public override void SetCellContent(UICell cell, int row)
    {
        ResourceCell resourceCell = cell.GetComponent <ResourceCell>();

        if (resourceCell != null)
        {
            resourceCell.SetContent(resources[row]);
        }
    }
Beispiel #3
0
        public override Simulation.SimulationBuildingEnity GetSimEntity()
        {
            if (basicMineSim == null)
            {
                if (this.resourceCell == null)
                {
                    resourceCell = this.getResourceCell(location.X, location.Z);
                }
                basicMineSim = new BasicMineSim(this);
            }

            return(basicMineSim);
        }
Beispiel #4
0
    public void SetPanel()
    {
        Dictionary <int, int> res_counts = StorageManager.GetUserResources();

        res_cells = new Dictionary <int, ResourceCell>();
        foreach (var key in res_counts.Keys)
        {
            var          count    = res_counts[key];
            ResourceCell resource = Instantiate(res_cell);
            resource.gameObject.SetActive(true);
            resource.SetData(StorageManager.GetResource(key), count);
            resource.transform.SetParent(group.transform);
            resource.transform.localScale = new Vector3(1, 1, 1);
            res_cells[key] = resource;
        }
    }
Beispiel #5
0
    public void SetItem(Item item)
    {
        text.text      = item.GetName();
        image.material = item.GetMaterial();
        this.item      = item;

        res_counts = StoreManager.GetItemPrice(item.GetID());
        CheckValidation();

        foreach (var key in res_counts.Keys)
        {
            var          count    = res_counts[key];
            ResourceCell resource = Instantiate(res_cell);
            resource.gameObject.SetActive(true);
            resource.SetData(StorageManager.GetResource(key), count);
            resource.transform.SetParent(group.transform);
            resource.transform.localScale = new Vector3(1, 1, 1);
        }
    }
Beispiel #6
0
        public void UpdateStatusScreen()
        {
            if (this.resourceCell == null)
            {
                resourceCell = this.getResourceCell(location.X, location.Z);
            }
            // TODO modifyvto allow custom string and images.
            if (statusBillboard.BillboardBackGroundTexture != null)
            {
                // float electicAvail = GetSimEntity().GetAvailableOutResource(Simulation.SimulationEnity.Resource.ORE);
                // float electricMax = GetSimEntity().GetMaxResourceAmount(Simulation.SimulationEnity.Resource.ORE);

                spriteBatch = new SpriteBatch(this.device);


                RenderTarget2D target = new RenderTarget2D(this.device, 400, 600);
                this.device.SetRenderTarget(target);// Now the spriteBatch will render to the RenderTarget2D

                this.device.Clear(Color.Transparent);

                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                spriteBatch.Draw(statusBillboard.BillboardBackGroundTexture, new Rectangle(0, 0, 400, 600), Color.White);

                //    StringBuilder sb = new StringBuilder();
                //   sb.Append("Ore: ");
                //  sb.Append(electicAvail.ToString("0.0"));
                // sb.Append("/");
                //sb.Append(electricMax);

                spriteBatch.DrawString(this.font, GetSimEntity().ToString(), new Vector2(20, 20), Color.Black);

                spriteBatch.End();

                this.device.SetRenderTarget(null);//This will set the spriteBatch to render to the screen again.

                this.statusBillboard.SetTexture((Texture2D)target);
            }
        }
Beispiel #7
0
        public TreeVertexCollection(GameSession.GameStorage storage)
        {
            this.MapSize = storage.ReadVector4();
            _topSize     = (int)this.MapSize.X - 1;
            _halfSize    = _topSize / 2;
            _vertexCount = (int)(this.MapSize.X * this.MapSize.Y);

            int vertexCount = storage.ReadInt();

            //Initialize our array to hold the vertices
            Vertices = new VertexMultitextured[_vertexCount];

            //Our method to populate the vertex collection
            // VertexMultitextured[] Vertices;
            for (int i = 0; i < this.Vertices.Length; i++)
            {
                this.Vertices[i] = storage.ReadVertexMultiTextured();
            }

            // int[] sector;
            sector = new int[storage.ReadInt()];
            for (int i = 0; i < sector.Length; i++)
            {
                sector[i] = storage.ReadInt();
            }

            // ResourceCell[] resources;
            resources = new ResourceCell[storage.ReadInt()];
            for (int i = 0; i < this.resources.Length; i++)
            {
                resources[i] = new ResourceCell();
                resources[i].Restore(storage);
            }

            //Our method to  calculate the normals for all vertices
            CalculateAllNormals();
        }
Beispiel #8
0
 public NeighbouringCellData(ResourceCell _gridCell, int __x, int __y)
 {
     gridCell = _gridCell;
     _x       = __x;
     _y       = __y;
 }