Example #1
0
 public override void BuildFace(Chunk chunk, BlockPos pos, MeshData meshData, BlockDirection blockDirection, Block block)
 {
     BlockBuilder.BuildRenderer(chunk, pos, meshData, blockDirection);
     BlockBuilder.BuildTexture(chunk, pos, meshData, blockDirection, new Tile[] {
         new Tile((int)textures[0].x, (int)textures[0].y),
         new Tile((int)textures[1].x, (int)textures[1].y),
         new Tile((int)textures[2].x, (int)textures[2].y),
         new Tile((int)textures[3].x, (int)textures[3].y),
         new Tile((int)textures[4].x, (int)textures[4].y),
         new Tile((int)textures[5].x, (int)textures[5].y)
     });
     BlockBuilder.BuildColors(chunk, pos, meshData, blockDirection);
     if (Config.Toggle.UseCollisionMesh)
     {
         BlockBuilder.BuildCollider(chunk, pos, meshData, blockDirection);
     }
 }
Example #2
0
	// Other Blocks can override this with their own solidity - e.g. Ramps will return true for up and its front
	public virtual bool IsSolid(BlockDirection direction) {
		switch(direction){
		case BlockDirection.Up:
			return true;
		case BlockDirection.Down:
			return true;
		case BlockDirection.Right:
			return true;
		case BlockDirection.Left:
			return true;
		case BlockDirection.Forward:
			return true;
		case BlockDirection.Back:
			return true;
		}
		
		return false;
	}
Example #3
0
 public virtual void BuildFace(Chunk chunk, BlockPos pos, MeshData meshData, BlockDirection blockDirection, Block block)
 {
 }
Example #4
0
    static void AddQuadToMeshData(Chunk chunk, BlockPos pos, MeshData meshData, BlockDirection blockDirection, bool useCollisionMesh)
    {
        //Adding a tiny overlap between block meshes may solve floating point imprecision
        //errors causing pixel size gaps between blocks when looking closely
        float halfBlock = (Config.Env.BlockSize / 2) + Config.Env.BlockFacePadding;

        //Converting the position to a vector adjusts it based on block size and gives us real world coordinates for x, y and z
        Vector3 vPos = pos;

        switch (blockDirection)
        {
            case BlockDirection.up:
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y + halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y + halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y + halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y + halfBlock, vPos.z - halfBlock), useCollisionMesh);
                break;
            case BlockDirection.down:
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z + halfBlock), useCollisionMesh);
                break;
            case BlockDirection.north:
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y + halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y + halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z + halfBlock), useCollisionMesh);
                break;
            case BlockDirection.east:
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y + halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y + halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z + halfBlock), useCollisionMesh);
                break;
            case BlockDirection.south:
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y + halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y + halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z - halfBlock), useCollisionMesh);
                break;
            case BlockDirection.west:
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y + halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y + halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z - halfBlock), useCollisionMesh);
                break;
            default:
                Debug.LogError("BlockDirection not recognized");
                break;
        }

        meshData.AddQuadTriangles(useCollisionMesh);
    }
Example #5
0
    public static void BuildTexture(Chunk chunk, BlockPos pos, MeshData meshData, BlockDirection blockDirection, Tile[] tiles)
    {
        Tile tilePos = new Tile();

        switch (blockDirection)
        {
            case BlockDirection.up:
                tilePos = tiles[0];
                break;
            case BlockDirection.down:
                tilePos = tiles[1];
                break;
            case BlockDirection.north:
                tilePos = tiles[2];
                break;
            case BlockDirection.east:
                tilePos = tiles[3];
                break;
            case BlockDirection.south:
                tilePos = tiles[4];
                break;
            case BlockDirection.west:
                tilePos = tiles[5];
                break;
            default:
                break;
        }

        Vector2[] UVs = new Vector2[4];

        UVs[0] = new Vector2(Config.Env.TileSize * tilePos.x + Config.Env.TileSize, Config.Env.TileSize * tilePos.y);
        UVs[1] = new Vector2(Config.Env.TileSize * tilePos.x + Config.Env.TileSize, Config.Env.TileSize * tilePos.y + Config.Env.TileSize);
        UVs[2] = new Vector2(Config.Env.TileSize * tilePos.x, Config.Env.TileSize * tilePos.y + Config.Env.TileSize);
        UVs[3] = new Vector2(Config.Env.TileSize * tilePos.x, Config.Env.TileSize * tilePos.y);

        meshData.uv.AddRange(UVs);
    }
Example #6
0
 public static void BuildRenderer(Chunk chunk, BlockPos pos, MeshData meshData, BlockDirection blockDirection)
 {
     AddQuadToMeshData(chunk, pos, meshData, blockDirection, false);
 }
Example #7
0
 public Fence GetNeighbor(BlockDirection direction)
 {
     return(neighbors[(int)direction]);
 }
Example #8
0
 /// <summary>
 ///  Determines the block that would be encountered if a cursor was navigating in
 ///  <paramref name="direction"/> from <paramref name="block"/>.
 /// </summary>
 /// <param name="direction"> The theoretical direction a cursor is moving. </param>
 /// <param name="block"> The block from which the cursor is moving. </param>
 /// <returns>
 ///  The block that is closest in the given direct from <paramref name="block"/>
 /// </returns>
 public abstract Block GetBlockTo(BlockDirection direction, Block block);
