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


Python Map.scroll方法代码示例

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


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

示例1: __init__

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import scroll [as 别名]
class Game:
    """game Main entry point. handles intialization of game and graphics.    
    members:
        map : map.Map() instance
    """

    done = False

    def __init__(self, width=640, height=480):
        """Initialize PyGame"""
        pygame.init()
        self.width, self.height = width, height
        self.clock = pygame.time.Clock()
        self.screen = pygame.display.set_mode((self.width, self.height))
        pygame.display.set_caption(GAME_TITLE)

        self.map = Map(self)

        print GAME_TITLE
        print GAME_ABOUT
        print GAME_HOTKEYS

    def main_loop(self):
        """Game() main loop"""
        while not self.done:
            # get key input, move, draw.
            self.handle_events()
            self.draw()
            self.clock.tick(60)

    def handle_events(self):
        """handle events."""
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                sys.exit()
            # event: keydown
            elif event.type == KEYDOWN:
                # exit on Escape
                if event.key == K_ESCAPE:
                    self.done = True
                # toggle bool
                elif event.key == K_s:
                    self.map.scrolling = not self.map.scrolling
                elif event.key == K_SPACE:
                    # random map
                    self.map.randomize()

            elif event.type == MOUSEMOTION:
                self.map.scroll(event.rel)

    def draw(self):
        """render screen"""
        self.screen.fill(Color("black"))
        self.map.draw()
        pygame.display.flip()
开发者ID:gbdu,项目名称:ninmonkey,代码行数:58,代码来源:game.py

示例2: WorldScreen

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import scroll [as 别名]
class WorldScreen(Screen):
    """The main game screen with a world to wander around."""

    def __init__(self, map_name):
        Screen.__init__(self)
        self.load_screen = LoadScreen()
        self.load_screen.draw()
        self.camera = pygame.Rect((0,0), CAMERA_SIZE)
        self.map = Map(map_name)
        self.party = PartyManager(self)
        self.npcs = NPCManager(self)
        self.gui = StatsWindow(self.party.sprites)
        self.party.add("hero")
        self.npcs.add("npc")
        self.dialog_text = "Sample dialog text."
        self.map.scroll(self.camera, self.party.chars['hero'])

    def add_sprites(self):
        self.chars = pygame.sprite.Group([
            self.party.sprites ])
        self.all_sprites = pygame.sprite.OrderedUpdates([
            self.map.layers['terrain'],
            self.chars,
            self.map.layers['foreground'],
            self.gui ])

        self.layers = pygame.sprite.LayeredDirty()
        for sprite in self.all_sprites:
            self.layers.add(sprite)
        # critical line to make the npc appear!
        # only took 50 mins to find this!    
        self.layers.add(self.npcs.sprites)

    def draw(self):
        """Draws the sprites to the screen and updates the window."""

        self.layers.update()
        rects = self.layers.draw(self.window)
        pygame.display.update(rects)

        if random.random() < 0.01:
            sounds.sounds.FEAR.play()            

        if random.random() < 0.003:
            sounds.sounds.BABY.play()            


    def destroy(self):
        """Destroy the current screen."""

        for sprite in self.all_sprites:
            sprite.kill()

        self.map = None
        self.party = None
        self.gui = None
开发者ID:tomviner,项目名称:crawlr,代码行数:58,代码来源:screens.py

示例3: WorldScreen

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import scroll [as 别名]
class WorldScreen(Screen):
    """The main game screen with a world to wander around."""

    def __init__(self, map_name):
        Screen.__init__(self)
        self.load_screen = LoadScreen()
        self.load_screen.draw()
        self.camera = pygame.Rect((0, 0), CAMERA_SIZE)
        self.map = Map(map_name)
        self.party = PartyManager(self)
        self.npcs = NPCManager(self)
        self.gui = StatsWindow(self.party.sprites)
        self.party.add("hero")
        self.npcs.add("npc")
        self.dialog_text = "Sample dialog text."
        self.map.scroll(self.camera, self.party.chars["hero"])

    def add_sprites(self):
        self.chars = pygame.sprite.Group([self.party.sprites])
        self.all_sprites = pygame.sprite.OrderedUpdates(
            [self.map.layers["terrain"], self.chars, self.map.layers["foreground"], self.gui]
        )

        self.layers = pygame.sprite.LayeredDirty()
        for sprite in self.all_sprites:
            self.layers.add(sprite)

    def draw(self):
        """Draws the sprites to the screen and updates the window."""

        self.layers.update()
        rects = self.layers.draw(self.window)
        pygame.display.update(rects)

    def destroy(self):
        """Destroy the current screen."""

        for sprite in self.all_sprites:
            sprite.kill()

        self.map = None
        self.party = None
        self.gui = None
开发者ID:rieya-uc,项目名称:crawlr,代码行数:45,代码来源:screens.py


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