我几乎已经放弃了,所以我需要帮助。
我正在尝试制作一个具有双跳的简单平台游戏...
我一直围着圈子奔跑,试图找到可行的方法
到目前为止,我最好的主意是比较刻度线的数量,但是每当我有了一个主意时,我都会设法将其全部搞乱,但我不知道如何...
有没有简单的方法?
请忽略任何不必要的变量,这仅是示例
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