├── Assets ├── Models │ ├── Arm.mtl │ ├── Arm.obj │ ├── Block.mtl │ └── Block.obj ├── SFX │ └── Punch_Sound.wav └── Textures │ ├── Arm_Texture.png │ ├── Brick_Block.png │ ├── Dirt_Block.png │ ├── Grass_Block.png │ ├── Old Textures │ ├── Arm_Texture.png │ ├── Brick_Block.png │ ├── Dirt_Block.png │ ├── Grass_Block.png │ └── Stone_Block.png │ ├── Skybox.png │ ├── Stone_Block.png │ └── Wood_Block.png ├── Main.py └── README.md /Assets/Models/Arm.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'arm.blend' 2 | # Material Count: 1 3 | 4 | newmtl Arm 5 | Ns 0.297520 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.800000 0.800000 0.800000 8 | Ks 0.315152 0.315152 0.315152 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.450000 11 | d 1.000000 12 | illum 2 13 | map_Kd arm.png 14 | -------------------------------------------------------------------------------- /Assets/Models/Arm.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.83.0 OBJ File: 'arm.blend' 2 | # www.blender.org 3 | mtllib arm.mtl 4 | o Cube_Cube.001 5 | v 0.000000 -0.500000 0.000000 6 | v 0.000000 0.500000 0.000000 7 | v 0.000000 -0.500000 -3.000000 8 | v 0.000000 0.500000 -3.000000 9 | v 1.000000 -0.500000 0.000000 10 | v 1.000000 0.500000 0.000000 11 | v 1.000000 -0.500000 -3.000000 12 | v 1.000000 0.500000 -3.000000 13 | vt 0.930330 0.500000 14 | vt 0.930330 0.622951 15 | vt 0.561476 0.622951 16 | vt 0.561476 0.500000 17 | vt 0.438524 0.622951 18 | vt 0.438524 0.500000 19 | vt 0.069670 0.622951 20 | vt 0.069670 0.500000 21 | vt 0.438524 0.131146 22 | vt 0.438524 0.008194 23 | vt 0.561476 0.008194 24 | vt 0.561476 0.131146 25 | vt 0.561476 0.991806 26 | vt 0.438524 0.991806 27 | vn -1.0000 0.0000 0.0000 28 | vn 0.0000 0.0000 -1.0000 29 | vn 1.0000 0.0000 0.0000 30 | vn 0.0000 0.0000 1.0000 31 | vn 0.0000 -1.0000 0.0000 32 | vn 0.0000 1.0000 0.0000 33 | usemtl Arm 34 | s off 35 | f 1/1/1 2/2/1 4/3/1 3/4/1 36 | f 3/4/2 4/3/2 8/5/2 7/6/2 37 | f 7/6/3 8/5/3 6/7/3 5/8/3 38 | f 5/9/4 6/10/4 2/11/4 1/12/4 39 | f 3/4/5 7/6/5 5/9/5 1/12/5 40 | f 8/5/6 4/3/6 2/13/6 6/14/6 41 | -------------------------------------------------------------------------------- /Assets/Models/Block.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'None' 2 | # Material Count: 1 3 | 4 | newmtl Stone 5 | Ns 225.000000 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.800000 0.800000 0.800000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.450000 11 | d 1.000000 12 | illum 2 13 | map_Kd grass_block.png 14 | -------------------------------------------------------------------------------- /Assets/Models/Block.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.81 (sub 16) OBJ File: '' 2 | # www.blender.org 3 | mtllib block.mtl 4 | o Cube 5 | v -1.000000 -1.000000 1.000000 6 | v -1.000000 1.000000 1.000000 7 | v -1.000000 -1.000000 -1.000000 8 | v -1.000000 1.000000 -1.000000 9 | v 1.000000 -1.000000 1.000000 10 | v 1.000000 1.000000 1.000000 11 | v 1.000000 -1.000000 -1.000000 12 | v 1.000000 1.000000 -1.000000 13 | vt 0.375000 0.000000 14 | vt 0.625000 0.000000 15 | vt 0.625000 0.250000 16 | vt 0.375000 0.250000 17 | vt 0.625000 0.500000 18 | vt 0.375000 0.500000 19 | vt 0.625000 0.750000 20 | vt 0.375000 0.750000 21 | vt 0.625000 1.000000 22 | vt 0.375000 1.000000 23 | vt 0.125000 0.500000 24 | vt 0.125000 0.750000 25 | vt 0.875000 0.500000 26 | vt 0.875000 0.750000 27 | vn -1.0000 0.0000 0.0000 28 | vn 0.0000 0.0000 -1.0000 29 | vn 1.0000 0.0000 0.0000 30 | vn 0.0000 0.0000 1.0000 31 | vn 0.0000 -1.0000 0.0000 32 | vn 0.0000 1.0000 0.0000 33 | usemtl Stone 34 | s off 35 | f 1/1/1 2/2/1 4/3/1 3/4/1 36 | f 3/4/2 4/3/2 8/5/2 7/6/2 37 | f 7/6/3 8/5/3 6/7/3 5/8/3 38 | f 5/8/4 6/7/4 2/9/4 1/10/4 39 | f 3/11/5 7/6/5 5/8/5 1/12/5 40 | f 8/5/6 4/13/6 2/14/6 6/7/6 41 | -------------------------------------------------------------------------------- /Assets/SFX/Punch_Sound.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/SFX/Punch_Sound.wav -------------------------------------------------------------------------------- /Assets/Textures/Arm_Texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/Textures/Arm_Texture.png -------------------------------------------------------------------------------- /Assets/Textures/Brick_Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/Textures/Brick_Block.png -------------------------------------------------------------------------------- /Assets/Textures/Dirt_Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/Textures/Dirt_Block.png -------------------------------------------------------------------------------- /Assets/Textures/Grass_Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/Textures/Grass_Block.png -------------------------------------------------------------------------------- /Assets/Textures/Old Textures/Arm_Texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/Textures/Old Textures/Arm_Texture.png -------------------------------------------------------------------------------- /Assets/Textures/Old Textures/Brick_Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/Textures/Old Textures/Brick_Block.png -------------------------------------------------------------------------------- /Assets/Textures/Old Textures/Dirt_Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/Textures/Old Textures/Dirt_Block.png -------------------------------------------------------------------------------- /Assets/Textures/Old Textures/Grass_Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/Textures/Old Textures/Grass_Block.png -------------------------------------------------------------------------------- /Assets/Textures/Old Textures/Stone_Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/Textures/Old Textures/Stone_Block.png -------------------------------------------------------------------------------- /Assets/Textures/Skybox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/Textures/Skybox.png -------------------------------------------------------------------------------- /Assets/Textures/Stone_Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/Textures/Stone_Block.png -------------------------------------------------------------------------------- /Assets/Textures/Wood_Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spyder-0/Minecraft-with-Python/7d344668f4a8f6490f92cc9a7687e444bb64ae91/Assets/Textures/Wood_Block.png -------------------------------------------------------------------------------- /Main.py: -------------------------------------------------------------------------------- 1 | # Tutorial https://www.youtube.com/watch?v=DHSRaVeQxIk 2 | 3 | from turtle import position, pu 4 | from ursina import * 5 | from ursina.prefabs.first_person_controller import FirstPersonController 6 | 7 | app = Ursina() 8 | 9 | # Variables 10 | grass_texture = load_texture("Assets/Textures/Grass_Block.png") 11 | stone_texture = load_texture("Assets/Textures/Stone_Block.png") 12 | brick_texture = load_texture("Assets/Textures/Brick_Block.png") 13 | dirt_texture = load_texture("Assets/Textures/Dirt_Block.png") 14 | wood_texture = load_texture("Assets/Textures/Wood_Block.png") 15 | sky_texture = load_texture("Assets/Textures/Skybox.png") 16 | arm_texture = load_texture("Assets/Textures/Arm_Texture.png") 17 | punch_sound = Audio("Assets/SFX/Punch_Sound.wav", loop = False, autoplay = False) 18 | window.exit_button.visible = False 19 | block_pick = 1 20 | 21 | # Updates every frame 22 | def update(): 23 | global block_pick 24 | 25 | if held_keys["left mouse"] or held_keys["right mouse"]: 26 | hand.active() 27 | else: 28 | hand.passive() 29 | 30 | if held_keys["1"]: block_pick = 1 31 | if held_keys["2"]: block_pick = 2 32 | if held_keys["3"]: block_pick = 3 33 | if held_keys["4"]: block_pick = 4 34 | if held_keys["5"]: block_pick = 5 35 | 36 | 37 | 38 | # Voxel (block) properties 39 | class Voxel(Button): 40 | def __init__(self, position = (0, 0, 0), texture = grass_texture): 41 | super().__init__( 42 | parent = scene, 43 | position = position, 44 | model = "Assets/Models/Block", 45 | origin_y = 0.5, 46 | texture = texture, 47 | color = color.color(0, 0, random.uniform(0.9, 1)), 48 | highlight_color = color.light_gray, 49 | scale = 0.5 50 | ) 51 | 52 | # What happens to blocks on inputs 53 | def input(self,key): 54 | if self.hovered: 55 | if key == "left mouse down": 56 | punch_sound.play() 57 | if block_pick == 1: voxel = Voxel(position = self.position + mouse.normal, texture = grass_texture) 58 | if block_pick == 2: voxel = Voxel(position = self.position + mouse.normal, texture = stone_texture) 59 | if block_pick == 3: voxel = Voxel(position = self.position + mouse.normal, texture = brick_texture) 60 | if block_pick == 4: voxel = Voxel(position = self.position + mouse.normal, texture = dirt_texture) 61 | if block_pick == 5: voxel = Voxel(position = self.position + mouse.normal, texture = wood_texture) 62 | 63 | 64 | if key == "right mouse down": 65 | punch_sound.play() 66 | destroy(self) 67 | 68 | # Skybox 69 | class Sky(Entity): 70 | def __init__(self): 71 | super().__init__( 72 | parent = scene, 73 | model = "Sphere", 74 | texture = sky_texture, 75 | scale = 150, 76 | double_sided = True 77 | ) 78 | 79 | # Arm 80 | class Hand(Entity): 81 | def __init__(self): 82 | super().__init__( 83 | parent = camera.ui, 84 | model = "Assets/Models/Arm", 85 | texture = arm_texture, 86 | scale = 0.2, 87 | rotation = Vec3(150, -10, 0), 88 | position = Vec2(0.4, -0.6) 89 | ) 90 | 91 | def active(self): 92 | self.position = Vec2(0.3, -0.5) 93 | 94 | def passive(self): 95 | self.position = Vec2(0.4, -0.6) 96 | 97 | # Increase the numbers for more cubes. For exapmle: for z in range(20) 98 | for z in range(20): 99 | for x in range(20): 100 | voxel = Voxel(position = (x, 0, z)) 101 | 102 | 103 | player = FirstPersonController() 104 | sky = Sky() 105 | hand = Hand() 106 | 107 | 108 | app.run() 109 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Minecraft with Python (Ursina Engine) 2 | A simple Minecraft game made with Python (Ursina Engine). 3 | 4 | ![image](https://user-images.githubusercontent.com/85440857/161966105-5a920a97-7d65-44ec-b126-cbc8eff0ae65.png) 5 | 6 | # Controls 7 | | Key | Description | 8 | | :---: | :---: | 9 | | `WASD` | Move | 10 | | `Mouse` | Camera Rotation | 11 | | `Left Click` | Place Block | 12 | | `Right Click` | Remove Block | 13 | | `1 - 4` | Switch Blocks | 14 | 15 | # About 16 | - This was made using ClearCode's [tutorial](https://www.youtube.com/watch?v=DHSRaVeQxIk) with some more modifications.
17 | - Ensure you have the Ursina library installed: `pip install ursina`. 18 | --------------------------------------------------------------------------------