-
Notifications
You must be signed in to change notification settings - Fork 3
/
labcraft.py
173 lines (130 loc) · 4.91 KB
/
labcraft.py
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from sims import *
window.borderless = False
app = Ursina()
grass_texture = load_texture('assets/grass_block.png')
stone_texture = load_texture('assets/stone_block.png')
brick_texture = load_texture('assets/brick_block.png')
dirt_texture = load_texture('assets/dirt_block.png')
sky_texture = load_texture('assets/skybox.png')
arm_texture = load_texture('assets/arm_texture.png')
osc_texture = load_texture('assets/osc_block.png')
earth_texture = load_texture('assets/earth_block.png')
mc_brick = load_texture('assets/mc_brick.png')
sun_texture = load_texture('assets/sun.png')
pendulum_texture = load_texture('assets/mc_brick.png')
punch_sound = Audio('assets/punch_sound',loop = False, autoplay = False)
block_pick = 1
window.fps_counter.enabled = False
window.exit_button.visible = False
debug = False
def update():
global block_pick
global debug
if held_keys['left mouse'] or held_keys['right mouse']:
hand.active()
else:
hand.passive()
if held_keys['1']: block_pick = 1
if held_keys['2']: block_pick = 2
if held_keys['3']: block_pick = 3
if held_keys['4']: block_pick = 4
if held_keys['5']: block_pick = 5
if held_keys['6']: block_pick = 6
if debug == True:
print(player.position.y)
# if player falls through the map, return to starting point.
if player.position.y < -10:
if debug == True:
print("falling!")
player.y = 1
player.x = 1
player.z = 1
class Voxel(Button):
def __init__(self, position = (0,0,0), texture = grass_texture):
super().__init__(
parent = scene,
position = position,
model = 'assets/block',
origin_y = 0.5,
texture = texture,
color = color.color(0,0,random.uniform(0.9,1)),
scale = 0.5)
def input(self,key):
if self.hovered:
if key == 'left mouse down':
punch_sound.play()
if block_pick == 1: voxel = Voxel(position = self.position + mouse.normal, texture = grass_texture)
if block_pick == 2: voxel = Voxel(position = self.position + mouse.normal, texture = stone_texture)
if block_pick == 3: voxel = Voxel(position = self.position + mouse.normal, texture = brick_texture)
if block_pick == 4: voxel = Voxel(position = self.position + mouse.normal, texture = dirt_texture)
if block_pick == 5: voxel = solarSystem(position = self.position + mouse.normal, texture = sun_texture)
if block_pick == 6: voxel = pendulum(position = self.position+mouse.normal, texture = pendulum_texture)
if key == 'right mouse down':
punch_sound.play()
destroy(self)
class Sky(Entity):
def __init__(self):
super().__init__(
parent = scene,
model = 'sphere',
texture = sky_texture,
scale = 150,
double_sided = True)
class Hand(Entity):
def __init__(self):
super().__init__(
parent = camera.ui,
model = 'assets/arm',
texture = arm_texture,
scale = 0.2,
rotation = Vec3(150,-10,0),
position = Vec2(0.4,-0.6))
def active(self):
self.position = Vec2(0.3,-0.5)
def passive(self):
self.position = Vec2(0.4,-0.6)
class pendulum(Button):
def __init__(self,position=(0,0,0), texture = pendulum_texture):
super().__init__(
parent = scene,
position = position,
model = 'assets/block',
texture = pendulum_texture,
color = color.gray,
origin_y = 0.5,
scale = 0.5)
self.pendulum = Entity(model = "pendulum", collider = "mesh", texture = "mc_brick.png", scale = 0.1)
def update(self):
simple_pendulum(self)
if self.hovered and held_keys['right mouse']:
destroy(self.pendulum)
destroy(self)
class solarSystem(Button):
def __init__(self, position = (0,0,0), texture = sun_texture):
super().__init__(
parent = scene,
position = position,
model = 'assets/block',
origin_y = 0.5,
texture = texture,
color = color.color(0,0,random.uniform(0.9,1)),
scale = 0.5)
self.planet = Entity(model="assets/block", scale= 0.1, texture = earth_texture)
self.t = 0.0
def update(self):
oscSim(self)
if self.hovered and held_keys['right mouse']:
destroy(self.planet)
destroy(self)
def terrainGen():
for z in range(20):
for x in range(20):
voxel = Voxel(position = (x,0,z))
terrainGen()
player = FirstPersonController()
sky = Sky()
hand = Hand()
# pendulum()
app.run()