Как сделать обнаружение пули у врагов на пигме? - PullRequest
0 голосов
/ 19 мая 2019

Я не могу заставить работать обнаружение.

Так что я пытался заставить это работать, но оно говорит мне, что пуля или врагиго не имеют атрибута x

    for bullet in bullets:
        if bullet.x == enemigo.x and bullet.y == enemigo.y:
            bullets.pop(bullets.index(bullet))

        for enemy in enemigos:
            if bullet.x == enemigo.x and bullet.y == enemigo.y:
                enemigos.pop(enemigos.index(enemigo))        

Я бы ожидал, что это выстрелит врагом и пулей, но вместо этого он падает, поэтому я пытался заставить его работать, но он продолжает говорить мне, что пуля или врагиго не имеют атрибута x

Этовсе используемые мной классы

class gamerboy:
    def __init__(self, x, y, width,height,vel,left,right,up,down,walkCount):

        self.x = x 
        self.y = y 
        self.width = width 
        self.height = height 
        self.vel = vel
        self.left = left
        self.right = right
        self.up = up
        self.down = down
        self.walkCount = walkCount
class enemigo:
    andarDerecha = [pygame.image.load('zomdrch1.png'), 
pygame.image.load('zomdrch2.png'), pygame.image.load('zomdrch3.png'), pygame.image.load('zomdrch1.png'), pygame.image.load('zomdrch2.png'), pygame.image.load('zomdrch3.png'), pygame.image.load('zomdrch1.png'), pygame.image.load('zomdrch2.png'), pygame.image.load('zomdrch3.png')]
andarIzquierda = [pygame.image.load('izq1.png'), pygame.image.load('izq2.png'), pygame.image.load('izq3.png'), pygame.image.load('izq1.png'), pygame.image.load('izq2.png'), pygame.image.load('izq3.png'), pygame.image.load('izq1.png'), pygame.image.load('izq2.png'), pygame.image.load('izq3.png')]
def __init__(self, x, y, width, height, vel, walkCount):

    self.x = x 
    self.y = y 
    self.width = width 
    self.height = height 
    self.vel = vel
    self.walkCount = walkCount

def draw(self,win):
    self.mover()
    if self.walkCount + 1 >= 33:
        self.walkCount = 0
        win.blit(self.andarDerecha)
    if self.vel > 0:
        win.blit(self.andarDerecha[self.walkCount//3], (self.x,self.y))
        self.walkCount += 1
    if self.vel < 0:  # Otherwise we will display the walkLeft images
        win.blit(self.andarIzquierda[self.walkCount//3], (self.x,self.y))
        self.walkCount += 1

def mover(self):
    if gamer.x > self.x and self.x < 550:
        self.vel = 4
        self.x += self.vel
        self.walkCount = 0                          
    if gamer.x < self.x and self.x > 650:
        self.vel = -4
        self.x += self.vel
        self.walkCount = 0

снаряд класса: def init (self, x, y, radio, color, direccion): self.x = x self.y = y self.radio = radio self.color = color self.direccion = direccion self.vel = 54 * direccion

def disparar(self,win):
    pygame.draw.circle(win, self.color, (self.x,self.y), self.radio)
...