Example #9
0
        //ЗАГРУЖАЕМ ЗАДАЧУ С ДИСКА
        public NewCell[,] LoadPuzzle()
        {
            List <string> puzzle = new List <string>();

            // очищаем cписок строк:
            puzzle.Clear();

            var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            var filePath      = System.IO.Path.Combine(documentsPath, "task.txt");
            //загружаем задачу с диска:
            StreamReader sr = new StreamReader(filePath);
            //считываем слова:
            string s = null;

            while ((s = sr.ReadLine()) != null)
            {
                // заменяем точки нулями:
                s = s.Replace('.', '0');
                puzzle.Add(s);
            }
            sr.Close();
            sr = null;

            int CellCol = 0, CellRow = 0;

            // в первой строке - размеры сетки:
            string[] str2 = puzzle[0].Split(new char[] { ' ', '-', 'x' });
            int      n    = 0;

            if (int.TryParse(str2[0], out n))
            {
                CellCol = n;
            }
            if (int.TryParse(str2[1], out n))
            {
                CellRow = n;
            }

            // очищаем список блоков:
            lstBlocks.Clear();
            // создаем пустую сетку:
            Grid    = new NewCell[CellCol, CellRow];
            nSolved = 0;

            // сетка - строки 1 ..CellRow:
            for (int i = 1; i < CellRow + 1; ++i)
            {
                s = puzzle[i];
                int r = i - 1;

                // разбиваем строку:
                string[] asc = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                for (int ns = 0; ns < asc.Length; ++ns)
                {
                    string sc = asc[ns];
                    // определяем цвет клетки:
                    int pos = sc.IndexOf('\\');
                    // черная клетка:
                    if (pos != -1)
                    {
                        // Создаем новую клетку:
                        Grid[ns, r] = new NewCell(false);
                        // ее решать не нужно:
                        ++nSolved;
                        Point nums = extractNums(sc, pos);
                        // горизонтальный блок:
                        if (nums.X > 0)
                        {
                            Block bl = new Block(ns, r, BlockDirection.BD_HORIZ, (int)nums.X);
                            lstBlocks.Add(bl);
                        }
                        //вертикальный блок:
                        if (nums.Y > 0)
                        {
                            Block bl = new Block(ns, r, BlockDirection.BD_VERT, (int)nums.Y);
                            lstBlocks.Add(bl);
                        }
                    }
                    // белая клетка:
                    else
                    {
                        // Создаем новую клетку:
                        Grid[ns, r] = new NewCell(true);
                        // какое в ней число:
                        int num = 0;
                        if (int.TryParse(sc, out num))
                        {
                            if (num != 0)
                            {
                                Grid[ns, r].num = num;
                                Grid[ns, r].fix = true;
                                ++nSolved;
                            }
                        }
                        else
                        {
                            Console.WriteLine("Неверный символ в строке!");
                        }
                    }
                }
            }

            // блоки
            foreach (Block bl in lstBlocks)
            {
                // коорд. черной клетки:
                int x = bl.blackX;
                int y = bl.blackY;
                // направление:
                BlockDirection bd = bl.dir;
                // число белых клеток:
                int nWhite = 0;
                if (bd == BlockDirection.BD_HORIZ)
                {
                    while (x + 1 < Grid.GetLength(0) && Grid[x + 1, y].color)
                    {
                        // добавляем блок в клетку:
                        Grid[x + 1, y].lstBlocks.Add(bl);
                        // добавляем число в множество:
                        if (Grid[x + 1, y].num != 0)
                        {
                            bl.setNums.Add(Grid[x + 1, y].num);
                        }
                        ++nWhite;
                        ++x;
                    }
                }
                else
                {
                    while (y + 1 < Grid.GetLength(1) && Grid[x, y + 1].color)
                    {
                        // добавляем блок в клетку:
                        Grid[x, y + 1].lstBlocks.Add(bl);
                        // добавляем число в множество:
                        if (Grid[x, y + 1].num != 0)
                        {
                            bl.setNums.Add(Grid[x, y + 1].num);
                        }
                        ++nWhite;
                        ++y;
                    }
                }
                bl.nWhite = nWhite;
            }
            return(Grid);
        }
