Quantcast
Viewing all articles
Browse latest Browse all 14389

how can I fix this and put my text file as tiles in my program?

I had this working before but I tried something and I deleted it and now my map isn't showing when I launch my program. I have my map in a text file and I'm reading the file in my program.

I removed what I was testing and reverted to when my program was working but it doesn't any more.this is the code:

class Level:    def __init__(self, level_number):        self.level_number = level_number        self.level_map = self.level_load()        self.tile_list = []        grass_img = pg.image.load('assets/grass.png')               tileSize = 75            y = 0        for row in self.level_map:            x = 0            for tile in row:                if tile == 1:                    img = pg.transform.scale(grass_img, (tileSize, tileSize))                    img_rect = img.get_rect()                    img_rect.x = x * tileSize                    img_rect.y = y * tileSize                    tile = (img, img_rect)                    self.tile_list.append(tile)                x += 1            y += 1        def draw(self, screen):        for tile in self.tile_list:            screen.blit(tile[0], tile[1])    def level_load(self):        level_map = []        if self.level_number == 1:            with open("level_data/level1.txt", 'r') as f:                for line in f:                     level_map.append(list(line))                           return level_map

this is what's inside the text file:

[1,1,1,1,1][1,0,0,0,1][1,0,0,0,1][1,1,1,1,1]

And its being used here:

def run(self):    level1 = Level(1)    while True:        self.screen.fill((88,180,252))        level1.draw(self.screen)

Viewing all articles
Browse latest Browse all 14389

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>