2017-04-22 1 views
-3

그래서 저는 파이썬으로 게임을 만들고 있어요. 비행 물체를 쏘면 폭발하지만, 폭발하지 않으면 더 이상 물체가 떨어지지 않습니다. 개체를 촬영하고 파괴 할 수 있도록이 문제를 해결하는 방법을 알아야합니다. 여기 내 코드는 다음과 같습니다.개체를 계속 내리는 방법? python game

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() 

답변

0

실제로 당신은 클래스를 사용하지 않고 있습니다.