파이게임 블럭깨기 블럭과 공 충돌 판별 질문입니다.

조회수 342회

블럭 생성 클래스

class Block:
  def __init__(self, col, rect, speed=0, life=0):
      self.col = col
      self.rect = rect
      self.speed = speed
      self.life = life
      self.dir = random.randint(-45, 45) + 270

블럭 생성

BLOCK = []
for y in range(0, 8):
    for x in range(0, 9):
        Block_health = random.randrange(1,4)
        BLOCK.append(Block(colors[Block_health-1], Rect(x * 80 + 150, y * 40 + 40, 60, 20), 0, Block_health))

블럭에 1~3번 공이 부딫히면 사라지도록 랜덤하게 생성을 했습니다.

공과 블럭의 충돌을 판별

        LenBlock = len(BLOCK)
        BLOCK = [x for x in BLOCK if not x.rect.colliderect(BALL.rect) and x.life!=0]
        if len(BLOCK) != LenBlock:
            Score += 10
            BALL.dir *= -1

공과 블럭이 부딫히면 공의 체력을 깎고, 0이되면 사라지게 하려는데 이 판별 코드를 어떻게 짜야 할지 모르겠습니다. 좀 알려주세요.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)