-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
my code sucks and gives only 5-15 FPS max. I programing minecraft on ursina. pls help me
here's the code:
`from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from numpy import floor
from perlin_noise import PerlinNoise
import matplotlib.pyplot as plt
import random
noise = PerlinNoise(octaves=3, seed=random.randint(1, 10000))
app = Ursina(vsync=False)
FPS = 120
selected_block = "grass"
blocks_texture = {
"grass" : load_texture('Textures/grassUV.png'),
"dirt": load_texture("Textures/groundMud1.png"),
"stone": load_texture("Textures/wallStone1.png"),
"bedrock": load_texture("Textures/bedrock.png")
}
blocks = []
arm_texture = load_texture('Textures/arm1.png')
sky_texture = load_texture('Textures/skybox.png')
#sky = Entity(
model = 'sphere', texture = sky_texture,
scale = 1000, double_sided = True
)
player = FirstPersonController(
mouse_sensitivity=Vec2(100, 100),
position=(0, 10, 0),
)
class Voxel(Entity):
def init(self, position, block_type):
super().init(
position=position,
model="Stuff/Models/Grass_block_pycraft",
scale=0.5,
origin_y=-0.5,
texture=blocks_texture.get(block_type),
collider="box"
)
self.block_type = block_type
mini_block_ia = Entity(
parent = camera,
model = "Stuff/Models/Grass_block_pycraft",
scale = 0.075,
texture=blocks_texture.get(selected_block),
position = (0.15, -0.2, 0.5),
rotation = (-15, -30, -5)
)
#CTAPAR |**EHEPA|_|R
#min_height = -5
#for x in range(-10, 10):
for z in range(-10, 10):
height = noise([x * 0.02, z * 0.02])
height = math.floor(height * 7.5)
for y in range(height, min_height - 1, -1):
if y == min_height:
block = Voxel((x, y + min_height, z), "bedrock")
elif y == height:
block = Voxel((x, y + min_height, z), "grass")
elif height - y > 2:
block = Voxel((x, y + min_height, z), "stone")
else:
block = Voxel((x, y + min_height, z), "dirt")
min_height = -5
for x in range(-16, 16):
for z in range(-16, 16):
height = noise([x * 0.02, z * 0.02])
height = math.floor(height * 7.5)
for y in range(height, min_height - 1, -1):
if y == min_height:
blocks.append(Voxel((x, y + min_height, z), "bedrock"))
elif y == height:
blocks.append(Voxel((x, y + min_height, z), "grass"))
elif height - y > 2:
blocks.append(Voxel((x, y + min_height, z), "stone"))
else:
blocks.append(Voxel((x, y + min_height, z), "dirt"))
def input(key):
global selected_block
if key == "right mouse down":
hit_info = raycast(camera.world_position, camera.forward, distance=10)
if hit_info.hit:
block = Voxel(hit_info.entity.position + hit_info.normal, selected_block)
if key == "left mouse down" and mouse.hovered_entity:
if not mouse.hovered_entity.block_type == "bedrock":
destroy(mouse.hovered_entity)
if key == "1":
selected_block = "grass"
if key == '2':
selected_block = "dirt"
if key == '3':
selected_block = "stone"
def update():
mini_block_ia.texture=blocks_texture.get(selected_block)
if player.y <= -10:
player.position = (0,10,0)
block = blocks
arm = Entity(parent = camera.ui, model = 'Stuff/Models/arm1',
texture = arm_texture, scale = 0.2,
rotation = Vec3(150, 60, -30), position = Vec2(0.5,-0.6))
app.run()`
my configuration:
RTX 4060
Intel Core I5 8400
16GB DDR4 Kingston Fury
P.S. i need more optimization