Example #10
0
    // Update is called once per frame
    void Update()
    {
        if (Player.GetComponent <Player>().CursorMode == 1)
        {
            if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
            {
                Cursor.transform.position += new Vector3(0, 0.1f, 0);
                if (Cursor.transform.position.y >= 11.9f)
                {
                    Cursor.transform.position = new Vector3(
                        Cursor.transform.position.x, 11.9f, Cursor.transform.position.z);
                }
            }
            if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
            {
                Cursor.transform.position += new Vector3(0, -0.1f, 0);
                if (Cursor.transform.position.y <= -11.9f)
                {
                    Cursor.transform.position = new Vector3(
                        Cursor.transform.position.x, -11.9f, Cursor.transform.position.z);
                }
            }
            Cursor.GetComponent <Renderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
        }
        else
        {
            Cursor.GetComponent <Renderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
        }

        if (Player.GetComponent <Player>().CursorMode == 1 && Input.GetKeyDown(KeyCode.K))
        {
            //Goal_false2.transform.position = new Vector3(
            //   Goal_false2.transform.position.x * -1.0f, Goal_false2.transform.position.y, Goal_false2.transform.position.z);

            //Goal_true2.transform.position = new Vector3(
            //   Goal_true2.transform.position.x * -1.0f, Goal_true2.transform.position.y, Goal_true2.transform.position.z);

            //Needle_0.transform.position = new Vector3(
            //   Needle_0.transform.position.x * -1.0f, Needle_0.transform.position.y, Needle_0.transform.position.z);

            //Needle_1.transform.position = new Vector3(
            //   Needle_1.transform.position.x * -1.0f, Needle_1.transform.position.y, Needle_1.transform.position.z);

            //Needle_2.transform.position = new Vector3(
            //   Needle_2.transform.position.x * -1.0f, Needle_2.transform.position.y, Needle_2.transform.position.z);

            //Needle_3.transform.position = new Vector3(
            //   Needle_3.transform.position.x * -1.0f, Needle_3.transform.position.y, Needle_3.transform.position.z);

            //Needle_4.transform.position = new Vector3(
            //   Needle_4.transform.position.x * -1.0f, Needle_4.transform.position.y, Needle_4.transform.position.z);
            GameObject[] objects;

            objects = GameObject.FindGameObjectsWithTag("Object");

            Count = objects.Length;

            bool TranLeft = Player.transform.position.y <= Cursor.transform.position.y ? false : true;


            // TranLeft = Player.GetComponent<SpriteRenderer>().flipX;
            if (BlockDirection.RotationState == BlockDirection.ROTATION_STATE_NAME.Rotated)
            {
                for (int i = 0; i < Count; i++)
                {
                    //切り取り線を参照しプレイヤーと異なる側のブロックを反転
                    if (objects[i].transform.position.y <= Cursor.transform.position.y && TranLeft || objects[i].transform.position.y > Cursor.transform.position.y && !TranLeft)
                    {
                        // objects[i].transform.position = new Vector3(objects[i].transform.position.x * -1.0f, objects[i].transform.position.y , objects[i].transform.position.z * -1.0f);
                        //左右反転だから左か右に向いてるブロックの向きだけを反転するようにする
                        //  objects[i].GetComponent<BlockDirection>().blkDirection = (objects[i].GetComponent<BlockDirection>().blkDirection % 2) == 1 ? (objects[i].GetComponent<BlockDirection>().blkDirection + 2) % 4 : objects[i].GetComponent<BlockDirection>().blkDirection;

                        CursorController.rotatecount++;

                        BlockDirection blk = objects[i].GetComponent <BlockDirection>();
                        blk.StartPosition = objects[i].transform.position;
                        blk.EndPosition   = new Vector3(objects[i].transform.position.x * -1.0f, objects[i].transform.position.y, objects[i].transform.position.z);
                        //blk.StartRotation = objects[i].transform.rotation;
                        //blk.EndRotation = new Quaternion(objects[i].transform.rotation.x, objects[i].transform.rotation.y - 180.0f , objects[i].transform.rotation.z, objects[i].transform.rotation.w);
                        // blk.RotateSpeed = 2.0f * Mathf.Abs(objects[i].transform.position.x) / BlockDirection.RotateTime;
                        // blk.MaxRotateScale = 2.0f * objects[i].transform.position.x / 28.0f * 2.0f;
                    }
                }

                if (CursorController.rotatecount != 0)
                {
                    BlockDirection.RotationState = BlockDirection.ROTATION_STATE_NAME.Rotating;
                    CursorController.rotatecount = 0;
                }
            }
            else
            {
                BlockDirection.PassedTime = BlockDirection.RotateTime - BlockDirection.PassedTime;
                for (int i = 0; i < Count; i++)
                {
                    BlockDirection blk      = objects[i].GetComponent <BlockDirection>();
                    Vector3        startPos = blk.StartPosition;
                    blk.StartPosition = blk.EndPosition;
                    blk.EndPosition   = startPos;
                    //Quaternion startRotate = blk.StartRotation;
                    //blk.StartRotation = blk.EndRotation;
                    // blk.EndRotation = startRotate;
                }
            }
        }

        //DebugImage2.color = color;
    }
Example #11
0
 public int GetTextureChip(BlockDirection direction, bool isObject)
 {
     return(this.textureChips[(isObject) ? 6 : (int)direction]);
 }
Example #12
0
 public void SetDirection(BlockDirection direction)
 {
     this.direction = direction;
 }
Example #13
0
    public Mesh GetMesh(BlockDirection direction)
    {
        int index = this.ToLocalDirection((int)direction);

        return(this.shape.meshes[index]);
    }
Example #14
0
 public BlockDirection GetConnectionDir(BlockDirection direction)
 {
     return((BlockDirection)ToWorldDirection((int)this.shape.connectionDir[ToLocalDirection((int)direction)]));
 }
Example #15
0
 public BlockConnection GetConnection(BlockDirection direction)
 {
     return(this.shape.connection[ToLocalDirection((int)direction)]);
 }
Example #16
0
 public override bool IsSolid(BlockDirection blockDirection)
 {
     return isSolid;
 }
Example #17
0
	//Set Block Near Position's Direction With BlockID
	public void SetBlockNearBy (ISSCBlockVector position, BlockDirection direction, int blockID)
	{
		ISSCBlockVector tmpBV = new ISSCBlockVector ();
		tmpBV = position;
		switch (direction) {
		case BlockDirection.Up: 
			tmpBV.y += 1;
			SetBlock (tmpBV, blockID);
			break;
		case BlockDirection.Down: 
			tmpBV.y -= 1;
			SetBlock (tmpBV, blockID);
			break;
		case BlockDirection.Right: 
			tmpBV.x += 1;
			SetBlock (tmpBV, blockID);
			break;
		case BlockDirection.Left: 
			tmpBV.x -= 1;
			SetBlock (tmpBV, blockID);
			break;
		case BlockDirection.Forward: 
			tmpBV.z += 1;
			SetBlock (tmpBV, blockID);
			break;
		case BlockDirection.Back: 
			tmpBV.z -= 1;
			SetBlock (tmpBV, blockID);
			break;
		}
	}
