0

Python と Pygame を使用してゲーム プロジェクトを作成しています。(画面は 770 x 485) ランダムに生成された四角形がドロップダウンするので、円を左右に 5 つの垂直レーンに移動します。それらをランダムに生成するための Wall クラスがありますが、長方形の各インスタンスと円の間の衝突を検出する方法がわかりません。

z のビットと c リストは、それらを衝突させようとする場所ですが、最初の四角形とのみ衝突し、他の落下四角形は検出されません (互いに 100 ティックの期間後に生成されます)。 ) 誰かが私を正しい方向に向けることができますか? z変数、cリスト、v変数についてはよくわかりません:\

前もって感謝します!

class Wall:
    def __init__(self,colour,x,y,life):
        self.colour = colour
        self.x = x
        self.y = y
        self.life = life
    def drop(self):
        pygame.draw.rect(screen, self.colour, (self.x, self.y, 154, 30))
        self.y += 1.25
        self.life -= 1
        if self.life < 0:
            wall.remove(self)

def playMode(): #assume everything is indented properly
global wall, points
check   = True
left    = False
right   = False
circlex = 385
degrees = 0
health  = 3
wall = []
x = 2
points = 0
n = 0
c = []
starttime = time.time()
while True:
    runningtime = time.clock()
    screen.fill((255,255,255))
    x -= 1
    if x == 1:
      wall.append(Wall((random.randint(1,255),random.randint(1,255),random.randint(1,255)),
random.choice([0, 154, 308, 462, 616]), -30 , 450))
        x = 100
    for i in wall:
        i.drop()
    z = wall[-1]
    c.append(z)
    v = c[(n)]
    if 445 >= v.y >= 340 and v.x == (circlex - 77):           
        health -= 1
        points -= 5
        v.y = 485 #moves this instance offscreen so it doesn't make the hp go to 0 immediately
        n += 1
        print v.y

    circle = pygame.draw.circle(screen, colour,(circlex, 409), 50)

    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                showPauseScreen()
            elif event.key == K_p:
                showPauseScreen()
            elif event.key == K_LEFT:
                if circlex > 77:
                    circlex = circlex - 154
            elif event.key == K_RIGHT:
                if circlex < 616:
                    circlex = circlex + 154
        elif event.type == QUIT:
            terminate()

    if health == 0:
        check = False
        return #goes to gameover screen basically
    pygame.display.update()
    clock.tick(100)
4

1 に答える 1