gpt4 book ai didi

python - Pygame 双跳

转载 作者:行者123 更新时间:2023-12-01 05:47:56 29 4
gpt4 key购买 nike

我几乎要放弃了,所以我需要帮助。我正在尝试制作一个具有双跳的简单平台游戏......我一直在兜圈子,试图找到有用的东西到目前为止,我最好的想法是比较刻度数,但每次我得到一些想法时,我都会设法把它搞砸,但我不知道如何......有简单的方法吗?

请忽略任何不必要的变量,这只是一个示例

Clock=pygame.time.Clock()

t=0
a=0
b=0
f=0
m=0

while True:
Clock.tick(180)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key==K_SPACE and b==0:
movey=-1
a=1
t=pygame.time.get_ticks()
if event.key==K_SPACE and b==1:
f=pygame.time.get_ticks()
if f<=t+238:
a=1
else:
pass
if event.type == KEYUP:
if event.key==K_SPACE and b==0 and a==1:
a=0
b=1
if event.key==K_SPACE and b==1 and a==1:
m=1
b=3
s=y
if m==1:
y+=movey
if y==s-32:
m==0

elif y<=312 and movey==-1:
movey=+1
elif y==344 and movey==+1:
movey=0
a=0
b=0
else:
y+=movey

现在这就是我正在尝试的......

最佳答案

g = -1  # gravity
floor = 0 # where frog stands


class Frog(): # say you have a frog
def __init__(self):
self.y = 0 # distance from ground
self.y_speed = 0 # speed
self.jumping = 0 # jumping status

def jump(self):
if self.jumping == 0:
self.y_speed = 9 # a big jump
self.jumping = 1 # change jumping status
# I want the small jump available only when falling
elif self.jumping == 1 and self.y_speed <= 0:
self.y_speed = 5 # a small one
self.jumping = 2 # change jumping status

def update(self): # this is called by mainloop
self.y_speed += g # change the acceleration
self.y = max(self.y + self.y_speed, floor) # don't want fall off
if self.y == 0: # on the ground again!
self.jumping = 0 # reset jump
self.y_speed = 0 # reset speed

关于python - Pygame 双跳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15463422/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com