Ejemplo n.º 1
0
    void Start()
    {
        id          = GetId();
        prevGrabbed = false;

        BlockManager.AddActive(this);
        shadow.SetActive(false);

        cubeVFX = GetComponent <CubeVFX> ();

        cubePositions = new List <IntegerVector3> ();
        dimensions    = new IntegerVector3();

        foreach (BoxCollider cube in GetComponents <BoxCollider>())
        {
            cubePositions.Add(new IntegerVector3(cube.center));

            dimensions.x = Mathf.Max(dimensions.x, Mathf.RoundToInt(cube.center.x));
            dimensions.y = Mathf.Max(dimensions.y, Mathf.RoundToInt(cube.center.y));
            dimensions.z = Mathf.Max(dimensions.z, Mathf.RoundToInt(cube.center.z));
        }
        for (int i = 0; i < transform.childCount; i++)
        {
            GameObject cube = transform.GetChild(i).gameObject;

            if (cube != shadow)
            {
                cubes.Add(cube);
            }
        }

        transform.SetPositionAndRotation(transform.position, Random.rotation);

        Snap(transform);
    }
Ejemplo n.º 2
0
    // Plant a block so that it can't be moved again
    public static void Plant(Block block)
    {
        BlockManager.RemoveActive(block);

        foreach (GameObject cube in block.cubes)
        {
            cube.transform.SetParent(null);
            IntegerVector3 index = WorldSpaceToIndex(cube.transform.position, false);
            index.Set(blocks, cube);
            index.Set(occupied, new OccupationState(OccupationState.Type.Planted, block.id));

            if (index.At(occupied).GetID() != block.id)
            {
                Debug.Log(string.Format("! {0}", index.At(occupied).GetID()));
            }
        }

        Object.Destroy(block.gameObject);

        RemovePlanes();

        if (IsFull())
        {
            main.Invoke("EndGame", 0);
        }
    }
Ejemplo n.º 3
0
 public void AddNode(IntegerVector3 coordinates, MapNode mapNode)
 {
     if (this.map.ContainsKey(coordinates))
     {
         throw new ArgumentException("Map coordinate already exists.");
     }
     this.map.Add(coordinates, mapNode);
 }
Ejemplo n.º 4
0
    // Transform a block area index vector into world space
    public static Vector3 IndexToWorldSpace(IntegerVector3 index)
    {
        float x = corner + gs.blockSize * index.x;
        float y = heightOffset + gs.blockSize * index.y;
        float z = corner + gs.blockSize * index.z;

        return(new Vector3(x, y, z));
    }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Location"/> class.
 /// </summary>
 /// <param name="map">The game world id.</param>
 /// <param name="localeId">The locale id.</param>
 /// <param name="position">The X, Y, Z position.</param>
 public Location(
     string map,
     IntegerVector3 position)
 {
     this.map = map;
     this.x   = position.X;
     this.y   = position.Y;
     this.z   = position.Z;
 }
Ejemplo n.º 6
0
    Vector3 SnapColumn(Vector3 position, Quaternion rotation)
    {
        IntegerVector3 transformedDim = rotation * dimensions;

        position.x = BlockArea.SnapDimension(BlockArea.ClampDimension(position.x, transformedDim.x));
        position.z = BlockArea.SnapDimension(BlockArea.ClampDimension(position.z, transformedDim.z));

        return(position);
    }