Example #18
0
 public virtual bool IsSolid(BlockDirection blockDirection)
 {
     return false;
 }
Example #19
0
 public static void BuildRenderer(Chunk chunk, BlockPos pos, MeshData meshData, BlockDirection blockDirection)
 {
     AddQuadToMeshData(chunk, pos, meshData, blockDirection, false);
 }
Example #20
0
    }                                                       //Public read-only variable for easy access to the blockId for saving


    public BlockData(Block block)
    {
        this.block = block;
        rotation   = BlockDirection.Z_PLUS;
    }
Example #21
0
    //public static BlockDirection Opposite(this BlockDirection direction)
    //{
    //    return (int)direction < 4 ? (direction + 4) : (direction - 4);
    //}

    public static BlockDirection Opposite(this BlockDirection direction)
    {
        return((int)direction < 2 ? (direction + 2) : (direction - 2));
    }
Example #22
0
 //Change the rotation according to the above enum
 public void SetRotation(BlockDirection rotation)
 {
     this.rotation = rotation;
 }
Example #23
0
 public Vector2[] GetFaceUV(CubeFace face, BlockDirection dir)
 {
     face = TransformFace(face, dir);
     return(texCoords[(int)face]);
 }
    protected virtual void Update()
    {
        mDir = BlockDirection.Null;

        if (Input.GetButtonDown("Interact"))
        {
            var player = FindObjectOfType <Player>();
            if (player == null)
            {
                return;
            }

            if (mPlayerAttached)
            {
                mQueueDettach = true;
            }
            else
            {
                mPlayerDirection = GetPlayerDirection();
                if ((mPlayerDirection == BlockDirection.Left || mPlayerDirection == BlockDirection.Right) && Mathf.Abs(transform.position.x - player.transform.position.x) <= InteractDistance)
                {
                    mPlayerAttached = true;
                }
                if ((mPlayerDirection == BlockDirection.Backward || mPlayerDirection == BlockDirection.Forward) && Mathf.Abs(transform.position.z - player.transform.position.z) <= InteractDistance)
                {
                    mPlayerAttached = true;
                }

                if (mPlayerAttached)
                {
                    player.SetIgnoreInput(true);
                }
            }
        }

        if (mPlayerAttached && !mQueueDettach)
        {
            var xInput = Input.GetAxis("Horizontal");
            var yInput = Input.GetAxis("Vertical");

            if (mPlayerDirection == BlockDirection.Left || mPlayerDirection == BlockDirection.Right)
            {
                if (yInput > 0.1f)
                {
                    mDir = BlockDirection.Right;
                }
                if (yInput < -0.1f)
                {
                    mDir = BlockDirection.Left;
                }
            }

            else if (mPlayerDirection == BlockDirection.Backward || mPlayerDirection == BlockDirection.Forward)
            {
                if (xInput < -0.1f)
                {
                    mDir = BlockDirection.Forward;
                }
                if (xInput > 0.1f)
                {
                    mDir = BlockDirection.Backward;
                }
            }

            if (mDir != BlockDirection.Null)
            {
                BlockPuzzleTileInfo tile;
                if (BlockGrid.BlockMoveIsValid(transform.position, mDir, out tile))
                {
                    tile.Pos.y = transform.position.y;
                    mTargetPos = tile.Pos;
                }
            }
        }

        MoveToTargetPos();

        if (mPlayerAttached && FindObjectOfType <Player>())
        {
            var player = FindObjectOfType <Player>();

            // Dettaching tia if either Tia or the block start to fall away from the other.
            if (GetComponent <Rigidbody>())
            {
                if (Mathf.Abs(GetComponent <Rigidbody>().velocity.y) > 0.25f)
                {
                    mQueueDettach = true;
                }
            }
            if (Mathf.Abs(player.GetComponent <Rigidbody>().velocity.y) > 0.25f)
            {
                mQueueDettach = true;
            }

            // Update player anim.
            float animSpeed = mCurrentVelocity.magnitude * Mathf.Sign(Vector3.Dot(transform.position - player.transform.position, mCurrentVelocity));
            player.SetPushPullSpeed(animSpeed);

            // Update the player position.
            var tiaPushPos = transform.position;
            tiaPushPos.y = player.transform.position.y;
            tiaPushPos  += BlockPuzzleManager.DirectionToVector(mPlayerDirection) * 2f;
            player.transform.position = Vector3.Slerp(player.transform.position, tiaPushPos, Time.deltaTime * 5f);

            // Updating the player rotation.
            player.transform.parent = transform;
            var tiaLookPos = transform.position;
            tiaLookPos.y = player.transform.position.y;
            player.transform.LookAt(tiaLookPos);

            // Dettaching the player if required.
            if (mCurrentVelocity.magnitude <= 0f)
            {
                if (mQueueDettach)
                {
                    mPlayerAttached         = false;
                    player.transform.parent = null;
                    player.SetIgnoreInput(false);
                    mQueueDettach = false;
                }
            }
        }

        if (mCurrentVelocity.magnitude <= 0f && mQueueDestroy)
        {
            Destroy(this);
        }
    }
