當前位置: 首頁>>代碼示例>>Python>>正文


Python Background.blit方法代碼示例

本文整理匯總了Python中background.Background.blit方法的典型用法代碼示例。如果您正苦於以下問題:Python Background.blit方法的具體用法?Python Background.blit怎麽用?Python Background.blit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在background.Background的用法示例。


在下文中一共展示了Background.blit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from background import Background [as 別名]
# 或者: from background.Background import blit [as 別名]
def main():
  black = 0, 0, 0

  SCORE = 0

  clock = pygame.time.Clock()
  pygame.init()

  start = pygame.image.load("start.png").convert()
  start = pygame.transform.scale(start, (width, width))
  screen.blit(start, (0, 0))
  pygame.display.flip()

  n = True
  while n:
    for event in pygame.event.get():
      if event.type == KEYDOWN:
        n = False
        break

  fruit_contours = FruitContours()
  back = Background(screen, width, height)
  fruits = []

  beat_timer = times.BeatTimer(fruit_falling_speed, fruit_falling_distance)


  # A dictionary for which buttons that will generate what fruit
  fruitdir = {K_UP: "apple", K_LEFT: "lemon", K_RIGHT: "banana"}

  # PLay that music you!
  pygame.mixer.init()
  pygame.mixer.Sound("harder.ogg").play()

  while 1:
    screen.fill(black)

    fruit_contours.unglow()

    delta = clock.tick(30)

    for event in pygame.event.get():
      if event.type == QUIT: return
      elif event.type == KEYDOWN:
        button = event.key
        if button == K_ESCAPE:
          print "You win:", SCORE, "points!", "HIGHSCORE!"
          return
        elif button in (K_UP,K_LEFT,K_RIGHT):
          for f in fruits:
            if f.hit == False and f.fruit == fruitdir[button] and f.rect.bottom > (height - 150):
              SCORE += 1
              fruit_contours.glow(f.fruit)
              f.hit = True
              break
            # Lose points if you're cheating
            elif f == fruits[-1]: SCORE -= 1

    back.blit()

    # Move and blit all the fruits on the screen
    for index, fruit in enumerate(fruits):
      if fruit.move(delta):
        fruit.blit()
      else:
        if not fruit.hit: SCORE -= 1
        fruits.pop(index)

    # Generate random fruits
    if beat_timer.get_beat(delta):
      new_fruit = generateRandomFruit()

      fruits.append(new_fruit)

    # Draw the fruit contours
    fruit_contours.blit()

    pygame.display.flip()
    pygame.display.set_caption("Score: " + str(SCORE))
開發者ID:adamse,項目名稱:wowhack2,代碼行數:81,代碼來源:falling_fruits.py


注:本文中的background.Background.blit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。