Example #1
0
        /// <summary>
        /// 设置泥块
        /// </summary>
        /// <param name="newClod">新的泥块</param>
        /// <param name="x">X</param>
        /// <param name="y">Y</param>
        /// <param name="z">Z</param>
        /// <returns>是否可以设置</returns>
        public bool setClod(Clod newClod, int x, int y, int z)
        {
            //计算岛屿和方块在岛屿的坐标
            int ix = (x) >> 4;
            int iz = (z) >> 4;
            int cx = (x) & 15;
            int cy = (y) & 127;
            int cz = (z) & 15;

            //获取岛屿指针
            Island island = getIsland(ix, iz);

            if (island != null)
            {
                //超出限制当然要踢出!当然这不可能!
                if (cx < 0 || cx >= 16 || cy < 0 || cy >= 128 || cz < 0 || cz >= 16)
                {
                    return(false);
                }

                //设置。。
                island.clods[cx, cy, cz] = newClod;

                //更新网格,貌似要删掉?
                island.createMesh();

                //更新岛屿网格
                if (cx == 0)
                {
                    getIsland(ix - 1, iz).createMesh();
                }
                else if (cx == 15)
                {
                    getIsland(ix + 1, iz).createMesh();
                }
                if (cz == 0)
                {
                    getIsland(ix, iz - 1).createMesh();
                }
                else if (cz == 15)
                {
                    getIsland(ix, iz + 1).createMesh();
                }

                return(true);
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// 还是抄的。。
        /// </summary>
        /// <param name="pos">依然是方块坐标</param>
        /// <param name="offset0">偏移量1</param>
        /// <param name="offset1">偏移量2</param>
        /// <param name="offset2">偏移量3</param>
        /// <returns></returns>
        public static Clod GetTheoreticalByte(Vector3 pos, Vector3 offset0, Vector3 offset1, Vector3 offset2)
        {
            float heightBase  = 16;
            float maxHeight   = 48;
            float heightSwing = maxHeight - heightBase;

            Clod clod = Clod.Air;

            float clusterValue  = CalculateNoiseValue(pos, offset1, 0.01f);
            float blobValue     = CalculateNoiseValue(pos, offset1, 0.03f);
            float mountainValue = CalculateNoiseValue(pos, offset0, 0.02f);

            if ((mountainValue == 0) && (blobValue < 0.72f))
            {
                clod = Clod.Air;
            }
            else if (clusterValue > 0.9f)
            {
                clod = Clod.Grass;
            }
            else if (clusterValue > 0.5f)
            {
                clod = Clod.Soil;
            }
            else if (clusterValue > 0.1f)
            {
                clod = Clod.Stone;
            }

            mountainValue = Mathf.Sqrt(mountainValue);

            mountainValue *= heightSwing;
            mountainValue += heightBase;

            mountainValue += (blobValue * 10) - 5f;



            if (mountainValue >= pos.y)
            {
                return(clod);
            }
            return(Clod.Air);
        }
Example #3
0
        void Update()
        {
            PlayerLing _ling = (PlayerLing)ling;

            float rotationX = gameObject.transform.localEulerAngles.y + Input.GetAxis("Mouse X") * 8f;

            rotationY += Input.GetAxis("Mouse Y") * 8f;
            rotationY  = Mathf.Clamp(rotationY, -80f, 80f);

            gameObject.transform.localEulerAngles = new Vector3(0, rotationX, 0);
            cameraObj.transform.localEulerAngles  = new Vector3(-rotationY, gameObject.transform.localEulerAngles.y, 0);

            Vector3 move = new Vector3(0f, 0f, 0f);

            if (Input.GetKey(KeyCode.W))
            {
                move += (Vector3.forward * Time.deltaTime) * (cc.isGrounded ? 4.5f : 3.5f);
            }

            if (Input.GetKey(KeyCode.S))
            {
                move += (Vector3.back * Time.deltaTime) * (cc.isGrounded ? 4.5f : 3.5f);
            }

            if (Input.GetKey(KeyCode.A))
            {
                move += (Vector3.left * Time.deltaTime) * (cc.isGrounded ? 4.5f : 3.5f);
            }

            if (Input.GetKey(KeyCode.D))
            {
                move += (Vector3.right * Time.deltaTime) * (cc.isGrounded ? 4.5f : 3.5f);
            }

            if (Input.GetKey(KeyCode.Space) && cc.isGrounded)
            {
                isJump = true;
            }

            if (isJump && (jumpY <= 1.5f))
            {
                move  += (Vector3.up * 10.0f * Time.deltaTime);
                jumpY += 5.5f * Time.deltaTime;
            }
            else
            {
                isJump = false;
                jumpY  = 0.00f;
            }

            move += (Vector3.down * 4.5f * Time.deltaTime);
            move  = gameObject.transform.rotation * move;

            cc.Move(gameObject.transform.TransformDirection(move));

            if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
            {
                RaycastHit hit;
                Ray        ray = cameraObj.GetComponent <Camera>().ViewportPointToRay(new Vector3(0.5f, 0.5f, 0.5f));
                if (Physics.Raycast(ray, out hit, 10f))
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        Vector3 p = hit.point;
                        p -= hit.normal / 4f;
                        sky.setClod(Clod.Air, Mathf.RoundToInt(p.x), Mathf.RoundToInt(p.y), Mathf.RoundToInt(p.z));
                    }


                    if (Input.GetMouseButtonDown(1))
                    {
                        Vector3 p = hit.point;
                        p += hit.normal / 4f;
                        sky.setClod(putClod, Mathf.RoundToInt(p.x), Mathf.RoundToInt(p.y), Mathf.RoundToInt(p.z));
                    }

                    if (Input.GetMouseButtonDown(2))
                    {
                        Vector3 p = hit.point;
                        p      -= hit.normal / 4f;
                        putClod = sky.getClod(Mathf.RoundToInt(p.x), Mathf.RoundToInt(p.y), Mathf.RoundToInt(p.z));
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.H))
            {
                sky.addLing(new Ling(sky), gameObject.transform.position + new Vector3(0f, 2f, 0f));
            }

            if (Input.GetKeyDown(KeyCode.J))
            {
                sky.addLing(new BlueJellyLing(sky), gameObject.transform.position + new Vector3(0f, 2f, 0f));
            }

            if (Input.GetKeyDown(KeyCode.F2))
            {
                transform.parent.Translate(Vector3.up * 100f);
            }

            if (_ling.ix != (int)gameObject.transform.position.x >> 4 ||
                _ling.iz != (int)gameObject.transform.position.z >> 4)
            {
                _ling.updateIsland();
            }
        }