Example #25
0
    public static void BuildTexture(Chunk chunk, BlockPos pos, MeshData meshData, BlockDirection blockDirection, Tile tilePos)
    {
        Vector2[] UVs = new Vector2[4];

        UVs[0] = new Vector2(Config.Env.TileSize * tilePos.x + Config.Env.TileSize, Config.Env.TileSize * tilePos.y);
        UVs[1] = new Vector2(Config.Env.TileSize * tilePos.x + Config.Env.TileSize, Config.Env.TileSize * tilePos.y + Config.Env.TileSize);
        UVs[2] = new Vector2(Config.Env.TileSize * tilePos.x, Config.Env.TileSize * tilePos.y + Config.Env.TileSize);
        UVs[3] = new Vector2(Config.Env.TileSize * tilePos.x, Config.Env.TileSize * tilePos.y);

        meshData.uv.AddRange(UVs);
    }
Example #26
0
 public CellValue(BlockShape _blocktype, BlockDirection _direction, BlockStyle _style)
 {
     blockType = _blocktype;
     direction = _direction;
     style     = _style;
 }
Example #27
0
    public static void BuildColors(Chunk chunk, BlockPos pos, MeshData meshData, BlockDirection blockDirection)
    {
        bool nSolid = false;
        bool eSolid = false;
        bool sSolid = false;
        bool wSolid = false;

        bool wnSolid = false;
        bool neSolid = false;
        bool esSolid = false;
        bool swSolid = false;

        float light = 0;

        switch (blockDirection)
        {
            case BlockDirection.up:
                nSolid = chunk.GetBlock(pos.Add(0, 1, 1)).controller.IsSolid(BlockDirection.south);
                eSolid = chunk.GetBlock(pos.Add(1, 1, 0)).controller.IsSolid(BlockDirection.west);
                sSolid = chunk.GetBlock(pos.Add(0, 1, -1)).controller.IsSolid(BlockDirection.north);
                wSolid = chunk.GetBlock(pos.Add(-1, 1, 0)).controller.IsSolid(BlockDirection.east);

                wnSolid = chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(BlockDirection.east) && chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(BlockDirection.south);
                neSolid = chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(BlockDirection.south) && chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(BlockDirection.west);
                esSolid = chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(BlockDirection.west) && chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(BlockDirection.north);
                swSolid = chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(BlockDirection.north) && chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(BlockDirection.east);

                light = chunk.GetBlock(pos.Add(0, 1, 0)).data1 / 255f;

                break;
            case BlockDirection.down:
                nSolid = chunk.GetBlock(pos.Add(0, -1, -1)).controller.IsSolid(BlockDirection.south);
                eSolid = chunk.GetBlock(pos.Add(1, -1, 0)).controller.IsSolid(BlockDirection.west);
                sSolid = chunk.GetBlock(pos.Add(0, -1, 1)).controller.IsSolid(BlockDirection.north);
                wSolid = chunk.GetBlock(pos.Add(-1, -1, 0)).controller.IsSolid(BlockDirection.east);

                wnSolid = chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(BlockDirection.east) && chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(BlockDirection.south);
                neSolid = chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(BlockDirection.south) && chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(BlockDirection.west);
                esSolid = chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(BlockDirection.west) && chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(BlockDirection.north);
                swSolid = chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(BlockDirection.north) && chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(BlockDirection.east);

                light = chunk.GetBlock(pos.Add(0, -1, 0)).data1 / 255f;

                break;
            case BlockDirection.north:
                nSolid = chunk.GetBlock(pos.Add(1, 0, 1)).controller.IsSolid(BlockDirection.west);
                eSolid = chunk.GetBlock(pos.Add(0, 1, 1)).controller.IsSolid(BlockDirection.down);
                sSolid = chunk.GetBlock(pos.Add(-1, 0, 1)).controller.IsSolid(BlockDirection.east);
                wSolid = chunk.GetBlock(pos.Add(0, -1, 1)).controller.IsSolid(BlockDirection.up);

                esSolid = chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(BlockDirection.east) && chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(BlockDirection.south);
                neSolid = chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(BlockDirection.south) && chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(BlockDirection.west);
                wnSolid = chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(BlockDirection.west) && chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(BlockDirection.north);
                swSolid = chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(BlockDirection.north) && chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(BlockDirection.east);

                light = chunk.GetBlock(pos.Add(0, 0, 1)).data1 / 255f;

                break;
            case BlockDirection.east:
                nSolid = chunk.GetBlock(pos.Add(1, 0, -1)).controller.IsSolid(BlockDirection.up);
                eSolid = chunk.GetBlock(pos.Add(1, 1, 0)).controller.IsSolid(BlockDirection.west);
                sSolid = chunk.GetBlock(pos.Add(1, 0, 1)).controller.IsSolid(BlockDirection.down);
                wSolid = chunk.GetBlock(pos.Add(1, -1, 0)).controller.IsSolid(BlockDirection.east);

                esSolid = chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(BlockDirection.west) && chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(BlockDirection.north);
                neSolid = chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(BlockDirection.south) && chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(BlockDirection.west);
                wnSolid = chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(BlockDirection.east) && chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(BlockDirection.north);
                swSolid = chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(BlockDirection.north) && chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(BlockDirection.east);

                light = chunk.GetBlock(pos.Add(1, 0, 0)).data1 / 255f;

                break;
            case BlockDirection.south:
                nSolid = chunk.GetBlock(pos.Add(-1, 0, -1)).controller.IsSolid(BlockDirection.down);
                eSolid = chunk.GetBlock(pos.Add(0, 1, -1)).controller.IsSolid(BlockDirection.west);
                sSolid = chunk.GetBlock(pos.Add(1, 0, -1)).controller.IsSolid(BlockDirection.up);
                wSolid = chunk.GetBlock(pos.Add(0, -1, -1)).controller.IsSolid(BlockDirection.south);

                esSolid = chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(BlockDirection.west) && chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(BlockDirection.north);
                neSolid = chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(BlockDirection.south) && chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(BlockDirection.west);
                wnSolid = chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(BlockDirection.east) && chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(BlockDirection.north);
                swSolid = chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(BlockDirection.north) && chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(BlockDirection.east);

                light = chunk.GetBlock(pos.Add(0, 0, -1)).data1 / 255f;

                break;
            case BlockDirection.west:
                nSolid = chunk.GetBlock(pos.Add(-1, 0, 1)).controller.IsSolid(BlockDirection.up);
                eSolid = chunk.GetBlock(pos.Add(-1, 1, 0)).controller.IsSolid(BlockDirection.west);
                sSolid = chunk.GetBlock(pos.Add(-1, 0, -1)).controller.IsSolid(BlockDirection.down);
                wSolid = chunk.GetBlock(pos.Add(-1, -1, 0)).controller.IsSolid(BlockDirection.east);

                esSolid = chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(BlockDirection.west) && chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(BlockDirection.north);
                neSolid = chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(BlockDirection.south) && chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(BlockDirection.west);
                wnSolid = chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(BlockDirection.east) && chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(BlockDirection.north);
                swSolid = chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(BlockDirection.north) && chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(BlockDirection.east);

                light = chunk.GetBlock(pos.Add(-1, 0, 0)).data1 / 255f;

                break;
            default:
                Debug.LogError("BlockDirection not recognized");
                break;
        }

        AddColors(meshData, wnSolid, nSolid, neSolid, eSolid, esSolid, sSolid, swSolid, wSolid, light);
    }
