用户:刘惠娟123456查看:0 回复:1 评论:0 创建时间:2021-12-24T19:18:50
【作品展示】

【作品介绍】
【作品源代码】
import pygame
import random
import time
pygame.init()
screen = pygame.display.set_mode((500, 600))
pygame.display.set_caption("端午快乐")
#加载图片
background = "sea.png"
background_image = pygame.image.load(background)
player = "dragonboat.png"
player_image = pygame.image.load(player)
player_x = 200
player_y = 500
zz = "zongzi.png"
zz_image = pygame.image.load(zz)
zz_x = 0
zz_y = -100
happy = "happy.png"
happy_image = pygame.image.load(happy)
player_move = 0
score = 0
font = pygame.font.SysFont("SimHei", 22)
keep_going = True
while keep_going:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keep_going = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
player_move = -4
if event.key == pygame.K_RIGHT:
player_move = 4
player_x += player_move
zz_y += 2
if player_x < 0:
player_x = 0
if player_x > 500-player_image.get_width():
player_x = 500-player_image.get_width()
if zz_y > player_y:
if(zz_x+zz_image.get_width() > player_x) and (zz_x < player_x + player_image.get_width()):
zz_x = random.randint(0, 350)
zz_y = -100
score += 1
if zz_y > 600:
zz_x = random.randint(0, 350)
zz_y = -100
#显示图片
screen.blit(background_image, (0, 0))
screen.blit(player_image, (player_x, player_y))
screen.blit(zz_image, (zz_x, zz_y))
text = font.render("粽子数量:"+str(score), True, (255, 215, 0), (255, 0, 0))
screen.blit(text, (360, 10))
if score == 1:
screen.blit(happy_image, (0, 200))
keep_going = False
pygame.display.update()
time.sleep(5)
pygame.quit()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn