Python 我怎样才能得到改变生活的次数(pygame)?
我是python和pygame的新手,到目前为止,我设法让一切都正常工作,但却不知道如何让我的生活陷入低谷 如果你还没有制定出一个简单的水果捕捉游戏 我设法使我的分数提高了。我试着说,如果水果低于某个x坐标,就会夺走生命,但它不起作用Python 我怎样才能得到改变生活的次数(pygame)?,python,pygame,Python,Pygame,我是python和pygame的新手,到目前为止,我设法让一切都正常工作,但却不知道如何让我的生活陷入低谷 如果你还没有制定出一个简单的水果捕捉游戏 我设法使我的分数提高了。我试着说,如果水果低于某个x坐标,就会夺走生命,但它不起作用 import time import random import pygame from pygame import* pygame.init() myname=input('What is your name') #set the window size win
import time
import random
import pygame
from pygame import*
pygame.init()
myname=input('What is your name')
#set the window size
window= pygame.display.set_mode((800,600) ,0,24)
pygame.display.set_caption("Fruit Catch")
#game variables
myscore=0
mylives=3
mouth_x=300
fruit_x=250
fruit_y=75
fruitlist=['broccoli.gif','chicken.gif']
#prepare for screen
myfont=pygame.font.SysFont("Britannic Bold", 55)
label1=myfont.render(myname, 1, (240, 0, 0))
label3=myfont.render(str(mylives), 1, (20, 255, 0))
#grapchics
fruit=pygame.image.load('data/chicken.png')
mouth=pygame.image.load('data/v.gif')
backGr=pygame.image.load('data/kfc.jpg')
#endless loop
running=True
while running:
if fruit_y>=460:#check if at bottom, if so prepare new fruit
fruit_x=random.randrange(50,530,1)
fruit_y=75
fruit=pygame.image.load('data/'+fruitlist[random.randrange(0,2,1)])
else:fruit_y+=5
#check collision
if fruit_y>=440:
if fruit_x>=mouth_x and fruit_x<=mouth_x+300 :
myscore+=1
fruit_y=600#move it off screen
pygame.mixer.music.load('data/eating.wav')
#detect key events
for event in pygame.event.get():
if (event.type==pygame.KEYDOWN):
if (event.key==pygame.K_LEFT):
mouth_x-=55
if (event.key==pygame.K_RIGHT):
mouth_x+=55
label2=myfont.render(str(myscore), 1, (20, 255, 0))
window.blit(backGr,(0,0))
window.blit(mouth, (mouth_x,440))
window.blit(fruit,(fruit_x, fruit_y))
window.blit(label1, (174, 537))
window.blit(label2, (700, 157))
window.blit(label3, (700, 400))
pygame.display.update()
导入时间
随机输入
导入pygame
从pygame导入*
pygame.init()
myname=input('你叫什么名字')
#设置窗口大小
window=pygame.display.set_模式((800600),0,24)
pygame.display.set_标题(“水果捕获”)
#博弈变量
myscore=0
迈利夫=3
嘴x=300
水果x=250
水果y=75
水果列表=['brocoli.gif','chicken.gif']
#准备上映
myfont=pygame.font.SysFont(“不列颠粗体”,55)
label1=myfont.render(myname,1,(240,0,0))
label3=myfont.render(str(mylives),1,(20255,0))
#笔画
fruit=pygame.image.load('data/chicken.png')
mouth=pygame.image.load('data/v.gif')
backGr=pygame.image.load('data/kfc.jpg'))
#无止境的循环
运行=真
运行时:
如果水果y>=460:#检查底部是否有,如果有,准备新水果
水果x=random.randrange(50530,1)
水果y=75
fruit=pygame.image.load('data/'+水果列表[random.randrange(0,2,1)])
其他:水果y+=5
#检查碰撞
如果水果y>=440:
如果在检查碰撞时,果肉>=嘴肉和果肉,请使用else
#check collision
if fruit_y>=440:
if fruit_x>=mouth_x and fruit_x<=mouth_x+300 :
myscore+=1
fruit_y=600#move it off screen
pygame.mixer.music.load('data/eating.wav')
else:
mylives-= 1
#检查碰撞
如果水果y>=440:
如果在检查碰撞时,果肉>=嘴肉和果肉,请使用else
#check collision
if fruit_y>=440:
if fruit_x>=mouth_x and fruit_x<=mouth_x+300 :
myscore+=1
fruit_y=600#move it off screen
pygame.mixer.music.load('data/eating.wav')
else:
mylives-= 1
#检查碰撞
如果水果y>=440:
如果水果>=mouth\u x和水果,您还可以显示您可能尝试添加到该文件中以减少生命的代码。因为当前的内容显然根本不会涉及到mylives
或label3
。为什么不这样做:如果你还可以显示你可能试图添加到其中以减少生命的代码,请。因为现在的东西显然根本就不会触及我的生命或label3。你为什么不这样做呢:如果水果