Skip to content

Commit 32a3692

Browse files
Update 4.0
1 parent 81ca173 commit 32a3692

File tree

3 files changed

+70
-85
lines changed

3 files changed

+70
-85
lines changed

Diff for: configuration.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"trees": true,
33
"showInventory": true,
44
"sounds": true,
5-
"directionalShaders": true,
5+
"directionalShaders": false,
66
"fps_counter_enabled": true,
77
"treesCount": 5,
8-
"parkour_mode": true,
8+
"parkour_mode": false,
99
"land_size": 15
1010
}

Diff for: font/minecraft.ttf

21.3 KB
Binary file not shown.

Diff for: main.py

+68-83
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
from ursina import *
22
from ursina.prefabs.first_person_controller import FirstPersonController
3-
# from ursina.prefabs.editor_camera import EditorCamera
43
from perlin_noise import PerlinNoise
54
from ursina.shaders import lit_with_shadows_shader
65
import random
7-
import sys
8-
import math
96
import json
7+
import psutil
108
from ursina.prefabs.panel import Panel
119

12-
13-
10+
#Initializing Game Object
1411
app = Ursina()
1512

13+
#Creating the Player Object
1614
player = FirstPersonController()
15+
player.height = 2
16+
player.cursor = Entity(parent=camera.ui, model='quad',color=color.light_gray, scale=.008, rotation_z=45)
17+
player.gravity = 0.5
18+
# player.model = "assets/player.obj"
19+
# player.texture = "textures/"
20+
player.scale = 1
21+
player.y = 50
1722

23+
# Window Settings
24+
window.title = "Minecraft Python Edition"
1825
window.exit_button.visible = False
1926
window.fullscreen = True
2027
window.vsync = False
2128
window.borderless = False
22-
window.color = color.rgb(0,181,226)
29+
window.color = color.rgb(0, 181, 226)
2330
window.show_ursina_splash = True
24-
window.title = "Minecraft Python Edition"
25-
player.height = 2
26-
player.cursor = Entity(parent=camera.ui, model='crosshair',
27-
color=color.light_gray, scale=.008, rotation_z=45)
28-
player.gravity = 0.5
29-
# player.model = "assets/player.obj"
30-
# player.texture = "textures/"
31+
32+
# Init Variables
3133
terrainblocks = []
32-
player.scale = 1
33-
player.y = 50
34+
button_font = "font/minecraft.ttf"
35+
pressed = False
3436
block_id = 1
35-
o = Panel(scale=5)
36-
o.visible = False
37-
inventorytrue = "i"
3837
bgmusic = [Audio("assets/music/calm1.ogg", loop=True, autoplay=False),
3938
Audio("assets/music/calm2.ogg", loop=True, autoplay=False),
4039
Audio("assets/music/calm3.ogg", loop=True, autoplay=False),
@@ -44,12 +43,7 @@
4443
]
4544
bgumusic = random.choice(bgmusic)
4645
bgumusic.play()
47-
# bgmusic.autoplay = True
48-
voxels = []
4946
noise = PerlinNoise(octaves=3,seed=random.randint(1,1000000))
50-
51-
terrain = Entity(model=None,collider=None)
52-
5347
blocks = [
5448
['leaves', "assets/leaves_block_tex.png", load_texture("assets/leaves_block_tex.png")],
5549
["grass", "assets/grass_block_tex.png", load_texture("assets/grass_block_tex.png")],
@@ -63,6 +57,15 @@
6357
["ice", "assets/ice_block_tex.png", load_texture("assets/ice_block_tex.png")]
6458
]
6559

60+
# Variables for F3 debug screen
61+
debugscreen = Entity(model=None, parent=camera.ui)
62+
debugscreen.visible = False
63+
coordinates = Text(position=Vec3(-.87, 0.44, 0),
64+
font=button_font, parent=debugscreen)
65+
cpu_panel = Text(position=Vec3(-.87, 0.40, 0),
66+
parent=debugscreen, font=button_font)
67+
68+
#Importing Json
6669
with open("configuration.json", "r") as configuration:
6770
data = json.load(configuration)
6871
trees = data["trees"]
@@ -77,6 +80,9 @@
7780
if fps_counter_enabled == False:
7881
window.fps_counter = False
7982

