Esempio n. 1
0
 public Player(Game game, BaseMouseKeyboard baseMouseKeyboard)
 {
     this.game              = game;
     this.health            = 100;
     this.baseMouseKeyboard = baseMouseKeyboard;
     this.flyingMode        = true;
     this.fallingSpeed      = 0;
     this.EnableCamera(new Camera(game, this, new Vector3(Settings.BLOCK_SIZE.X, Globals.perlin_noise.getPerlinNoise_MaxHeight() + (float)Settings.playerHeight + Globals.block_Yoffset, Settings.BLOCK_SIZE.Z)));
     this.rayBlock = new RayBlock(this);
     this.status   = new SpriteBatch_Handler(this);
 }
Esempio n. 2
0
        public static void plantTree(Vector3 position)
        {
            Vector3 pos, chunkHeight_DictionaryLocation;
            int     i, woodHeight = 5 + (((int)position.X + (int)position.Z) % 2);

            #region Wood Trunks

            for (i = 0; i < woodHeight; i++)
            {
                pos = new Vector3(position.X, position.Y + i, position.Z);
                if (!GameDictionaries.blocksDestroyedDictionary.ContainsKey(pos))
                {
                    GameDictionaries.blocksDictionary[pos] = BlockType.Wood_Trunk;
                }
            }

            #endregion Wood Trunks

            #region Leafs

            for (int x = (int)position.X - 2; x < (int)position.X + 3; x++)
            {
                for (int z = (int)position.Z - 2; z < (int)position.Z + 3; z++)
                {
                    chunkHeight_DictionaryLocation = RayBlock.getChunkOrigin_OffSet(new Vector3(x, 0, z), 0, 0, 0);
                    if ((GameDictionaries.chunksHeightDictionary.TryGetValue(chunkHeight_DictionaryLocation, out int heightValue) || true) && heightValue < ((int)position.Y + i + 1))
                    {
                        GameDictionaries.chunksHeightDictionary[chunkHeight_DictionaryLocation] = (int)position.Y + i + 1;
                    }
                    for (int y = (int)position.Y + i - 2; y < (int)position.Y + i + 2; y++)
                    {
                        if (x != position.X || z != position.Z || y > (int)position.Y + i - 1)
                        {
                            pos = new Vector3(x, y, z);
                            if (!GameDictionaries.blocksDestroyedDictionary.ContainsKey(pos))
                            {
                                GameDictionaries.blocksDictionary[pos] = BlockType.Leaf;
                            }
                        }
                    }
                }
            }
            #endregion Leafs
        }
Esempio n. 3
0
        private void AddBlock()
        {
            Vector3 addBlockOrigin = Raycast.Raycast_addBlockOrigin(player);

            #region Add The Block

            // Check for valid collision with the player and valid placement
            if (addBlockOrigin != new Vector3(0, -1, 0) &&
                !GameDictionaries.blocksAddedDictionary.ContainsKey(addBlockOrigin) &&
                !(GameDictionaries.blocksDictionary.TryGetValue(new Vector3(addBlockOrigin.X, addBlockOrigin.Y - Globals.block_Yoffset, addBlockOrigin.Z), out BlockType value1) && value1 == BlockType.Water) &&
                addBlockOrigin != Chunk.getBlockOffset(new Vector3((int)(player.camera.Position.X + Globals.saftyDistanceFromBlock), (int)(player.camera.Position.Y), (int)(player.camera.Position.Z + Globals.saftyDistanceFromBlock))) &&
                addBlockOrigin != Chunk.getBlockOffset(new Vector3((int)(player.camera.Position.X + Globals.saftyDistanceFromBlock), (int)(player.camera.Position.Y), (int)(player.camera.Position.Z - Globals.saftyDistanceFromBlock))) &&
                addBlockOrigin != Chunk.getBlockOffset(new Vector3((int)(player.camera.Position.X - Globals.saftyDistanceFromBlock), (int)(player.camera.Position.Y), (int)(player.camera.Position.Z + Globals.saftyDistanceFromBlock))) &&
                addBlockOrigin != Chunk.getBlockOffset(new Vector3((int)(player.camera.Position.X - Globals.saftyDistanceFromBlock), (int)(player.camera.Position.Y), (int)(player.camera.Position.Z - Globals.saftyDistanceFromBlock))) &&
                addBlockOrigin != Chunk.getBlockOffset(new Vector3((int)(player.camera.Position.X + Globals.saftyDistanceFromBlock), (int)(player.camera.Position.Y - Settings.playerHeight), (int)(player.camera.Position.Z + Globals.saftyDistanceFromBlock))) &&
                addBlockOrigin != Chunk.getBlockOffset(new Vector3((int)(player.camera.Position.X + Globals.saftyDistanceFromBlock), (int)(player.camera.Position.Y - Settings.playerHeight), (int)(player.camera.Position.Z - Globals.saftyDistanceFromBlock))) &&
                addBlockOrigin != Chunk.getBlockOffset(new Vector3((int)(player.camera.Position.X - Globals.saftyDistanceFromBlock), (int)(player.camera.Position.Y - Settings.playerHeight), (int)(player.camera.Position.Z + Globals.saftyDistanceFromBlock))) &&
                addBlockOrigin != Chunk.getBlockOffset(new Vector3((int)(player.camera.Position.X - Globals.saftyDistanceFromBlock), (int)(player.camera.Position.Y - Settings.playerHeight), (int)(player.camera.Position.Z - Globals.saftyDistanceFromBlock))))
            {
                // Add block to the dictionaries
                GameDictionaries.blocksDictionary[addBlockOrigin]      = Globals.addableBlockTypes[player.baseMouseKeyboard.mouseWheel_Value];
                GameDictionaries.blocksAddedDictionary[addBlockOrigin] = Globals.addableBlockTypes[player.baseMouseKeyboard.mouseWheel_Value];

                // Update the max chunk height if the block is above the current max height
                Vector3 chunk_offset = RayBlock.getChunkOrigin_OffSet(new Vector3(addBlockOrigin.X, 0, addBlockOrigin.Z), 0, 0, 0);
                if ((int)addBlockOrigin.Y > World.maxHeightInChunk((int)chunk_offset.X, (int)chunk_offset.Z))
                {
                    GameDictionaries.chunksHeightDictionary[chunk_offset] = (int)addBlockOrigin.Y;
                }

                // Build chunks mesh
                BuildChunksAroundMesh(addBlockOrigin);
            }

            #endregion Add The Block
        }
