Więc, chciałbym stworzyc generator poziomow dla mojej gry, jednak kiedy printuje liste "Sciany" printuje sie cos takiego: [<__main__.Sciana object at 0x0000018E2472C410>, <__main__.Sciana object at 0x0000018E28C15790>, <__main__.Sciana object at 0x0000018E28C15250>, <__main__.Sciana object at 0x0000018E28C15710>]
Co zrobic zeby zamiast tego printowalo sie cos takiego : Sciana(200,400,25,25) ?
Tutej moj kod:
import pygame
import time
pygame.init()
window = pygame.display.set_mode((1280, 720))
pozycja = 0
x = 0
y = 0
class Sciana:
def __init__(self, x, y, szerokosc, wysokosc):
self.x_cord = x
self.y_cord = y
self.szerokosc = szerokosc
self.wysokosc = wysokosc
self.hitbox = pygame.Rect(self.x_cord, self.y_cord, self.szerokosc, self.wysokosc)
def draw(self):
pygame.draw.rect(window, (0,0,0) , self.hitbox)
run = True
item = 'sciana'
image = pygame.image.load('select.png')
sciany = [
Sciana(0,0,25,25)
]
while run:
time.sleep(0.05)
pygame.time.Clock().tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
speed = 25
if keys[pygame.K_1]:
item = 'sciana'
if keys[pygame.K_2]:
item = 'lava'
if keys[pygame.K_RIGHT]:
x += speed
if keys[pygame.K_LEFT]:
x -= speed
if keys[pygame.K_UP]:
y -= speed
if keys[pygame.K_DOWN]:
y += speed
if keys[pygame.K_SPACE]:
if item == 'sciana':
sciany.insert(pozycja, Sciana(x,y,25,25))
print(sciany)
pozycja += 1
player = window.blit(image,(x, y,))
window.fill((255,255,255))
window.blit(image,(x, y,))
pygame.display.update()