当前位置: 首页>>代码示例>>Python>>正文


Python Score.modify_score方法代码示例

本文整理汇总了Python中score.Score.modify_score方法的典型用法代码示例。如果您正苦于以下问题:Python Score.modify_score方法的具体用法?Python Score.modify_score怎么用?Python Score.modify_score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在score.Score的用法示例。


在下文中一共展示了Score.modify_score方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GameView

# 需要导入模块: from score import Score [as 别名]
# 或者: from score.Score import modify_score [as 别名]

#.........这里部分代码省略.........
        """
        from score import Score
        self.score = Score(self.background)

    def _setup_sprites(self):
        """
        Initializes all sprites

        """
        from sprite import Pad, Ball
        self.pad_left = Pad(relative_to=self.playarea_rect)
        self.pad_right = Pad(relative_to=self.playarea_rect, align=1)
        self.ball = Ball(relative_to=self.playarea_rect)
        self.allsprites = pygame.sprite.RenderUpdates((
                    self.pad_left,
                    self.pad_right,
                    self.ball
                    ))
        self.pads = pygame.sprite.Group((self.pad_left, self.pad_right))

    def _setup_background(self):
        self.background = pygame.Surface((self.screen.get_size()))
        self.background = self.background.convert()
        self.background.fill((0,0,0))

        self.playarea = pygame.image.load(os.path.join("data", "playfield.png"))
        self.playarea.convert_alpha()
        self.playarea_rect = self.playarea.get_rect()
        self.playarea_rect.top = 50
        self.background.blit(self.playarea, self.playarea_rect)

    def kill(self):
        self.allsprites.empty()
        self.stopped = True

    def game_over(self, win=True):
        """
        What do you think it does??

        """
        self.ball.kill()
        if win:
            image = pygame.image.load(os.path.join("data", "fuckyea.jpg"))
        else:
            image = pygame.image.load(os.path.join("data", "fuuu.jpg"))
        image = image.convert()
        image_rect = image.get_rect()
        image_rect.center = [400, 300]
        self.background.blit(image, image_rect)
        pygame.display.flip()
        self.stopped = True
        #self.event_manager.unregister_listener(self)

    def handle_collisions(self):
        """
        Detect ball - sprite collisions and handle them

        """
        collisions = pygame.sprite.spritecollide(self.ball, self.pads, False)
        if len(collisions):
            # in the future there will be generic collision test
            # so the ball will bounce of extra walls etc
            self.ball.movement_vector[0] = -self.ball.movement_vector[0] 
            self.ball.image = pygame.transform.flip(self.ball.image, 1, 0)
            ball_mid = self.ball.rect.midright[1]
            pad = collisions[0]
            pad_mid = pad.rect.midright[1]
            angle_speed = (pad_mid - ball_mid)/10
            self.ball.movement_vector[1] -= angle_speed

    def notify(self, event):
        """
        Recieve events

        """
        if isinstance(event, events.TickEvent) and not self.stopped:
            if not self.paused:
                self.handle_collisions()
                self.allsprites.update()
                if self.surfaces:
                    self._blit_registered_surfaces()
                self.screen.blit(self.background, (0,0))
                self.allsprites.draw(self.screen)
                pygame.display.flip()
        elif isinstance(event, events.RegisterSurfaceEvent):
            self.register_surface(event.surface)
        elif isinstance(event, events.PauseEvent):
            self.paused = not self.paused
        elif isinstance(event, events.BlitRequestEvent):
            surface = getattr(self, event.surface_name)
            surface.blit(event.element, event.element_rect)
        elif isinstance(event, events.ModifyScoreEvent):
            self.score.modify_score(event)
        elif isinstance(event, events.GameOverEvent):
            self.game_over(event.win)
        elif isinstance(event, events.ControlPadEvent):
            if event.left:
                self.pad_left.pos =  event.pos
            else:
                self.pad_right.pos =  event.pos
开发者ID:pielgrzym,项目名称:pung,代码行数:104,代码来源:views.py


注:本文中的score.Score.modify_score方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。