편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2021.12.12

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


    블럭 생성 클래스

    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이되면 사라지게 하려는데 이 판별 코드를 어떻게 짜야 할지 모르겠습니다. 좀 알려주세요.

  • 프로필 알 수 없는 사용자님의 편집
    날짜2021.12.12

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


    블럭 생성 클래스

    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이되면 사라지게 하려는데 이 판별 코드를 어떻게 짜야 할지 모르겠습니다. 좀 알려주세요 ㅠㅠ