Python Forum
Why is it not printing out
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is it not printing out
#1
Im trying to make an own "collision" which you can first see in "world_Data" in the class world.coll. But the world data is not updating it and all the "1" is dirt and 0 nothing




class World():
    def __init__(self,world_data):

        self.tile_list = []

        dirt = pygame.image.load(os.path.join('pics', 'hej.png'))
        row_count = 0
        for row in world_data:
            col_count = 0
            for tile in row:
                if tile == 1:
                    img = pygame.transform.scale(dirt, (tile_size, tile_size))
                    img_rect = img.get_rect()
                    img_rect.x = col_count * tile_size
                    img_rect.y = row_count * tile_size
                    tile = (img, img_rect)
                    self.tile_list.append(tile)

                col_count += 1
            row_count += 1


    def draw(self):
        for tile in self.tile_list:
            WIN.blit(tile[0], tile[1])

    def coll(self,erik_move):
        if erik_move[1] > 500:
            world_data[0] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]


world_data = [
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    ]



world = World(world_data)




def draw_grid():
    for line in range(0, 20):
        pygame.draw.line(WIN, (255, 255, 255), (0, line * tile_size), (WIDTH, line * tile_size))
        pygame.draw.line(WIN, (255, 255, 255), (line * tile_size, 0), (line * tile_size, HEIGHT))



font = pygame.font.SysFont("Times New Roman, Arial", 30)
text = font.render("BONK A BEAVER", True, BLACK)


ERIK = pygame.image.load(os.path.join('pics', 'erik2.png'))
ERIK = pygame.transform.scale(ERIK, (200, 200))

Backg = pygame.image.load(os.path.join('pics', 'sky.png'))

print(Backg)
FPS = 60



#Om du vill röra din surface, (bilden/surface, hastighet per frames  )


def key_pressed(keys_pressed, erik_move):
    if keys_pressed[pygame.K_a]:
        erik_move.x -= 5
    if keys_pressed[pygame.K_d]:
        erik_move.x += 5
    if keys_pressed[pygame.K_w]:
        erik_move.y -= 5
    if keys_pressed[pygame.K_s]:
        erik_move.y += 5





def erik_pos(erik_move, number):
    erik_move[0] = erik_move[0] + number






#Här bildas och uppdateras surface
def draw_window(erik_move):
    WIN.fill(BLACK)
    WIN.blit(ERIK, (erik_move.x, erik_move.y))

    world.draw()
    draw_grid()

    world.coll(erik_move)
    print(world_data[0])
    pygame.display.update()
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020