Python Forum
Help i don't know how to fix this
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help i don't know how to fix this
#1
Hi im new on pygame programming and when I want to make the "world" variable with the "World" class it gives me error how can I fix it?
import pygame

pygame.init()

screen_width = 1001
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))

# screen name
pygame.display.set_caption("HANDSOME ADVENTURE")

# variables
tile_size = 50

# screen icon
icon = pygame.image.load('handsome icon.png')
pygame.display.set_icon(icon)

# load images
bg_img = pygame.image.load('bgp.png')


def draw_grid():
    for line in range(0, 100):
        pygame.draw.line(screen, (255, 255, 255), (0, line * tile_size), (screen_width, line * tile_size))
        pygame.draw.line(screen, (255, 255, 255), (line * tile_size, 0), (line * tile_size, screen_height))


class World():
    def __int__(self, data):
        self.tile_list = []

        dirtimg = pygame.image.load('handsomedirt.png')

        row_count = 0
        for row in data:
            col_count = 0
            for tile in row:
                if tile == 1:
                    img = pygame.transform.scale(dirtimg, (tile_size, tile_size))
                    img_rect = img.get_rect()
                    img_rect.x = col_count * tile_size
                    img_rect.y = col_count * tile_size
                    tile = (img, img_rect)
                    self.tile_list.append(tile)
                col_count += 1
            row_count += 1


world_data = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 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, 1],
]


world = World(world_data)

# gameloop
run = True
while run:

    screen.blit(bg_img, (0, 0))

    print(world.tile_list)

    draw_grid()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    pygame.display.update()

pygame.quit()
Error:
world = World(world_data) TypeError: World() takes no arguments libpng warning: iCCP: known incorrect sRGB profile
Reply
#2
change __int__ to __init__ in line 30. I did not check for other errors.
izmamonke likes this post
Reply
#3
(Jul-08-2021, 04:21 PM)deanhystad Wrote: change __int__ to __init__ in line 30. I did not check for other errors.

Thank you!
Reply


Forum Jump:

User Panel Messages

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