2010-04-20 5 views
2

나는 요리사 (내가 가지고있는 이미지, 하하)가있는 라이브 와이어와 파이 게임을 사용하여 게임을 작성하려고 시도하고 있으며 하늘에서 떨어지는 바위는 피합니다. 암석은 무작위로 떨어지게됩니다. 나는 1 개의 바위가 처음부터 떨어지기를 원합니다. 그리고 나서 당신이 성공적으로 바위를 피할 때마다, 당신이 잃을 때까지 2 개의 더 많은 바위가 떨어졌습니다. 내가 지금까지 가지고있는 것은 요리사와 1 개의 바위가 떨어지는 것이다. 그러나 어떤 이유로 Sprite가 충돌하거나 바위가 화면 하단에 닿으면 게임이 끝났습니다. 내가 말한 것처럼 메시지를 통해 게임을하지 않고 종료합니다. 나는 매우 혼란스럽고 내가 한 일을 볼 수 없다. 나는 내가 2 개의 바위 부분을 위해 그것을 정확하게 코드화하지 않았다는 것을 안다. 그러나 나는 심지어 약간 달릴 수 없다. 도움! 당신은 Rock classend_game 방법을 선언 한'Dodger'타입 게임

from livewires import games, color 
import random 

games.init(screen_width = 640, screen_height = 480, fps = 50) 


class Chef(games.Sprite): 

    image = games.load_image("chef.bmp") 

    def __init__(self): 
     super(Chef, self).__init__(image = Chef.image, 
            x = games.mouse.x, 
            bottom = games.screen.height) 

    def update(self): 
     self.x = games.mouse.x 

     if self.left < 0: 
      self.left = 0 

     if self.right > games.screen.width: 
      self.right = games.screen.width 

     self.check_catch() 

    def check_catch(self): 
     for pizza in self.overlapping_sprites: 
      if not self.bottom>games.screen.height: 
       self.end_game() 


class Rock(games.Sprite): 

    def update(self): 
     if self.bottom > games.screen.height: 
       new_rock=Rock(x=random.randrange(games.screen.width), 
           y=10, 
           dy=1) 
       games.screen.add(new_rock) 

    def end_game(self): 
     end_message = games.Message(value = "Game Over", 
            size = 90, 
            color = color.red, 
            x = games.screen.width/2, 
            y = games.screen.height/2, 
            lifetime = 5 * games.screen.fps, 
            after_death = games.screen.quit) 
     games.screen.add(end_message) 


def main(): 

    wall_image = games.load_image("wall.jpg", transparent = False) 
    games.screen.background = wall_image 

    the_chef = Chef() 
    games.screen.add(the_chef) 

    rock_image=games.load_image("rock.bmp") 
    the_rock=Rock(image=rock_image, 
        x=random.randrange(games.screen.width), 
        y=10, 
        dy=1) 
    games.screen.add(the_rock) 

    games.mouse.is_visible = False 

    games.screen.event_grab = True 
    games.screen.mainloop() 

main() 

답변

0

하지만 당신은 Chef classcheck_catch 방법에서 호출됩니다 여기에 내가 지금 무슨이다.

+0

감사합니다. 내 주된 문제는 스프라이트가 화면 하단에 도달하면 게임이 종료된다는 것입니다. – Jam

+0

왜냐하면 : self.overlapping_sprites에있는 피자에 대해 def check_catch (self) : : if self.bottom> games.screen.height : self.end_game() – ninMonkey

관련 문제