Esempio n. 4
0
        private void BuildChunksAroundMesh(Vector3 blockOrigin)
        {
            #region Current Chunk

            Vector3 chunk_offset = RayBlock.getChunkOrigin_OffSet(blockOrigin, 0, 0, 0);
            if (!GameDictionaries.chunksRenderingDictionary.ContainsKey(chunk_offset))
            {
                GameDictionaries.chunksRenderingDictionary[chunk_offset] = new Chunk(chunk_offset);
                GameDictionaries.chunksHeightDictionary[new Vector3(chunk_offset.X, 0, chunk_offset.Z)] = (int)chunk_offset.Y + Settings.CHUNK_SIZE;
            }
            GameDictionaries.chunksRenderingDictionary[chunk_offset].BuildChunkMesh();

            #endregion Current Chunk

            #region Chunks Around

            #region PX Chunk

            if (GameDictionaries.blocksDictionary.ContainsKey(new Vector3(blockOrigin.X + Globals.block_Xoffset, blockOrigin.Y, blockOrigin.Z)))
            {
                chunk_offset = RayBlock.getChunkOrigin_OffSet(blockOrigin, 1, 0, 0);
                if (GameDictionaries.chunksRenderingDictionary.ContainsKey(chunk_offset))
                {
                    GameDictionaries.chunksRenderingDictionary[chunk_offset].BuildChunkMesh();
                }
            }

            #endregion PX Chunk

            #region NX Chunk

            if (GameDictionaries.blocksDictionary.ContainsKey(new Vector3(blockOrigin.X - Globals.block_Xoffset, blockOrigin.Y, blockOrigin.Z)))
            {
                chunk_offset = RayBlock.getChunkOrigin_OffSet(blockOrigin, -1, 0, 0);
                if (GameDictionaries.chunksRenderingDictionary.ContainsKey(chunk_offset))
                {
                    GameDictionaries.chunksRenderingDictionary[chunk_offset].BuildChunkMesh();
                }
            }

            #endregion NX Chunk

            #region PY Chunk

            if (GameDictionaries.blocksDictionary.ContainsKey(new Vector3(blockOrigin.X, blockOrigin.Y + Globals.block_Yoffset, blockOrigin.Z)))
            {
                chunk_offset = RayBlock.getChunkOrigin_OffSet(blockOrigin, 0, 1, 0);
                if (GameDictionaries.chunksRenderingDictionary.ContainsKey(chunk_offset))
                {
                    GameDictionaries.chunksRenderingDictionary[chunk_offset].BuildChunkMesh();
                }
            }

            #endregion PY Chunk

            #region NY Chunk

            if (GameDictionaries.blocksDictionary.ContainsKey(new Vector3(blockOrigin.X, blockOrigin.Y - Globals.block_Yoffset, blockOrigin.Z)))
            {
                chunk_offset = RayBlock.getChunkOrigin_OffSet(blockOrigin, 0, -1, 0);
                if (GameDictionaries.chunksRenderingDictionary.ContainsKey(chunk_offset))
                {
                    GameDictionaries.chunksRenderingDictionary[chunk_offset].BuildChunkMesh();
                }
            }

            #endregion NY Chunk

            #region PZ Chunk

            if (GameDictionaries.blocksDictionary.ContainsKey(new Vector3(blockOrigin.X, blockOrigin.Y, blockOrigin.Z + Globals.block_Zoffset)))
            {
                chunk_offset = RayBlock.getChunkOrigin_OffSet(blockOrigin, 0, 0, 1);
                if (GameDictionaries.chunksRenderingDictionary.ContainsKey(chunk_offset))
                {
                    GameDictionaries.chunksRenderingDictionary[chunk_offset].BuildChunkMesh();
                }
            }

            #endregion PZ Chunk

            #region NZ Chunk

            if (GameDictionaries.blocksDictionary.ContainsKey(new Vector3(blockOrigin.X, blockOrigin.Y, blockOrigin.Z - Globals.block_Zoffset)))
            {
                chunk_offset = RayBlock.getChunkOrigin_OffSet(blockOrigin, 0, 0, -1);
                if (GameDictionaries.chunksRenderingDictionary.ContainsKey(chunk_offset))
                {
                    GameDictionaries.chunksRenderingDictionary[chunk_offset].BuildChunkMesh();
                }
            }

            #endregion NZ Chunk

            #endregion Chunks Around
        }