Example #28
0
    // ブロックメッシュをマージ
    public void Merge(Mesh mesh, Vector3 position, BlockDirection direction, Vector3 scale,
                      bool divideChipVert, int textureId, int meshId)
    {
        var chip = TexturePalette.Instance.GetChip(textureId);

        int vertexOffset = this.vertexPos.Count;

        Vector3[] vertexPos    = mesh.vertices;
        Vector3[] vertexNormal = mesh.normals;
        Vector2[] vertexUv     = mesh.uv;
        int[]     indices      = mesh.GetIndices(0);
        float[]   heights      = new float[vertexUv.Length];

        // Vが0.0~1.0の範囲外の場合は高さを調整する
        for (int j = 0; j < indices.Length; j += 3)
        {
            Vector2 uv0 = vertexUv[indices[j + 0]];
            Vector2 uv1 = vertexUv[indices[j + 1]];
            Vector2 uv2 = vertexUv[indices[j + 2]];

            float height = position.y;

            if (uv0.y < 0.0f || uv1.y < 0.0f || uv2.y < 0.0f)
            {
                height += 0.5f;
            }
            else if (uv0.y > 1.0f || uv1.y > 1.0f || uv2.y > 1.0f)
            {
                height -= 0.5f;
            }

            heights[indices[j + 0]] = height;
            heights[indices[j + 1]] = height;
            heights[indices[j + 2]] = height;
        }

        for (int j = 0; j < vertexPos.Length; j++)
        {
            Vector3 localPosition = Vector3.Scale(vertexPos[j], Vector3.Scale(new Vector3(-1, 1, -1), scale));
            Vector3 localNormal   = Vector3.Scale(vertexNormal[j], new Vector3(-1, 1, -1));
            this.vertexPos.Add(position + EditUtil.RotatePosition(localPosition, direction));
            this.vertexNormal.Add(EditUtil.RotatePosition(localNormal, direction));
            this.vertexUv.Add(chip.ApplyUV(vertexUv[j], divideChipVert, heights[j]));
            this.vertexMeta.Add(new Vector2((float)meshId, 0.0f));
        }
        for (int j = 0; j < indices.Length; j++)
        {
            this.triangles.Add(vertexOffset + indices[j]);
        }

        if (this.subMeshMerger != null)
        {
            int key = EditUtil.PositionToHashCode(new Vector3(
                                                      Mathf.Floor(position.x / this.subMeshDivs.x),
                                                      Mathf.Floor(position.y / this.subMeshDivs.y),
                                                      Mathf.Floor(-position.z / this.subMeshDivs.z)));

            if (!this.subMeshMerger.ContainsKey(key))
            {
                this.subMeshMerger.Add(key, new BlockMeshMerger());
            }
            this.subMeshMerger[key].Merge(mesh, position, direction, scale, divideChipVert, textureId, meshId);
        }
    }
Example #29
0
 public static void BuildCollider(Chunk chunk, BlockPos pos, MeshData meshData, BlockDirection blockDirection)
 {
     AddQuadToMeshData(chunk, pos, meshData, blockDirection, true);
 }
Example #30
0
 public LegacyBlockInfo(BlockDirection direction, LegacyEdgesState edgesState, BlockShape shape)
 {
     data = (byte)((int)direction | ((int)edgesState << 2) | ((int)shape << 4));
 }
Example #31
0
 public void SetBlockDirection(BlockDirection direction)
 {
     data = (byte)((data & ~3) | (int)direction);
 }
Example #32
0
 public static void BuildCollider(Chunk chunk, BlockPos pos, MeshData meshData, BlockDirection blockDirection)
 {
     AddQuadToMeshData(chunk, pos, meshData, blockDirection, true);
 }
