diff --git a/assets/texturas/rochas.webp b/assets/texturas/rochas.webp new file mode 100644 index 00000000..04613d6d Binary files /dev/null and b/assets/texturas/rochas.webp differ diff --git a/assets/texturas/texture.png b/assets/texturas/texture.png new file mode 100644 index 00000000..6f358e97 Binary files /dev/null and b/assets/texturas/texture.png differ diff --git a/main.py b/main.py index 061cdf82..3c8ee892 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,7 @@ from pyglet.graphics import TextureGroup from pyglet.window import key, mouse -TICKS_PER_SEC = 60 +TICKS_PER_SEC = 20 # Size of sectors used to ease block loading. SECTOR_SIZE = 16 @@ -20,8 +20,8 @@ WALKING_SPEED = 5 FLYING_SPEED = 15 -GRAVITY = 20.0 -MAX_JUMP_HEIGHT = 1.0 # About the height of a block. +GRAVITY = 9.8 +MAX_JUMP_HEIGHT = 1.2 # About the height of a block. # To derive the formula for calculating jump speed, first solve # v_t = v_0 + a * t # for the time at which you achieve maximum height, where a is the acceleration @@ -32,7 +32,7 @@ JUMP_SPEED = math.sqrt(2 * GRAVITY * MAX_JUMP_HEIGHT) TERMINAL_VELOCITY = 50 -PLAYER_HEIGHT = 2 +PLAYER_HEIGHT = 1.8 if sys.version_info[0] >= 3: xrange = range @@ -51,7 +51,7 @@ def cube_vertices(x, y, z, n): ] -def tex_coord(x, y, n=4): +def tex_coord(x, y, n=8): """ Return the bounding vertices of the texture square. """ @@ -75,13 +75,22 @@ def tex_coords(top, bottom, side): return result -TEXTURE_PATH = 'texture.png' +TEXTURE_PATH = 'assets/texturas/texture.png' GRASS = tex_coords((1, 0), (0, 1), (0, 0)) SAND = tex_coords((1, 1), (1, 1), (1, 1)) BRICK = tex_coords((2, 0), (2, 0), (2, 0)) STONE = tex_coords((2, 1), (2, 1), (2, 1)) +# Blocos Criados pelo joao + +MADEIRA = tex_coords((2, 2), (2, 2), (1, 2)) +MADEIRA_COPA = tex_coords((3, 2), (3, 2), (3, 2)) +CARVAO = tex_coords((3, 0), (3, 0), (3, 0)) +DIAMANTE = tex_coords((3, 1), (3, 1), (3, 1)) +GRAVEL = tex_coords((0, 3), (0, 3), (0, 3)) +TNT = tex_coords((3, 3), (2, 3), (1, 3)) + FACES = [ ( 0, 1, 0), ( 0,-1, 0), @@ -156,18 +165,75 @@ def __init__(self): self._initialize() + def _generate_tree(self, x, y, z): + """ Gera uma árvore na posição especificada. + + Parameters + ---------- + x, y, z : int + Posição base da árvore (onde o tronco começa). + """ + # Altura do tronco (4 a 6 blocos) + trunk_height = random.randint(4, 6) + + # Criar tronco + for dy in xrange(trunk_height): + trunk_y = y + dy + trunk_pos = (x, trunk_y, z) + # Substituir qualquer bloco que não seja GRASS ou STONE na base + if trunk_pos not in self.world or (dy == 0 and self.world.get(trunk_pos) in [GRASS, STONE]): + self.add_block(trunk_pos, MADEIRA, immediate=False) + + # Criar copa da árvore (folhas) + top_y = y + trunk_height + # Raio da copa (2 a 3 blocos) + crown_radius = random.randint(2, 3) + + # Gerar folhas em formato esférico/oval ao redor do topo + for dx in xrange(-crown_radius, crown_radius + 1): + for dz in xrange(-crown_radius, crown_radius + 1): + for dy in xrange(0, crown_radius + 1): + # Verificar se está dentro do raio da copa + distance = math.sqrt(dx**2 + dz**2 + (dy * 1.5)**2) + if distance <= crown_radius: + crown_x = x + dx + crown_y = top_y + dy + crown_z = z + dz + crown_pos = (crown_x, crown_y, crown_z) + # Não substituir o tronco + if not (dx == 0 and dz == 0 and dy == 0): + # Verificar se a posição está livre ou pode ser substituída + if crown_pos not in self.world or self.world.get(crown_pos) == GRASS: + self.add_block(crown_pos, MADEIRA_COPA, immediate=False) + def _initialize(self): """ Initialize the world by placing all the blocks. """ - n = 80 # 1/2 width and height of world + n = 100 # 1/2 width and height of world s = 1 # step size y = 0 # initial y height + + # Otimização: gerar blocos raros durante a criação inicial para evitar loop duplo for x in xrange(-n, n + 1, s): for z in xrange(-n, n + 1, s): # create a layer stone an grass everywhere. self.add_block((x, y - 2, z), GRASS, immediate=False) - self.add_block((x, y - 3, z), STONE, immediate=False) + # 30% de chance de ser GRAVEL, 70% de ser STONE na camada abaixo da grama + if random.random() < 0.30: + self.add_block((x, y - 3, z), GRAVEL, immediate=False) + else: + self.add_block((x, y - 3, z), STONE, immediate=False) + # Criar mais camadas de STONE em profundidade (reduzido para otimização) + for depth in xrange(-4, -7, -1): # De y -4 até y -6 (3 camadas) + position = (x, depth, z) + # 17.5% de chance de ser CARVÃO ou DIAMANTE (média entre 15% e 20%) + if random.random() < 0.175: + # 50% de chance de ser CARVÃO, 50% de ser DIAMANTE + rare_block = CARVAO if random.random() < 0.5 else DIAMANTE + self.add_block(position, rare_block, immediate=False) + else: + self.add_block(position, STONE, immediate=False) if x in (-n, n) or z in (-n, n): # create outer walls. for dy in xrange(-2, 3): @@ -193,6 +259,41 @@ def _initialize(self): self.add_block((x, y, z), t, immediate=False) s -= d # decrement side length so hills taper off + # Gerar TNT aleatoriamente no mapa (4% de chance) + for x in xrange(-n + 5, n - 4, s): + for z in xrange(-n + 5, n - 4, s): + # 4% de chance de gerar TNT nesta posição + if random.random() < 0.04: + # Colocar TNT na superfície (y - 1), acima da grama + tnt_pos = (x, y - 1, z) + # Verificar se há GRASS abaixo e se a posição está livre + grass_pos = (x, y - 2, z) + if grass_pos in self.world and self.world[grass_pos] == GRASS: + # Se a posição da TNT estiver livre, colocar + if tnt_pos not in self.world: + self.add_block(tnt_pos, TNT, immediate=False) + + # Gerar árvores aleatoriamente na superfície + # Gerar árvores em posições aleatórias onde há GRASS + num_trees = min(n // 2, 500) # Aumentado para ter mais árvores visíveis + trees_placed = 0 + attempts = 0 + max_attempts = num_trees * 10 # Limitar tentativas para evitar loop infinito + + while trees_placed < num_trees and attempts < max_attempts: + attempts += 1 + tree_x = random.randint(-n + 10, n - 10) + tree_z = random.randint(-n + 10, n - 10) + # Verificar se há GRASS nesta posição (y - 2 é a camada de GRASS) + grass_pos = (tree_x, y - 2, tree_z) + if grass_pos in self.world and self.world[grass_pos] == GRASS: + # Verificar se a posição acima está livre (onde o tronco vai começar) + trunk_pos = (tree_x, y - 1, tree_z) + if trunk_pos not in self.world: + # Gerar árvore na posição (y - 1 é onde a árvore começa, acima do GRASS) + self._generate_tree(tree_x, y - 1, tree_z) + trees_placed += 1 + def hit_test(self, position, vector, max_distance=8): """ Line of sight search from current position. If a block is intersected it is returned, along with the block previously in the line @@ -681,9 +782,8 @@ def on_mouse_press(self, x, y, button, modifiers): if previous: self.model.add_block(previous, self.block) elif button == pyglet.window.mouse.LEFT and block: - texture = self.model.world[block] - if texture != STONE: - self.model.remove_block(block) + # Permitir quebrar qualquer bloco, incluindo STONE + self.model.remove_block(block) else: self.set_exclusive_mouse(True) diff --git a/texture.png b/texture.png deleted file mode 100644 index 9d05a7e2..00000000 Binary files a/texture.png and /dev/null differ