Ejemplo n.º 7
0
 public static bool IsOver(IntegerVector3 anchor, List <IntegerVector3> structure, Quaternion rotation)
 {
     foreach (IntegerVector3 cube in structure)
     {
         if (IsCubeOver(anchor + rotation * cube))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 8
0
 public static bool IsOccupied(IntegerVector3 anchor, List <IntegerVector3> structure, Quaternion rotation, int id = 0)
 {
     foreach (IntegerVector3 cube in structure)
     {
         if (IsCubeOccupied(anchor + rotation * cube, id))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 9
0
 public MapNode this[IntegerVector3 coordinates]
 {
     get
     {
         if (this.map.ContainsKey(coordinates))
         {
             return(this.map[coordinates]);
         }
         return(null);
     }
 }
Ejemplo n.º 10
0
    // Snapping dynamics:

    // snaps the height if necessary
    // @return: did a snap actually occur?
    bool SnapHeight(Transform t)
    {
        IntegerVector3 index = BlockArea.WorldSpaceToIndex(t.position);

        if (BlockArea.IsOccupied(index, cubePositions, t.rotation, id))
        {
            do
            {
                index.y++;
            } while (BlockArea.IsOccupied(index, cubePositions, t.rotation, id));

            t.SetPositionAndRotation(BlockArea.IndexToWorldSpace(index), t.rotation);

            return(true);
        }
        return(false);
    }
Ejemplo n.º 11
0
 // General Place and Unplace helper method
 static void GeneralPlace(Block block, int id)
 {
     foreach (GameObject cube in block.cubes)
     {
         IntegerVector3 index = WorldSpaceToIndex(cube.transform.position, false);
         if (index.inBounds(occupied))
         {
             if (id == 0)
             {
                 index.Set(occupied, new OccupationState(OccupationState.Type.Unoccupied));
             }
             else
             {
                 index.Set(occupied, new OccupationState(OccupationState.Type.Layed, id));
             }
         }
     }
 }
Ejemplo n.º 12
0
    void Update()
    {
        if (grabbed)
        {
            shadow.transform.SetPositionAndRotation(transform.position, transform.rotation);
            Snap(shadow.transform);
        }
        else if (!planting)
        {
            transform.position += BlockManager.BlockFallingSpeed(transform.position.y) * Time.deltaTime * Vector3.down;

            //if (BlockArea.IsOccupied (BlockArea.WorldSpaceToIndex (transform.position), cubePositions, transform.rotation)) {
            //	Snap (transform);
            //	Lay ();
            //}
            if (Snap(transform))
            {
                Lay();
            }
        }
        if (planting)
        {
            IntegerVector3 underIndex = BlockArea.WorldSpaceToIndex(transform.position) + new IntegerVector3(0, -1, 0);

            if (!BlockArea.IsOccupied(underIndex, cubePositions, transform.rotation, id))
            {
                Unlay();
            }
        }

        // Debug

        /*cubeVFX.ApplyColor(Color.blue);
         * if (delayedUngrabbed) {
         *      cubeVFX.ApplyColor(Color.yellow);
         * }
         * if (grabbed) {
         *      cubeVFX.ApplyColor(Color.red);
         * }
         * if (planting) {
         *      cubeVFX.ApplyColor(Color.green);
         * }*/
    }
Ejemplo n.º 13
0
    public static bool IsCubeOccupied(IntegerVector3 index, int id = 0)
    {
        if (IsCubeOverfull(index))
        {
            return(false);
        }

        if (IsCubeUnder(index))
        {
            return(true);
        }

        if (!IsCubeInBounds(index))
        {
            return(true);
        }

        return(index.At(occupied).Occupied(id));
    }
Ejemplo n.º 14
0
        public void AddNode(int x, int y, int z, MapNode mapNode)
        {
            IntegerVector3 coordinate = new IntegerVector3(x, y, z);

            AddNode(coordinate, mapNode);
        }
Ejemplo n.º 15
0
 public static bool IsCubeInBounds(IntegerVector3 index)
 {
     return(IsCubeInPlanarBounds(index) &&
            index.y >= 0);
 }
Ejemplo n.º 16
0
 public static bool IsCubeInPlanarBounds(IntegerVector3 index)
 {
     return(index.x >= 0 && index.x < gs.areaSize &&
            index.z >= 0 && index.z < gs.areaSize);
 }
Ejemplo n.º 17
0
 public static bool IsCubeUnder(IntegerVector3 index)
 {
     return(index.y < 0);
 }
Ejemplo n.º 18
0
 public static bool IsCubeOverfull(IntegerVector3 index)
 {
     return(index.y >= gs.fullAreaHeight);
 }
Ejemplo n.º 19
0
 // Restrict the x and z coordinates of an index vector to within the block area
 public static IntegerVector3 Clamp(IntegerVector3 index)
 {
     index.x = Mathf.Clamp(index.x, 0, gs.areaSize - 1);
     index.z = Mathf.Clamp(index.z, 0, gs.areaSize - 1);
     return(index);
 }