Skip to content

Commit 5621fc4

Browse files
committed
Inital Commit
0 parents  commit 5621fc4

File tree

6 files changed

+88
-0
lines changed

6 files changed

+88
-0
lines changed

assets/grass.png

44.9 KB
Loading

assets/sky.png

930 KB
Loading

assets/soil.png

11.7 KB
Loading

assets/stone.png

37.2 KB
Loading

assets/wood.png

61.3 KB
Loading

main.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from ursina import *
2+
from ursina.prefabs.first_person_controller import FirstPersonController
3+
4+
app = Ursina()
5+
6+
grass_texture = load_texture("assets/grass.png")
7+
soil_texture = load_texture("assets/soil.png")
8+
stone_texture = load_texture("assets/stone.png")
9+
wood_texture = load_texture("assets/wood.png")
10+
11+
sky_texture = load_texture("assets/sky.png")
12+
13+
current_texture = grass_texture
14+
15+
def update():
16+
global current_texture
17+
if held_keys['1']: current_texture = grass_texture
18+
if held_keys['2']: current_texture = soil_texture
19+
if held_keys['3']: current_texture = stone_texture
20+
if held_keys['4']: current_texture = wood_texture
21+
22+
if held_keys['left mouse'] or held_keys['right mouse']:
23+
hand.active()
24+
else:
25+
hand.passive()
26+
27+
28+
29+
class Sky(Entity):
30+
def __init__(self):
31+
super().__init__(
32+
parent=scene,
33+
model='sphere',
34+
scale=150,
35+
texture=sky_texture,
36+
double_sided=True
37+
)
38+
39+
40+
class Hand(Entity):
41+
def __init__(self):
42+
super().__init__(
43+
parent = camera.ui,
44+
model = 'cube',
45+
scale = (0.2,0.3),
46+
color = color.white,
47+
rotation=Vec3(150, -10, 0),
48+
position=Vec2(0.4, -0.4)
49+
)
50+
51+
def active(self):
52+
self.position = Vec2(0.1, -0.5)
53+
self.rotation = Vec3(90, -10, 0)
54+
55+
def passive(self):
56+
self.rotation = Vec3(150, -10, 0)
57+
self.position = Vec2(0.4, -0.4)
58+
59+
60+
class Voxel(Button):
61+
def __init__(self, position=(0, 0, 0), texture=grass_texture):
62+
super().__init__(
63+
parent=scene,
64+
model='cube',
65+
color=color.white,
66+
highlight_color=color.lime,
67+
texture=texture,
68+
position=position,
69+
origin_y=0.5
70+
)
71+
72+
def input(self, key):
73+
if self.hovered:
74+
if key == "left mouse down":
75+
voxel = Voxel(position=self.position + mouse.normal , texture=current_texture)
76+
if key == 'right mouse down':
77+
destroy(self)
78+
79+
80+
for z in range(15):
81+
for x in range(15):
82+
voxel = Voxel((x, 0, z))
83+
84+
player = FirstPersonController()
85+
sky = Sky()
86+
hand = Hand()
87+
88+
app.run()

0 commit comments

Comments
 (0)