|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
报错情况﹕
Traceback (most recent call last):
File "F:/我的世界13.py", line 11, in <module>
zhujue_old = pygame.image.load("imges/zhujue.png")
FileNotFoundError: No file 'imges/zhujue.png' found in working directory 'F:\'.b
代码﹕
import pygame, sys
pygame.init()
width, height = 800, 600
window = pygame.display.set_mode((width, height))
windowrect = pygame.Rect(0, 0, width, height)
pygame.display.set_caption("跑酷")
shibai = 0
guan = 1
zhujue_old = pygame.image.load("imges/zhujue.png")
zhujue1 = pygame.transform.rotozoom(zhujue_old, 0, 0.6)
zhujue2 = pygame.transform.flip(zhujue1, True, False)
zhujue = zhujue1
zhujuew, zhujueh = zhujue.get_size()
x, y = 10, 470
xsu, ysu = 0, 0
boolwalk = False
walk = None
up = False
peng = False
zuidaguan = 10
yanjiang = [
[],
[[0, height - 300, width, 40]],
[[200, height - 51, 100, 41], [450, height - 51, 100, 41]],
[],
[],
[],
[[0, 0, width, 40], [350, height - 50, 300, 40]],
[],
[[470, height - 50, 330, 40]],
[]
]
zhangai = [
[[0, height - 50, 100, 40], [0, 270, width, 40]],
[[0, height - 50, width, 40]],
[[0, height - 50, width, 40]],
[[0, height - 50, width, 40], [300, height - 450, 50, 400], [350, height - 450, 200, 50], [350, height - 300, 200, 50]],
[[0, height - 50, width, 40], [500, height - 450, 50, 400], [300, height - 450, 200, 50], [300, height - 300, 200, 50]],
[[0, height - 50, 100, 40], [150, height - 200, 100, 40], [300, height - 350, 100, 40], [450, height - 500, 100, 40]],
[[0, height - 50, 100, 40], [100, 200, 40, 390], [250, 40, 40, 410], [250, height - 50, 100, 40], [550, height - 100, 100, 40]],
[[0, height - 50, 100, 40], [0, 300, 300, 40], [300, 40, 500, 40]],
[[0, height - 50, 470, 40]],
[[0, height - 50, width, 40]]
]
zilist = [
"欢迎来到我的跑酷游戏~试试按住上键吧~", "小心岩浆哦~", "难度+1", "经典正F", "经典反F", "天梯~", "小心哦~", "难度很高~", "信仰之跃! 加油! ", "恭喜你, 成功通关~"
]
font = pygame.font.Font("font/1.ttf", 30)
def ifin(x, y, w, h, mx, my):
if x <= mx <= x + w and y <= my <= y + h:
return True
return False
while True:
pygame.time.Clock().tick(60)
text = font.render("失败次数: " + str(shibai), True, (0, 0, 0))
text2 = font.render("第 {} 关".format(guan), True, (0, 0, 0))
text3 = font.render(zilist[guan - 1], True, (0, 0, 0))
textrect = text3.get_rect()
textrect.centerx = windowrect.centerx
if guan == 8:
textrect.y = 100
else:
textrect.y = 70
window.fill((255, 255, 255))
if y > height:
shibai += 1
x, y = 10, 470
ysu = 0
xsu = 0
if boolwalk:
if walk == pygame.K_d or walk == pygame.K_RIGHT:
if xsu <= 8:
xsu += 2
zhujue = zhujue1
if walk == pygame.K_a or walk == pygame.K_LEFT:
if xsu >= -8:
xsu -= 2
zhujue = zhujue2
xsu *= 0.9
x += xsu
ysu -= 1
y -= ysu
peng = False
for i in zhangai[guan - 1]:
if i:
wx, wy, ww, wh = i
if ifin(wx, wy, ww, wh, x + 1, y + zhujueh) or ifin(wx, wy, ww, wh, x + zhujuew - 1, y + zhujueh) or ifin(wx, wy, ww, wh, x + int(zhujuew / 2), y + zhujueh) or \
ifin(wx, wy, ww, wh, x + 1, y) or ifin(wx, wy, ww, wh, x + zhujuew - 1, y) or ifin(wx, wy, ww, wh, x + int(zhujuew / 2), y):
peng = True
if peng:
y += ysu
ysu = 0
if up:
ysu = 20
for i in zhangai[guan - 1]:
if i:
mx, my, mw, mh = i
pygame.draw.rect(window, (0, 0, 0), (mx, my, mw, mh))
if ifin(mx, my, mw, mh, x + zhujuew, y) or \
ifin(mx, my, mw, mh, x, y) or \
ifin(mx, my, mw, mh, x, y + zhujueh) or \
ifin(mx, my, mw, mh, x + zhujuew, y + zhujueh) or \
ifin(mx, my, mw, mh, x, y + int(zhujueh / 2)) or \
ifin(mx, my, mw, mh, x + zhujuew, y + int(zhujueh / 2)):
x -= xsu
if up:
if xsu > 0:
xsu = -10
else:
xsu = 10
ysu = 15
else:
ysu = 0
for i in yanjiang[guan - 1]:
if i:
mx, my, mw, mh = i
pygame.draw.rect(window, (255, 0, 0), (mx, my, mw, mh))
if ifin(mx, my, mw, mh, x + zhujuew, y) or ifin(mx, my, mw, mh, x, y) or ifin(mx, my, mw, mh, x, y + zhujueh) or ifin(mx, my, mw, mh, x + zhujuew, y + zhujueh):
shibai += 1
x, y = 10, 470
ysu = 0
xsu = 0
if ifin(width - 5, 0, 50, height, x + zhujuew, y) and guan < zuidaguan:
x, y = 10, 470
guan += 1
window.blit(zhujue, (x, y))
window.blit(text, (10, 10))
window.blit(text2, (10, 50))
window.blit(text3, textrect)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit()
if event.key in [pygame.K_a, pygame.K_d, pygame.K_RIGHT, pygame.K_LEFT]:
walk = event.key
boolwalk = True
if event.key == pygame.K_w or event.key == pygame.K_UP:
up = True
if event.type == pygame.KEYUP:
if event.key in [pygame.K_a, pygame.K_d, pygame.K_RIGHT, pygame.K_LEFT]:
boolwalk = False
if event.key == pygame.K_w or event.key == pygame.K_UP:
up = False
pygame.display.update()
|
|