本文整理汇总了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))