在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Overv/WebCraft开源软件地址(OpenSource Url):https://github.com/Overv/WebCraft开源编程语言(OpenSource Language):JavaScript 88.5%开源软件介绍(OpenSource Introduction):WebCraft (HTML5 Minecraft)This project is no longer actively maintained! This project is intended to become a Minecraft Classic clone using HTML 5 technologies, most notably WebGL and WebSockets. No third-party libraries are used, with the exception of glmatrix and socket.io. People who have written similar demos used libraries such as three.js, but it is both foolish and inefficient to use a 3D engine for rendering large amount of blocks. ScreenshotsStructure
ModulesThe two front-ends invoke the available modules to deliver the components necessary for the gameplay and graphics of either the singleplayer or multiplayer experience. The available modules are listed below. Blocks.js This is the most moddable module, as it contains the structure with the available block materials and their respective properties. It also contains functions invoked by the render class for proper shading and lighting of blocks. World.js This is the base class, which all other modules depend on. Although it is a very important module, it is also the most passive module. It contains the block structure of the world and exposes functions for manipulating it. Physics.js This module has strong roots in the world class and simulates the flow of fluid blocks and the gravity of falling blocks at regular intervals. It has no specific parameters and is simply invoked in the game loop to update the world. Render.js This is the module that takes care of visualizing the block structure in the world class. When a world is assigned to it, it sets up a structure of chunks that are updated when a block changes. These chunks are mostly just fancy Vertex Buffer Objects. As this module takes care of the rendering, it also houses the code that deals with picking (getting a block from an x, y position on the screen). Player.js Finally there is also the module that handles everything related to the player of the game. Surprising, perhaps, is that it also deals with the physics and collision of the player. Less surprising is that it manages the material selector and input and responds to it in an update function, just like the physics module. Network.js This module makes it easy to synchronize a world between a server and connected clients. It comes with both a Client and Server class to facilitate all of your networking needs. Typical game set-upFirst a new world is created and the block structure is initialised.
The 6 in createFlatWorld here is the line between the ground and the first air layer. Now that we have a world, we can set up a renderer, which will subsequently divide the world into chunks for rendering.
The 8 here determines the XYZ size of one chunk. In this case the entire world consists out of 8 chunks. To finish the code that deals with world management, we create the physics simulator.
And finally, we add a local player to the game:
That concludes the set-up code. The render loop can be constructed with a timer on a fixed framerate:
To see how the material selector and canvas can be set-up, have a look at singleplayer.html and style/main.css. Note that the player and physics modules are entirely optional, so you could just as well use this code as a base for making a Minecraft map viewer on your website. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论