I'm currently creating a minecraft clone and whenever I try to generate a chunk that is 16x * 32y * 16z it'll refuse to let me open a full screen window and if it isn't fullscreened then it'll be offset to a weird part of the screen.
https://pastebin.com/XTncVhBM
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
import ctypes
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
gameApp = Ursina()
class Face(Button):
def __init__(self, position=(float(0), float(0), float(0)), rotation=(0, 0, 0),
truePos=(float(0), float(0), float(0))):
super().__init__(
parent=scene,
position=position,
model='quad',
scale=1,
origin_y=1,
rotation=rotation,
texture='white_cube',
color=color.white,
highlight_color=color.lime
)
self.truePos = truePos
def destroy(self):
destroy(self)
class Block(object):
def __init__(self, position=(float(0), float(0), float(0)), chunk=None):
self.negativeZFace = Face(position=position + (0.0, 1.0, -0.5), rotation=(0, 0, 0), truePos=position)
self.positiveZFace = Face(position=position + (0.0, -1.0, 0.5), rotation=(180, 0, 0), truePos=position)
self.positiveYFace = Face(position=position + (0.0, 0.5, 1.0), rotation=(90, 0, 0), truePos=position)
self.negativeYFace = Face(position=position + (0.0, -0.5, -1.0), rotation=(270, 0, 0), truePos=position)
self.positiveXFace = Face(position=position + (0.5, 1.0, 0.0), rotation=(0, 270, 0), truePos=position)
self.negativeXFace = Face(position=position + (-0.5, 1.0, 0.0), rotation=(0, 90, 0), truePos=position)
self.position = position
self.faces = [self.negativeYFace, self.negativeXFace, self.negativeZFace, self.positiveXFace,
self.positiveYFace, self.positiveZFace]
self.chunk: Chunk = chunk
self.optimize()
def destroy(self):
for face in self.faces:
face.destroy()
if self.chunk.genBlocks.keys().__contains__(str(tuple(map(operator.add, self.position, (1.0, 0, 0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (1.0, 0, 0))))].regenFaces()
if self.chunk.genBlocks.keys().__contains__(str(tuple(map(operator.add, self.position, (-1.0, 0, 0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (-1.0, 0, 0))))].regenFaces()
if self.chunk.genBlocks.keys().__contains__(str(tuple(map(operator.add, self.position, (0.0, 0, 1.0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (0.0, 0, 1.0))))].regenFaces()
if self.chunk.genBlocks.keys().__contains__(str(tuple(map(operator.add, self.position, (0.0, 0, -1.0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (0.0, 0, -1.0))))].regenFaces()
if self.chunk.genBlocks.keys().__contains__(
str(tuple(map(operator.add, self.position, (0.0, 1.0, 0.0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (0.0, 1.0, 0.0))))].regenFaces()
if self.chunk.genBlocks.keys().__contains__(
str(tuple(map(operator.add, self.position, (0.0, -1.0, 0.0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (0.0, -1.0, 0.0))))].regenFaces()
self.chunk.removeBlock(self.position)
def regenFaces(self):
self.negativeZFace = Face(position=self.position + (0.0, 1.0, -0.5), rotation=(0, 0, 0), truePos=self.position)
self.positiveZFace = Face(position=self.position + (0.0, -1.0, 0.5), rotation=(180, 0, 0),
truePos=self.position)
self.positiveYFace = Face(position=self.position + (0.0, 0.5, 1.0), rotation=(90, 0, 0), truePos=self.position)
self.negativeYFace = Face(position=self.position + (0.0, -0.5, -1.0), rotation=(270, 0, 0),
truePos=self.position)
self.positiveXFace = Face(position=self.position + (0.5, 1.0, 0.0), rotation=(0, 270, 0), truePos=self.position)
self.negativeXFace = Face(position=self.position + (-0.5, 1.0, 0.0), rotation=(0, 90, 0), truePos=self.position)
self.faces = [self.negativeYFace, self.negativeXFace, self.negativeZFace, self.positiveXFace,
self.positiveYFace, self.positiveZFace]
self.optimize()
def new(self):
if self.chunk.genBlocks.keys().__contains__(str(tuple(map(operator.add, self.position, (1.0, 0, 0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (1.0, 0, 0))))].regenFaces()
if self.chunk.genBlocks.keys().__contains__(str(tuple(map(operator.add, self.position, (-1.0, 0, 0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (-1.0, 0, 0))))].regenFaces()
if self.chunk.genBlocks.keys().__contains__(str(tuple(map(operator.add, self.position, (0.0, 0, 1.0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (0.0, 0, 1.0))))].regenFaces()
if self.chunk.genBlocks.keys().__contains__(str(tuple(map(operator.add, self.position, (0.0, 0, -1.0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (0.0, 0, -1.0))))].regenFaces()
if self.chunk.genBlocks.keys().__contains__(
str(tuple(map(operator.add, self.position, (0.0, 1.0, 0.0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (0.0, 1.0, 0.0))))].regenFaces()
if self.chunk.genBlocks.keys().__contains__(
str(tuple(map(operator.add, self.position, (0.0, -1.0, 0.0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (0.0, -1.0, 0.0))))].regenFaces()
def optimize(self):
if self.chunk.genBlocks.keys().__contains__(str(tuple(map(operator.add, self.position, (1.0, 0, 0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (1.0, 0, 0))))].negativeXFace.destroy()
self.positiveXFace.destroy()
if self.chunk.genBlocks.keys().__contains__(str(tuple(map(operator.add, self.position, (-1.0, 0, 0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (-1.0, 0, 0))))].positiveXFace.destroy()
self.negativeXFace.destroy()
if self.chunk.genBlocks.keys().__contains__(str(tuple(map(operator.add, self.position, (0.0, 0, 1.0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (0.0, 0, 1.0))))].negativeZFace.destroy()
self.positiveZFace.destroy()
if self.chunk.genBlocks.keys().__contains__(str(tuple(map(operator.add, self.position, (0.0, 0, -1.0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (0.0, 0, -1.0))))].positiveZFace.destroy()
self.negativeZFace.destroy()
if self.chunk.genBlocks.keys().__contains__(
str(tuple(map(operator.add, self.position, (0.0, 1.0, 0.0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (0.0, 1.0, 0.0))))].negativeYFace.destroy()
self.positiveYFace.destroy()
if self.chunk.genBlocks.keys().__contains__(
str(tuple(map(operator.add, self.position, (0.0, -1.0, 0.0))))):
self.chunk.genBlocks[
str(tuple(map(operator.add, self.position, (0.0, -1.0, 0.0))))].positiveYFace.destroy()
self.negativeYFace.destroy()
class Chunk(object):
def __init__(self, position=(float(0), float(0), float(0)), blocks=None):
print("creating chunk")
position = tuple(map(operator.mul, position, (16, 0, 16)))
self.genBlocks = {}
if blocks is None:
blocks = []
for blockPos in blocks:
if not isinstance(blockPos, tuple):
break
else:
genBlock = Block(position=tuple(map(operator.add, blockPos, position)), chunk=self)
self.genBlocks[str(genBlock.position)] = genBlock
print("finished chunk")
def optimize(self):
for block in self.genBlocks:
block: Block = self.genBlocks[block]
if self.genBlocks.keys().__contains__(str(tuple(map(operator.add, block.position, (1.0, 0, 0))))):
self.genBlocks[str(tuple(map(operator.add, block.position, (1.0, 0, 0))))].negativeXFace.destroy()
if self.genBlocks.keys().__contains__(str(tuple(map(operator.add, block.position, (-1.0, 0, 0))))):
self.genBlocks[str(tuple(map(operator.add, block.position, (-1.0, 0, 0))))].positiveXFace.destroy()
if self.genBlocks.keys().__contains__(str(tuple(map(operator.add, block.position, (0.0, 0, 1.0))))):
self.genBlocks[str(tuple(map(operator.add, block.position, (0.0, 0, 1.0))))].negativeZFace.destroy()
if self.genBlocks.keys().__contains__(str(tuple(map(operator.add, block.position, (0.0, 0, -1.0))))):
self.genBlocks[str(tuple(map(operator.add, block.position, (0.0, 0, -1.0))))].positiveZFace.destroy()
if self.genBlocks.keys().__contains__(str(tuple(map(operator.add, block.position, (0.0, 1.0, 0.0))))):
self.genBlocks[str(tuple(map(operator.add, block.position, (0.0, 1.0, 0.0))))].negativeYFace.destroy()
if self.genBlocks.keys().__contains__(str(tuple(map(operator.add, block.position, (0.0, -1.0, 0.0))))):
self.genBlocks[str(tuple(map(operator.add, block.position, (0.0, -1.0, 0.0))))].positiveYFace.destroy()
def addBlock(self, position):
genBlock = Block(position=position, chunk=self)
self.genBlocks[str(genBlock.position)] = genBlock
def removeBlock(self, position):
self.genBlocks.pop(str(position)).new()
class Voxel(Button):
def __init__(self, position=(0, 0, 0)):
super().__init__(
parent=scene,
position=position,
model='cube',
scale=(1, 1, 1),
texture='white_cube',
color=color.white,
highlight_color=color.lime
)
def input(self, key):
if self.hovered:
if key == "right mouse down":
voxel = Voxel(position=self.position + mouse.normal)
if key == "left mouse down":
destroy(self)
window.title = "PyCraft"
player = FirstPersonController()
player.name = "Player"
started = False
def update():
global started
global player
if not started:
blocks = []
for x in range(16):
for z in range(16):
for y in range(10):
blocks.append((float(x), float(y * -1), float(z)))
test_chunk = Chunk(position=(0, 0, 0), blocks=blocks)
started = True
player.y = 1
player.x = 0
player.z = 0
try:
print_on_screen(f"X: {str(round(player.x))}, Y: {str(round(player.y))}, Z: {str(round(player.z))}",
duration=time.dt)
except:
pass
if held_keys["space"]:
try:
print_o