-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminecraft.py
More file actions
121 lines (83 loc) · 2.79 KB
/
minecraft.py
File metadata and controls
121 lines (83 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# pip install - ursina
# pip install - pygame
import pygame
pygame.mixer.init()
pygame.init()
from ursina import*
import ursina
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()
window.title= "Python's MineCraft"
window.borderless = False
window.exit_button.visible = False
grass_texture = load_texture("Assets/grass.jpg")
sky_texture = load_texture("Assets/sky.jpg")
soil_texture = load_texture("Assets/ground.jpg")
stone_texture = load_texture("Assets/wall.png")
wood_texture = load_texture("Assets/sand.jpg")
lava_texture = load_texture("Assets/lava.png")
water_textue = load_texture("Assets/water.jpg")
current_texture = grass_texture
def update():
global current_texture
if held_keys['1']: current_texture = grass_texture
if held_keys['2']: current_texture = soil_texture
if held_keys['3']: current_texture = stone_texture
if held_keys['4']: current_texture = wood_texture
if held_keys['5']: current_texture = lava_texture
if held_keys['6']: current_texture = water_textue
if held_keys["left mouse"] or held_keys["right mouse"]:
hand.active()
pygame.mixer.music.load('Assets/wing.mp3')
pygame.mixer.music.play()
else:
hand.passive()
class Sky(Entity):
def __init__(self):
super().__init__(
parent = scene,
model = "sphere",
scale = 150,
texture = sky_texture,
double_sided = True
)
class Hand(Entity):
def __init__(self):
super().__init__(
parent = camera.ui,
model = "cube",
scale = (0.2,0.3),
color = color.salmon,
rotation = Vec3(150, -10, 0),
position = Vec2(0.4, -0.4)
)
def active(self):
self.position = Vec2(0.1, -0.5)
self.rotation = Vec3(90,-10,0)
def passive(self):
self.rotation = Vec3(150, -10, 0)
self.position = Vec2(0.4, -0.4)
class Voxel(Button):
def __init__(self, position= (0,0,0), texture = (grass_texture)):
super().__init__(
parent = scene,
model = "cube",
color = color.white,
highlight_color = color.lime,
texture = texture,
position = position,
origin_y= 0.50
)
def input(self,key):
if self.hovered:
if key == "left mouse down":
voxel = Voxel(position= self.position + mouse.normal, texture= current_texture)
if key == "right mouse down":
destroy(self)
for z in range(50):
for x in range(50):
voxel = Voxel((x,0,z))
player = FirstPersonController()
sky = Sky()
hand = Hand()
app.run()