Example #33
0
	//Check Block's Direction Nearby Is Empty ,Empty Return True, Or Not Return False
	public bool IsNearByEmpty (ISSCBlockVector position, BlockDirection direction)
	{
		ISSCBlockVector tmpBV = position;

		switch (direction) {
		case BlockDirection.Up: 
			tmpBV.y += 1;
			return IsBlockEmpty (tmpBV);
		case BlockDirection.Down: 
			tmpBV.y -= 1;
			return IsBlockEmpty (tmpBV);
		case BlockDirection.Right: 
			tmpBV.x += 1;
			return IsBlockEmpty (tmpBV);
		case BlockDirection.Left: 
			tmpBV.x -= 1;
			return IsBlockEmpty (tmpBV);
		case BlockDirection.Forward: 
			tmpBV.z += 1;
			return IsBlockEmpty (tmpBV);
		case BlockDirection.Back: 
			tmpBV.z -= 1;
			return IsBlockEmpty (tmpBV);
		default :
			return false;
		}
	}
Example #34
0
    public static void BuildColors(Chunk chunk, BlockPos pos, MeshData meshData, BlockDirection blockDirection)
    {
        bool nSolid = false;
        bool eSolid = false;
        bool sSolid = false;
        bool wSolid = false;

        bool wnSolid = false;
        bool neSolid = false;
        bool esSolid = false;
        bool swSolid = false;

        float light = 0;

        switch (blockDirection)
        {
        case BlockDirection.up:
            nSolid = chunk.GetBlock(pos.Add(0, 1, 1)).controller.IsSolid(BlockDirection.south);
            eSolid = chunk.GetBlock(pos.Add(1, 1, 0)).controller.IsSolid(BlockDirection.west);
            sSolid = chunk.GetBlock(pos.Add(0, 1, -1)).controller.IsSolid(BlockDirection.north);
            wSolid = chunk.GetBlock(pos.Add(-1, 1, 0)).controller.IsSolid(BlockDirection.east);

            wnSolid = chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(BlockDirection.east) && chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(BlockDirection.south);
            neSolid = chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(BlockDirection.south) && chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(BlockDirection.west);
            esSolid = chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(BlockDirection.west) && chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(BlockDirection.north);
            swSolid = chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(BlockDirection.north) && chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(BlockDirection.east);

            light = chunk.GetBlock(pos.Add(0, 1, 0)).data1 / 255f;

            break;

        case BlockDirection.down:
            nSolid = chunk.GetBlock(pos.Add(0, -1, -1)).controller.IsSolid(BlockDirection.south);
            eSolid = chunk.GetBlock(pos.Add(1, -1, 0)).controller.IsSolid(BlockDirection.west);
            sSolid = chunk.GetBlock(pos.Add(0, -1, 1)).controller.IsSolid(BlockDirection.north);
            wSolid = chunk.GetBlock(pos.Add(-1, -1, 0)).controller.IsSolid(BlockDirection.east);

            wnSolid = chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(BlockDirection.east) && chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(BlockDirection.south);
            neSolid = chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(BlockDirection.south) && chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(BlockDirection.west);
            esSolid = chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(BlockDirection.west) && chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(BlockDirection.north);
            swSolid = chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(BlockDirection.north) && chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(BlockDirection.east);

            light = chunk.GetBlock(pos.Add(0, -1, 0)).data1 / 255f;

            break;

        case BlockDirection.north:
            nSolid = chunk.GetBlock(pos.Add(1, 0, 1)).controller.IsSolid(BlockDirection.west);
            eSolid = chunk.GetBlock(pos.Add(0, 1, 1)).controller.IsSolid(BlockDirection.down);
            sSolid = chunk.GetBlock(pos.Add(-1, 0, 1)).controller.IsSolid(BlockDirection.east);
            wSolid = chunk.GetBlock(pos.Add(0, -1, 1)).controller.IsSolid(BlockDirection.up);

            esSolid = chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(BlockDirection.east) && chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(BlockDirection.south);
            neSolid = chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(BlockDirection.south) && chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(BlockDirection.west);
            wnSolid = chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(BlockDirection.west) && chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(BlockDirection.north);
            swSolid = chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(BlockDirection.north) && chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(BlockDirection.east);

            light = chunk.GetBlock(pos.Add(0, 0, 1)).data1 / 255f;

            break;

        case BlockDirection.east:
            nSolid = chunk.GetBlock(pos.Add(1, 0, -1)).controller.IsSolid(BlockDirection.up);
            eSolid = chunk.GetBlock(pos.Add(1, 1, 0)).controller.IsSolid(BlockDirection.west);
            sSolid = chunk.GetBlock(pos.Add(1, 0, 1)).controller.IsSolid(BlockDirection.down);
            wSolid = chunk.GetBlock(pos.Add(1, -1, 0)).controller.IsSolid(BlockDirection.east);

            esSolid = chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(BlockDirection.west) && chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(BlockDirection.north);
            neSolid = chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(BlockDirection.south) && chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(BlockDirection.west);
            wnSolid = chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(BlockDirection.east) && chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(BlockDirection.north);
            swSolid = chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(BlockDirection.north) && chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(BlockDirection.east);

            light = chunk.GetBlock(pos.Add(1, 0, 0)).data1 / 255f;

            break;

        case BlockDirection.south:
            nSolid = chunk.GetBlock(pos.Add(-1, 0, -1)).controller.IsSolid(BlockDirection.down);
            eSolid = chunk.GetBlock(pos.Add(0, 1, -1)).controller.IsSolid(BlockDirection.west);
            sSolid = chunk.GetBlock(pos.Add(1, 0, -1)).controller.IsSolid(BlockDirection.up);
            wSolid = chunk.GetBlock(pos.Add(0, -1, -1)).controller.IsSolid(BlockDirection.south);

            esSolid = chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(BlockDirection.west) && chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(BlockDirection.north);
            neSolid = chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(BlockDirection.south) && chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(BlockDirection.west);
            wnSolid = chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(BlockDirection.east) && chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(BlockDirection.north);
            swSolid = chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(BlockDirection.north) && chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(BlockDirection.east);

            light = chunk.GetBlock(pos.Add(0, 0, -1)).data1 / 255f;

            break;

        case BlockDirection.west:
            nSolid = chunk.GetBlock(pos.Add(-1, 0, 1)).controller.IsSolid(BlockDirection.up);
            eSolid = chunk.GetBlock(pos.Add(-1, 1, 0)).controller.IsSolid(BlockDirection.west);
            sSolid = chunk.GetBlock(pos.Add(-1, 0, -1)).controller.IsSolid(BlockDirection.down);
            wSolid = chunk.GetBlock(pos.Add(-1, -1, 0)).controller.IsSolid(BlockDirection.east);

            esSolid = chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(BlockDirection.west) && chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(BlockDirection.north);
            neSolid = chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(BlockDirection.south) && chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(BlockDirection.west);
            wnSolid = chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(BlockDirection.east) && chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(BlockDirection.north);
            swSolid = chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(BlockDirection.north) && chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(BlockDirection.east);

            light = chunk.GetBlock(pos.Add(-1, 0, 0)).data1 / 255f;

            break;

        default:
            Debug.LogError("BlockDirection not recognized");
            break;
        }

        AddColors(meshData, wnSolid, nSolid, neSolid, eSolid, esSolid, sSolid, swSolid, wSolid, light);
    }
