Exemplo n.º 1
0
    public void SetBlock(int x, int y, JSBlockType blockType)
    {
        Map[x, y] = blockType;
        //Loop through all blocks objects, see if we have to update or add one
        GameObject foundBlock = null;
        foreach (var block in GameObject.FindGameObjectsWithTag("Block"))
        {
            if (Mathf.Approximately(block.transform.position.x, x) && Mathf.Approximately(block.transform.position.y, y)) {
                foundBlock = block;
                break;
            }
        }

        if (foundBlock == null)
        {
            foundBlock = (GameObject)Instantiate(BlockPrefab, new Vector3(x, y, 0), Quaternion.identity);
        }

        if (blockType.Material == null) {
            blockType.Material = new Material(BaseBlockMaterial);
        }

        //This part is inefficient, should be done with an observer
        blockType.Material.SetColor("_Color", new Color((float)blockType.Red / 255, (float)blockType.Green / 255, (float)blockType.Blue / 255));

        foundBlock.renderer.material = blockType.Material;
    }
Exemplo n.º 2
0
    private Color GetColor(JSBlockType jColor)
    {
        int red = jColor.Red;
        int green = jColor.Green;
        int blue = jColor.Blue;

        return new Color(red / 255f, green / 255f, blue / 255f);
    }
Exemplo n.º 3
0
 public JSBlockType BlockType(string name)
 {
     if (context.BlockTypes.ContainsKey(name)) {
         return context.BlockTypes[name];
     } else {
         JSBlockType blockType = new JSBlockType(Engine, name);
         context.BlockTypes.Add(name, blockType);
         return blockType;
     }
 }
Exemplo n.º 4
0
 public BlockChangedEventArgs(int x, int y, JSBlockType blockType)
 {
     X = x;
     Y = y;
     BlockType = blockType;
 }
Exemplo n.º 5
0
 public void Set(int x, int y, JSBlockType blockType)
 {
     Map[x,y] = blockType;
     BlockChanged(this, new BlockChangedEventArgs(x, y, blockType));
 }
Exemplo n.º 6
0
 public JSMap(ScriptEngine engine)
     : base(engine)
 {
     Map = new JSBlockType[128, 128];
     this.PopulateFunctions();
 }