如何使物体不断下降?蟒蛇游戏

时间:2017-04-22 20:40:10

标签: python-3.x pygame

所以我在python中制作一个游戏,当我拍摄我的飞行物体时它会爆炸,但是在它爆炸后不再有物体掉下来。我需要知道如何解决这个问题,以便物体能够不断地射击并摧毁。这是我的代码:

SPEED = 3
#set initial location of image
image_x = random.randrange(0, 480)
image_y = -50

image_y = image_y + SPEED
if image_y > 640:
    image_x = random.randrange(0, 480)
    image_y = -25

def __init__(self, x = 40, y = 40, speed = 2, odds_change = 200):
    """ Initialize the Fly object. """

    super(Fly, self).__init__( image = Fly.image,
                          y = y, x = random.randrange(0, 480),
                          dy = speed,
                         dx = speed)
    self.bottom = 0

    self.odds_change = odds_change
    self.time_til_drop = 500

def update(self):
    """ Determine if direction needs to be reversed."""
    if self.left < 0 or self.right > games.screen.width:
        self.dx = -self.dx
    elif random.randrange(self.odds_change) == 0:
        self.dx = -self.dx

    self.check_drop()

def check_drop(self):
    """ Decrease countdown or drop fly and reset countdown. """
    if self.time_til_drop > 0:
        self.time_til_drop -= 1 
    else:
       self.time_til_drop = 500
       new_fly = Fly(x = self.x)
       games.screen.add(new_fly)

       #set buffer to approx 30% of fly height regardless of fly speed
       self.time_til_drop = int(new_fly.height * 1000 / Fly.SPEED) + 1000

def die(self):
    """Destroy Fly."""
    #If fly is destroyed, then continue playing
    self.destroy()

1 个答案:

答案 0 :(得分:0)

你实际上并没有使用课程,你只是在编写函数。