Example #35
0
	public ISSCBlockVector SurroundingBlock (ISSCBlockVector position, BlockDirection direction)
	{
		ISSCBlockVector tmpBV = new ISSCBlockVector ();
		tmpBV = position;
		switch (direction) {
		case BlockDirection.Up: 
			tmpBV.y += 1;
			return tmpBV;
		case BlockDirection.Down: 
			tmpBV.y -= 1;
			return tmpBV;
		case BlockDirection.Right: 
			tmpBV.x += 1;
			return tmpBV;
		case BlockDirection.Left: 
			tmpBV.x -= 1;
			return tmpBV;
		case BlockDirection.Forward: 
			tmpBV.z += 1;
			return tmpBV;
		case BlockDirection.Back: 
			tmpBV.z -= 1;
			return tmpBV;
		}
		return tmpBV;
	}
Example #36
0
    public bool BlockMoveIsValid(Vector3 blockPos, BlockDirection dir, out BlockPuzzleTileInfo tileInfo)
    {
        tileInfo = new BlockPuzzleTileInfo();
        var tiles = GetTilePositions();

        BlockPuzzleTileInfo newTile = new BlockPuzzleTileInfo();

        newTile.Pos       = Vector3.one * float.PositiveInfinity;
        newTile.TileState = BlockPuzzleTileState.Invalid;

        float alignThreshold = 0.1f;

        foreach (var tile in tiles)
        {
            bool tileAlignsCorrectly = false;

            switch (dir)
            {
            case BlockDirection.Forward:
                if (tile.Pos.z > blockPos.z && Mathf.Abs(tile.Pos.x - blockPos.x) < alignThreshold)
                {
                    tileAlignsCorrectly = true;
                }
                break;

            case BlockDirection.Right:
                if (tile.Pos.x > blockPos.x && Mathf.Abs(tile.Pos.z - blockPos.z) < alignThreshold)
                {
                    tileAlignsCorrectly = true;
                }
                break;

            case BlockDirection.Backward:
                if (tile.Pos.z < blockPos.z && Mathf.Abs(tile.Pos.x - blockPos.x) < alignThreshold)
                {
                    tileAlignsCorrectly = true;
                }
                break;

            case BlockDirection.Left:
                if (tile.Pos.x < blockPos.x && Mathf.Abs(tile.Pos.z - blockPos.z) < alignThreshold)
                {
                    tileAlignsCorrectly = true;
                }
                break;

            case BlockDirection.Null:
                return(false);
            }

            if (tileAlignsCorrectly && Vector3.Distance(blockPos, tile.Pos) < Vector3.Distance(blockPos, newTile.Pos))
            {
                newTile = tile;
            }
        }

        tileInfo = newTile;

        // Checking that if Tia is pushed back she wont be forced into an invalid tile.
        if (tileInfo.TileState == BlockPuzzleTileState.Player)
        {
            BlockPuzzleTileInfo tempTile;
            bool validMove = BlockMoveIsValid(newTile.Pos, dir, out tempTile);
            bool onGrid    = GridContainsPoint(tileInfo.Pos + new Vector3(DirectionToVector(dir).x *pTileDims.x, 0f, DirectionToVector(dir).z *pTileDims.y));
            return(validMove || !onGrid);
        }

        if (tileInfo.TileState == BlockPuzzleTileState.Valid)
        {
            return(true);
        }
        return(false);
    }