83+
#----------------------------------------------Function Space---------------------------------------------------
84+
85+
#Defining Tree Structure
8086
def trunk(parent):
8187
for __z in range(1):
8288
for __x in range(1):
@@ -103,22 +109,14 @@ def plantTree(_x, _y, _z):
103109
trunk(tree)
104110
tree.y = 3
105111

106-
107-
def checkTree(_x, _y, _z):
108-
freq = 3
109-
amp = 80
110-
treeChance = ((noise([_x / freq, _z / freq])) * amp)
111-
if treeChance > 38:
112-
plantTree(_x, _y, _z)
113-
114-
115112
def genTrees():
116113
for tree in range(treesCount):
117114
chosenblock = random.choice(terrainblocks)
118115
# terrainblocks.remove(chosenblock)
119116
randomcoordinates = (chosenblock.x,chosenblock.z,chosenblock.y)
120117
plantTree(_x=randomcoordinates[0], _z=randomcoordinates[1], _y=randomcoordinates[2]+1)
121118

119+
# Finding about the blocks
122120
def findsoundbasedontexture(blockid, mode, block, blocklist=blocks):
123121
if mode == "default":
124122
if blocklist[blockid][0] in blocklist[blockid][1]:
@@ -138,39 +136,52 @@ def whichblockami(block):
138136
return eachBlock[0]
139137

140138
except:
141-
print(f"No texture on index")
142-
139+
print(f"No texture on index")
140+
141+
#------------------------------------End of Function Space-------------------------------------------
142+
143+
# Task Update
143144
def update():
144-
global inventorytrue
145+
global inventorytrue, pressed
145146
if held_keys['left mouse down'] or held_keys['right mouse down']:
146147
# punch_sound.play()
147148
hand.active()
148149
else:
149150
hand.passive()
150151

151-
# if held_keys["e"]:
152-
# application.pause()
153-
# o.visible = True
154-
# inventory.visible = True
155-
# inventory.addslots()
156-
# mouse.locked = False
157-
# mouse.visible = True
158-
# # inventorytrue = "o"
159152
if held_keys['escape']:
160153
sys.exit()
161154

155+
if held_keys['f3']:
156+
if pressed == False:
157+
debugscreen.visible = True
158+
pressed = True
159+
elif pressed == True:
160+
debugscreen.visible = False
161+
pressed = False
162+
162163
selected.adjust_position()
163164

164165
if held_keys["t"]:
165166
plantTree(round(player.x), round(player.y), round(player.z))
166167

168+
cpu = psutil.cpu_percent()
169+
ram = psutil.virtual_memory().percent
170+
coordinates.text = f'Position: {round(player.x)},{round(player.y)},{round(player.z)}'
171+
pid = os.getpid()
172+
python_process = psutil.Process(pid)
173+
memoryUse = python_process.memory_info()[0]/2.**30
174+
175+
cpu_panel.text = f'CPU: {cpu}% / RAM: {ram}% / Memory use: {round(memoryUse,2)} GB'
176+
167177
if player.y < -100:
168178
Audio("assets/sounds/sh/die.ogg")
169179
player.y = 15
170180
player.x = 0
171181
player.z = 0
172182
Audio("assets/sounds/sh/spawn.ogg")
173183

