Skip to content

Commit a270484

Browse files
Merge pull request Mayank94043626#98 from benedictprajwal/master
Minecraft Game - Python Project
2 parents 4f90cab + 302406f commit a270484

File tree

20 files changed

+330
-0
lines changed

20 files changed

+330
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
from ursina import *
2+
from ursina.prefabs.first_person_controller import FirstPersonController
3+
4+
app = Ursina()
5+
grass_texture = load_texture('assets/grass_block.png')
6+
stone_texture = load_texture('assets/stone_block.png')
7+
brick_texture = load_texture('assets/brick_block.png')
8+
dirt_texture = load_texture('assets/dirt_block.png')
9+
sky_texture = load_texture('assets/skybox.png')
10+
arm_texture = load_texture('assets/arm_texture.png')
11+
punch_sound = Audio('assets/punch_sound',loop = False, autoplay = False)
12+
block_pick = 1
13+
14+
window.fps_counter.enabled = False
15+
window.exit_button.visible = False
16+
17+
def update():
18+
global block_pick
19+
20+
if held_keys['left mouse'] or held_keys['right mouse']:
21+
hand.active()
22+
else:
23+
hand.passive()
24+
25+
if held_keys['1']: block_pick = 1
26+
if held_keys['2']: block_pick = 2
27+
if held_keys['3']: block_pick = 3
28+
if held_keys['4']: block_pick = 4
29+
30+
class Voxel(Button):
31+
def __init__(self, position = (0,0,0), texture = grass_texture):
32+
super().__init__(
33+
parent = scene,
34+
position = position,
35+
model = 'assets/block',
36+
origin_y = 0.5,
37+
texture = texture,
38+
color = color.color(0,0,random.uniform(0.9,1)),
39+
scale = 0.5)
40+
41+
def input(self,key):
42+
if self.hovered:
43+
if key == 'left mouse down':
44+
punch_sound.play()
45+
if block_pick == 1: voxel = Voxel(position = self.position + mouse.normal, texture = grass_texture)
46+
if block_pick == 2: voxel = Voxel(position = self.position + mouse.normal, texture = stone_texture)
47+
if block_pick == 3: voxel = Voxel(position = self.position + mouse.normal, texture = brick_texture)
48+
if block_pick == 4: voxel = Voxel(position = self.position + mouse.normal, texture = dirt_texture)
49+
50+
if key == 'right mouse down':
51+
punch_sound.play()
52+
destroy(self)
53+
54+
class Sky(Entity):
55+
def __init__(self):
56+
super().__init__(
57+
parent = scene,
58+
model = 'sphere',
59+
texture = sky_texture,
60+
scale = 150,
61+
double_sided = True)
62+
63+
class Hand(Entity):
64+
def __init__(self):
65+
super().__init__(
66+
parent = camera.ui,
67+
model = 'assets/arm',
68+
texture = arm_texture,
69+
scale = 0.2,
70+
rotation = Vec3(150,-10,0),
71+
position = Vec2(0.4,-0.6))
72+
73+
def active(self):
74+
self.position = Vec2(0.3,-0.5)
75+
76+
def passive(self):
77+
self.position = Vec2(0.4,-0.6)
78+
79+
for z in range(20):
80+
for x in range(20):
81+
voxel = Voxel(position = (x,0,z))
82+
83+
player = FirstPersonController()
84+
sky = Sky()
85+
hand = Hand()
86+
87+
app.run()
Binary file not shown.
2.38 KB
Loading
Binary file not shown.
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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
21.1 KB
Loading
1.18 MB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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

0 commit comments

Comments
 (0)