Use W, S, A, D, Space, X to move forward,backward, left, right, up, down. Use Q, R to accelerate or slow down move speed. Use G to enable gravity effect. Use ESC to exit the game.
Generate simple map.Enable movement, jump, collision detection.locate object, create or destroy an object.Add light and shadow.
- Map generation is implemented by a random height map;
- The movement is done by changing the view matrix according to keyboard and mouse inputs.
- Jump is implemented by a timer to reduce the increase of height.
- Because the objects in MC are all rectangle, AABB collision detection algorithm can be used.
- To locate the object in front of the player, the point centered in the screen has to been projected back to its 3D coordinate, then a vector can be got, which can be seen as a ray to be delivered to intersect with blocks in the world. If it touches a block, then calculate the direction from where it touches, so that we can know where to put the new block.
- Lights such as ambient lighting, diffuse lighting or specular lighting are all can be done by a normal vector and a fragment shader.
- Shadow is the most difficult component which requires render current objects to a depth map with a frame buffer, then rerender objects with this depth map. When the depth of the new renderer objects is not larger than the depth map, this place will be dimmed.