184+
# Defining Voxel
174185
class Voxel(Button):
175186
def __init__(self, position=(0, 0, 0), texture="assets/grass_block_tex.png", **kwargs):
176187
super().__init__(
@@ -191,12 +202,15 @@ def input(self, key):
191202
if key == 'right mouse down':
192203
if sounds == True:
193204
findsoundbasedontexture(blockid=block_id,mode="default",block=self.block).play()
194-
Voxel(position=self.position + mouse.normal,
205+
voxel = Voxel(position=self.position + mouse.normal,
195206
texture=blocks[block_id][2])
207+
terrainblocks.append(voxel)
196208
if key == 'left mouse down':
197209
if sounds == True:
198210
findsoundbasedontexture(blockid=block_id,mode="already",block=self.block).play()
199211
destroy(self)
212+
213+
# Changing hand texture
200214
def input(key):
201215
global block_id, hand
202216
if key.isdigit():
@@ -205,7 +219,7 @@ def input(key):
205219
block_id = len(blocks) - 1
206220
hand.texture = blocks[block_id][2]
207221

208-
222+
# Defining Hand
209223
class Hand(Entity):
210224
def __init__(self):
211225
super().__init__(
@@ -226,6 +240,7 @@ def active():
226240
def passive():
227241
hand.position = Vec2(0.6, -0.6)
228242

243+
#----------------------------------------------Inventory Zone-----------------------------------------
229244

230245
class Item(Entity):
231246
def __init__(self,texture,position=(0,-0.42)):
@@ -293,61 +308,31 @@ def appendItems(self):
293308
obsidian = Item(blocks[8][2], (0.26, -0.42))
294309
ice = Item(blocks[9][2], (0.35, -0.42))
295310

296-
# for z in range(-20,20):
297-
# for x in range(-20,20):
298-
# y = noise([x * .02, z * .02])
299-
# y = math.floor(y * 7.5)
300-
# voxel = Voxel(position=(x,y,z))
301-
# voxel.texture = blocks[1][2]
302-
# voxel.parent = terrain
303-
# terrainblocks.append(voxel)
311+
#-------------------------------------End of Inventory Zone-------------------------------------------
312+
313+
# Terrain Generation
304314
terrainWidth = landsize
305315
freq = 24
306316
if parkour == True:
307317
amp = 100
308318
else:
309-
amp = 5
319+
amp = 6
310320
for i in range(terrainWidth*terrainWidth):
311321
voxel = Voxel(texture=blocks[1][2])
312322
voxel.x = floor(i/terrainWidth)
313323
voxel.z = floor(i % terrainWidth)
314324
voxel.y = floor((noise([voxel.x/freq, voxel.z/freq]))*amp)
315325
# voxel.parent = terrain
316326
terrainblocks.append(voxel)
317-
318-
319-
# for b in range(1):
320-
# for i in range(terrainWidth*terrainWidth):
321-
# voxel = Voxel(texture=blocks[2][2])
322-
# voxel.x = floor(i/terrainWidth)
323-
# voxel.z = floor(i % terrainWidth)
324-
# voxel.y = floor(((noise([voxel.x/freq, voxel.z/freq]))*amp)-(b+1))
325-
326-
# for d in range(1):
327-
# for i in range(terrainWidth*terrainWidth):
328-
# voxel = Voxel(texture=blocks[3][2])
329-
# voxel.x = floor(i/terrainWidth)
330-
# voxel.z = floor(i % terrainWidth)
331-
# voxel.y = floor(((noise([voxel.x/freq, voxel.z/freq]))*amp)-(d+2))
332327

333328
if trees == True:
334329
genTrees()
335-
336-
# terrain.combine(terrainblocks)
337-
# print("Mesh combined successfully")
338-
# terrain.collider = 'mesh'
339-
# terrain.texture = "white_cube"
340-
330+
341331
if directionalshaders == True:
342332
DirectionalLight(parent=Voxel, y=2, z=3, shadows=True)
343333

344-
if inventory == True:
345-
hotbar = Hotbar()
346-
hotbar.appendItems()
347-
selected = Selected()
348-
# inventory = Inventory()
349-
# inventory.visible = False
350-
inventorytrue = "i"
351334
hand = Hand()
352-
# chunk = combine(terrainblocks)
335+
selected = Selected()
336+
hotbar = Hotbar()
337+
hotbar.appendItems()
353338
app.run()

0 commit comments

Comments
 (0)