[Python] TypeError: descriptor 'append' for 'list' objects doesn't apply to a 'type' object...

Discussão em 'Python' iniciado por Stack, Julho 3, 2025.

  1. Stack

    Stack Membro Participativo

    I'm coding a space shooter game with pygame python 3.9.13 (if it can help) and i can't go around it because i need a list with my class 'Bulet' and i can't found a solution, code:

    from pygame import *
    from shooter_game_more import*
    init()
    win = display.set_mode((700,500))
    back = transform.scale(image.load('galaxy.jpg'),(700,500))

    #Objects
    rect=Rect(1000,1000,1,1)
    player=Player(315,430,'rocket.png',70,70)#line 21
    #list of future bullets
    bullets=list
    #list of enemys
    enemys=[
    Enemy(0,0,'ufo.png',70,70),#line 28 in shoter_game.py
    Enemy(105,0,'ufo.png',70,70),
    Enemy(210,0,'ufo.png',70,70),
    Enemy(315,0,'ufo.png',70,70),
    Enemy(420,0,'ufo.png',70,70),
    Enemy(525,0,'ufo.png',70,70),
    Enemy(630,0,'ufo.png',70,70),
    ]

    #music
    mixer.music.load('space.ogg')
    mixer.music.play()

    #game loop
    game=True
    while game:
    for e in event.get():
    if e.type==QUIT:
    game=False
    if key.get_pressed()[K_SPACE]:
    bullets.append(Bulet(player.x-35,player.y-35,'bullet.png',7,35))
    player.move(15)
    #update the screen
    display.update()
    win.blit(back,(0,0))
    for enemy in enemys:
    enemy.move(4)
    enemy.show(win)
    enemy.get_kill((player.rect,rect))
    player.show(win)
    time.wait(25)


    and the module 'shooter_game_more':

    from pygame import*
    from random import randint
    class Objectt():
    def __init__(self,x,y,imagee,width,height):
    self.x=x
    self.y=y
    self.image=transform.scale(image.load(imagee),(width,height))
    self.rect=self.image.get_rect()

    def show(self,winn):
    winn.blit(self.image,(self.x,self.y))
    def rect_center(self):#center is rect on his coordiate
    self.rect.x=self.x
    self.rect.y=self.y

    def collide(self,rects):#collide with a list of rects
    collide=False
    for i in rects:
    if self.rect.colliderect(i)==True:
    collide=True
    return collide

    class Player(Objectt):
    def move(self,speed):
    if key.get_pressed()[K_a]==True:
    self.x-=speed
    if key.get_pressed()[K_d]==True:
    self.x+=speed
    self.rect_center()
    class Enemy(Objectt):
    def __init__(self,x,y,imagee,width,height):
    super().__init__(x,y,imagee,width,height)
    self.y=-70
    def restart(self):# respawn
    self.x=randint(0,630)
    self.y=-70
    self.rect_center()
    def move(self,speed):
    if self.y<360:
    self.y+=speed
    else:
    self.y+=speed*4
    if self.y>500:
    self.restart()
    self.rect_center()
    def get_kill(self,listrects):#respawn the enemy when touched
    if self.collide(listrects)==True:
    self.restart()
    class Bulet(Objectt):
    def move(self,speed):
    self.y+=60
    if self.y<35:#return if is to high to be destroyed
    return True



    When I run it, it send this message: TypeError: descriptor 'append' for 'list' objects doesn't apply to a 'type' object.

    I want to add the class 'Bulet' to my list bullets, but a I accept a way to go around it thanks.

    Continue reading...

Compartilhe esta Página