用户:
李梓豪chinaIqs查看:0 回复:1 评论:0 创建时间:2024-03-08T13:24:12
【作品展示】

【作品介绍】
通过点击来躲避障碍物
【作品源代码】
import pygame,sys
from pygame.locals import*
import os
import time,random
pygame.init()
pygame.mixer.music.load("boy.mp3")
pygame.mixer.music.set_volume(1)
pygame.mixer.music.play(-1)
num = 0
WIDTH, HEIGHT = 1400, 800
screen = pygame.display.set_mode((WIDTH, HEIGHT),flags=RESIZABLE)
box_Rect_x = 1600
box_Rect_y = 550-50
box = pygame.image.load("box1.png").convert()
boxs = {"1": (141, 144), "2": (284, 144),'6':(150,431)}
pygame.display.set_caption("跑酷游戏")
bg = pygame.image.load("bg.png")
bg_x,喵_y = 0,290
game = True
os.environ["SDL_IME_SHOW_UI"] = '1'
clock = pygame.time.Clock()
score = 0
while True:
for event in pygame.event.get():
if event.type == QUIT :
print(
"\nuninstall the pygame community喵contribute.html")
sys.exit()
pygame.quit()
elif event.type == MOUSEBUTTONDOWN:
sound = pygame.mixer.Sound("jump.mp3")
sound.play()
喵_y -= 200
if game == True:
screen.fill((0,225,0))
print("背景的x坐标", bg_x, "箱子的x坐标", box_Rect_x)
clock.tick(60)
num += 1
time.sleep(0.05)
喵 = pygame.image.load(str(num%4)+".png")
喵_rect = Rect((200+40,喵_y,300,300))
bg_x -= 30
if bg_x <= -1400:
bg_x = 0
screen.blit(bg, (bg_x, 0))
if box_Rect_x >= 0:
box_Rect_x -= 20
box_Rect = pygame.Rect((box_Rect_x, box_Rect_y, 140, 144))
pygame.draw.rect(screen,(255,0,0),box_Rect)
screen.blit(box, (box_Rect_x, box_Rect_y))
if box_Rect_x <20:
score += 1
#pygame.draw.rect(screen,(0,0,0),喵_rect)
screen.blit(喵, (400/2, 喵_y))
if box_Rect.colliderect(喵_rect):
Font = pygame.font.SysFont("TimesNewRoman",50)
font = Font.render(f" SCORE:{score}",False,(255,255,255))
screen.blit(font,(WIDTH/2,HEIGHT/2))
pygame.display.update()
print(pygame.font.get_fonts)
game = False
if box_Rect_x<0:
box_Rect_x = 1600
box_random = [1,2,6]
box_image = "box"+str(random.choice(box_random))+".png"
box = pygame.image.load(box_image).convert()
if box_image == "box2.png":
box_Rect_y = 550 - 190
box_Rect = pygame.Rect((box_Rect_x,box_Rect_y, boxs["2"][0], 144))
elif box_image == "box6.png":
box_Rect_y = 550 - 50
box_Rect = pygame.Rect(
(box_Rect_x, box_Rect_y, boxs["6"][0], boxs["6"][1]))
else:
box_Rect_y = 550 - 50
box_Rect = pygame.Rect((box_Rect_x, box_Rect_y, boxs["1"][0], 144))
if 喵_y < 300:
喵_y += 30
pygame.display.update()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn