1

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

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

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

现在这是我正在尝试的一个....

4

3 回答 3

3
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
于 2013-03-17T17:56:37.797 回答
1

两个例子:

您可以强制在两次跳跃之间设置最短时间,但为了简化示例,我将其省略了。询问您是否还有其他问题。

于 2013-03-17T17:56:35.857 回答
-2

使用计数器不是更容易吗?只需在你的播放器中设置一个计数器变量 = 0,然后定义你的跳跃并设置计数器 += 1。然后说如果计数器 < 2 那么你可以跳跃。不 ?

于 2014-10-14T22:34:27.507 回答