Python Forum
Why doesnt chunk generation work? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Why doesnt chunk generation work? (/thread-34016.html)



Why doesnt chunk generation work? - LotosProgramer - Jun-18-2021

So basically I have been trying to get a terrain generator but the values are always the same on the top left corner. Any ideas why? Wall Wall

MAIN SCRIPT
import pygame
import player
import world_gen

pygame.init()

tk = pygame.time.Clock()
FPS = 60

background = pygame.image.load('imgs/background_gradient.png')


is_running = True

(WIN_W, WIN_H) = (1600, 900)
display = pygame.display.set_mode((WIN_W, WIN_H))
pygame.display.set_caption('2D Minecraft v0.0 ALPHA')

temp_tile = pygame.image.load('imgs/temp_tile.png')

def HandleDrawing():
    display.blit(background, (0, 0))

    at_block = 0
    for chunk in world_gen.world_dat:
        display.blit(temp_tile, (chunk[at_block], chunk[at_block+1]))
        at_block += 1

    if player.is_walking:
        if not player.left and player.right:
            display.blit(pygame.transform.flip(player.walk_anim[player.at_walk_frame], True, False), (player.x, player.y))

        elif not player.right and player.left:
            display.blit(player.walk_anim[player.at_walk_frame], (player.x, player.y))

        elif player.left and player.right:
            display.blit(player.player, (player.x, player.y))

    else:
        display.blit(player.player, (player.x, player.y))

    pygame.display.update()

world_gen.chunk_gen(1)
while is_running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            is_running = False
    player.Movement()
    HandleDrawing()

    tk.tick(FPS)
pygame.quit()
WORLD GEN
import pygame
import noise
import random

chunk_size = 24
grid_size = 40
noise_multiplier = 0.05

world_dat = []

def chunk_gen(x):
    global world_dat
    chunk_dat = []
    for x_pos in range(chunk_size):
        h = int(noise.pnoise1(x + x_pos* chunk_size * noise_multiplier, repeat=9999999) * 5)
        chunk_dat.append(x + x_pos * grid_size)
        chunk_dat.append(h)

    chunk_dat.append(round(x / chunk_size)) 
    world_dat.append(chunk_dat)



RE: Why doesnt chunk generation work? - deanhystad - Apr-02-2022

The attached image is what I would expect from you code. How does this differ from what you are expecting?