March 8th Blog Post: Zelda Game

World Boundary

Added a world boundary on the map so that the player can’t walk out of it.

layouts = {
            'boundary': import_csv_layout('map//map_FloorBlocks.csv'), << Looking at this
            'grass': import_csv_layout('map//map_Grass.csv'),
            'object': import_csv_layout('map//map_Objects.csv')

This the csv directory of where the floor blocks (the barrier) of the world map. I made a function in another file (support.py) that has all the stuff to make it work.

support.py

def import_csv_layout(path):
    terrain_map = []
    with open(path) as level_map:
        layout = reader(level_map, delimiter = ',')
        for row in layout:
            terrain_map.append(list(row))
        return terrain_map

This code reads the csv file, then in level.py it draws it on the map and places the blocks around the edge of it.

world barrier shown.

world barrier hidden ( I just took off self.visible_sprites).

Grass

Added plants and collision on them!!!!

layouts = {
            'boundary': import_csv_layout('map//map_FloorBlocks.csv'),
     This one >>'grass': import_csv_layout('map//map_Grass.csv'),  
            'object': import_csv_layout('map//map_Objects.csv')

same thing as boundary, but has a graphics directory AND a csv (as does object).

graphics = {
            'grass': import_folder('graphics//grass'),
            'objects': import_folder('graphics//object')

made an import_folder() function that kinda does the same thing but loads the images and appends them to a list.

def import_folder(path):
    surface_list = []
    
    for _,__,img_files in walk(path):
        for image in img_files:
                full_path = path + '/' + image
                image_surf = pygame.image.load(full_path).convert_alpha()
                surface_list.append(image_surf)

also added them to an if statement so that it puts them in their correct places (kinda.)

if style == 'grass':
                            random_grass_image = choice(graphics['grass'])
                            Tile((x,y),[self.visible_sprites, 
                            self.obstacle_sprites],'grass', random_grass_image)

RESULT:

no grass

yes grass (and collisions!!!!)

Currently working on the larger objects right now :))))

Author: Zende_

From PA. EHS 2025. Does computer programming and such. That's really it.

Leave a Reply

Your email address will not be published. Required fields are marked *