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


Python Map.render方法代码示例

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


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

示例1: render

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import render [as 别名]
    def render(screen, width, height, gamestate, selected_id, host, port):
        raycaster = Raycaster(gamestate["players"], gamestate["walls"])
        raycaster.update()
        map_size = raycaster.get_map_size() + 1.0

        if selected_id == 0:
            for player in gamestate["players"]:
                Game.render_vision(raycaster, player, screen, width, height, map_size, len(gamestate["players"]))
        elif selected_id > 0 and selected_id - 1 < len(gamestate["players"]):
            Game.render_vision(raycaster, gamestate["players"][selected_id - 1], screen, width, height, map_size,
                               len(gamestate["players"]))

        Map.render(gamestate["walls"], screen, width, height, map_size)
        for p in gamestate["players"]:
            Player.render(p, raycaster, screen, width, height, map_size)
        for projectile in gamestate["projectiles"]:
            Projectile.render(projectile, screen, width, height, map_size)
        for p in gamestate["players"]:
            Player.render_font(p, screen, width, height, map_size)


        myfont = pygame.font.SysFont("Arial", 22)
        label = myfont.render("Ticks remaining: " + str(gamestate["remaining_ticks"]), 1, (255, 255, 255))
        s = pygame.Surface((label.get_width() + 20, label.get_height() + 20), pygame.SRCALPHA)  # per-pixel alpha
        s.fill((45, 45, 45, 200))
        screen.blit(s, (width // 2 - label.get_width() // 2 - 10, 0))
        screen.blit(label, (width // 2 - label.get_width() // 2, 10))

        myfont = pygame.font.SysFont("Arial", 16)
        label = myfont.render("test", 1, (255, 255, 255))
        line_height = label.get_height()
        myfont = pygame.font.SysFont("Arial", 32)
        label = myfont.render("Ranking-----", 1, (255, 255, 255))
        line_width = label.get_width()
        s = pygame.Surface((line_width + 20, line_height * (len(gamestate["ranking"]) + 2) + 40), pygame.SRCALPHA)  # per-pixel alpha
        s.fill((45, 45, 45, 200))
        screen.blit(s, (0, 0))

        myfont = pygame.font.SysFont("Arial", 32)
        label = myfont.render("Ranking", 1, (255, 255, 255))
        screen.blit(label, (10, 10))
        myfont = pygame.font.SysFont("Arial", 16)
        i = 2
        sorted_x = sorted(gamestate["ranking"].items(), key=operator.itemgetter(1), reverse=True)
        for key, value in sorted_x:
            label = myfont.render(key + ": " + str(value), 1, (255, 255, 255))
            screen.blit(label, (10, 10 + label.get_height() * 1.1 * i))
            i += 1

        myfont = pygame.font.SysFont("Arial", 32)
        label = myfont.render(host + ":" + str(port), 1, (255, 255, 0))
        s = pygame.Surface((label.get_width() + 20, label.get_height() + 20), pygame.SRCALPHA)  # per-pixel alpha
        s.fill((45, 45, 45, 200))
        screen.blit(s, (width // 2 - label.get_width() // 2 - 10, height - label.get_height() - 20))
        screen.blit(label, (width // 2 - label.get_width() // 2, height - label.get_height() - 10))
开发者ID:Programmierspiele,项目名称:into-darkness,代码行数:57,代码来源:game.py

示例2: render_game

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import render [as 别名]
    def render_game(self, screen, width, height):
        if self.selected_player == 0:
            self.render_lobby(screen, width, height, False)
            return
        raycaster = Raycaster(self.players, self.walls)
        raycaster.update()
        map_size = raycaster.get_map_size() + 1.0

        #self.render_vision(raycaster, self.player, screen, width, height, map_size)
            

        Map.render(self.walls, screen, width, height, map_size)
        #Map.render(raycaster.get_lines(), screen, width, height, map_size)
        for p in self.players:
            Player.render(p, raycaster, screen, width, height, map_size)
        for projectile in self.projectiles:
            Projectile.render(projectile, screen, width, height, map_size)
        for p in self.players:
            Player.render_font(p, screen, width, height, map_size)


        myfont = pygame.font.SysFont("Arial", 22)
        label = myfont.render("Ticks remaining: " + str(self.remaining_ticks), 1, (255, 255, 255))
        s = pygame.Surface((label.get_width() + 20, label.get_height() + 20), pygame.SRCALPHA)  # per-pixel alpha
        s.fill((45, 45, 45, 200))
        screen.blit(s, (width // 2 - label.get_width() // 2 - 10, 0))
        screen.blit(label, (width // 2 - label.get_width() // 2, 10))

        myfont = pygame.font.SysFont("Arial", 16)
        label = myfont.render("test", 1, (255, 255, 255))
        line_height = label.get_height()
        myfont = pygame.font.SysFont("Arial", 32)
        label = myfont.render("Ranking-----", 1, (255, 255, 255))
        line_width = label.get_width()
        s = pygame.Surface((line_width + 20, line_height * (len(self.ranking) + 2) + 40), pygame.SRCALPHA)  # per-pixel alpha
        s.fill((45, 45, 45, 200))
        screen.blit(s, (0, 0))

        myfont = pygame.font.SysFont("Arial", 32)
        label = myfont.render("Ranking", 1, (255, 255, 255))
        screen.blit(label, (10, 10))
        myfont = pygame.font.SysFont("Arial", 16)
        i = 2
        sorted_x = sorted(self.ranking.items(), key=operator.itemgetter(1), reverse=True)
        for key, value in sorted_x:
            label = myfont.render(key + ": " + str(value), 1, (255, 255, 255))
            screen.blit(label, (10, 10 + label.get_height() * 1.1 * i))
            i += 1
开发者ID:Programmierspiele,项目名称:into-darkness-ai-python,代码行数:50,代码来源:renderer.py

示例3: main

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import render [as 别名]
def main():
    """Where the magic happens."""

    options, configs = parse_args(sys.argv)
    ip_reader = csv.reader(open(options.ips, 'rb'), delimiter=',')
    ip_converter = IpConverter(configs)
    width = options.width
    height = options.height
    color = 'black'
    # Here we apply ratios, since the map will be croped later on.
    width = int(width * 2.5)
    height = int(height * 1.33333333) 
    world_map = Map(width, height, color)

    roll = options.gen
    current_roll = None

    for row in ip_reader:
        try:
            ip = proxy_filter(row[0])
            timestamp = parse(row[1])
            if current_roll is None:
                current_roll = getattr(timestamp, roll)
            elif current_roll != getattr(timestamp, roll) and\
                    getattr(timestamp, roll) % options.gen_accuracy == 0:
                current_roll = getattr(timestamp, roll)
                # print current map to file, and generate new one.
                world_map.render('%s/%s.jpg' % (configs['maps']['folder'],
                    timestamp))

            data = ip_converter.get_gps_from_ip(ip)
            if data is not None:
                world_map.add_gps_to_map(data) 
        except pygeoip.GeoIPError, error:
            logging.error(error)
        except ValueError, error:
            logging.error(error)
开发者ID:maraca,项目名称:mapdem,代码行数:39,代码来源:main.py

示例4: Game

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import render [as 别名]
class Game():
    def __init__(self, title, window_size):
        self.title = title
        self.window_size = window_size

        pygame.init()
        self.window = pygame.display.set_mode(self.window_size)
        pygame.display.set_caption(self.title)
        self.clock = pygame.time.Clock()

        self.world = Map()
        self.player = Player(32, 32, (255, 85, 85), self.world)

    def update(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        self.player.update()
        self.world.update(self.player)

    def render(self):
        pygame.display.set_caption('Survival - FPS: %d' % self.clock.get_fps())
        self.window.fill((0, 0, 0))

        self.world.render(self.window)

        self.player.render(self.window)

        pygame.display.update()
        self.clock.tick(30)

    def gameloop(self):
        while True:
            self.update()
            self.render()
开发者ID:o0kot0o,项目名称:SurvivalGame,代码行数:39,代码来源:game.py

示例5: __init__

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import render [as 别名]
class App:

    def __init__(self, name=None):
        self._running = True
        self._display_surf = None
        self.size = self.weight, self.height = 640, 480
        self.name = name or 'pw19'
        self.assets = Assets()
        self._map = Map()
        debug('main init done')
 
    def on_init(self):
        debug('on_init started')
        pygame.init()

        self.assets.load_all()
    
        # load icon and set it
        # icon = pygame.image.load(os.path.join('.', 'afuckingbeachballright_icon.png'))
                
        pygame.display.set_icon(self.assets['application_icon'])
        pygame.display.set_caption(self.name)

        self._surf = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
        self._running = True
        debug('on_init done')
    
    def test(self):
        debug('test started')
        # just a method in which I test some code :)
        self._surf.fill(Color('white'))
        pygame.draw.rect(self._surf, Color('black') , Rect(9,9,322+16,242), 1)
        pygame.display.flip()
        
        time.sleep(0.1) # I want to see the process... :)
        
        map = self._surf.subsurface(Rect(10,10,320+16,240))
        map.fill(Color('grey'))
        pygame.display.flip()
        
        time.sleep(0.1) # I want to see the process... :)        
        map.blit(self.assets['tile1'], (10,10))
        pygame.display.flip()
        
        time.sleep(0.1) # I want to see the process... :)        
        map.blit(self.assets['tile1'], (-5,-5))     
        map.blit(self.assets['tile1'], (355,235))
        pygame.display.flip()
        
        pool = ['tile1', 'tile2', 'tile3', 'tile4']
        map_height = 32
        map_width = 32
        
        random_map = [[random.choice(pool) for i in xrange(map_width)] for j in xrange(map_height)]        
        random_i = [[random.randint(0,6) for i in xrange(map_width)] for j in xrange(map_height)]        
        scroll_x = 0
        scroll_y = 0        
        for ix in xrange(map_width):
            for iy in xrange(map_height):
                offset_x = ix * 16 + scroll_x
                offset_y = iy * 16 + scroll_y
                map.blit(self.assets[random_map[iy][ix]], (offset_x,offset_y))
                if random_i[iy][ix] == 0:
                    map.blit(self.assets['chair'], (offset_x,offset_y))
        pygame.display.flip()
        
        time.sleep(0.5)
        
        self.map_area = map
        self._map.set_viewport(self.map_area)
        self._map.set_assets(self.assets)
        self._map.generate_random_map()
        self.map_area.fill(Color('white'))
        self._map.render()
        
        
                
                
        
        
        
        debug('test done')
        
 
    def on_event(self, event):
        if event.type == pygame.QUIT:
            self._quit()
        elif event.type == pygame.KEYDOWN:
            if event.unicode == u'q' and (pygame.KMOD_META & event.mod):
                self._quit()

    def on_loop(self):
        pass

    def on_render(self):
        pass

    def on_cleanup(self):
        pygame.quit()
 
#.........这里部分代码省略.........
开发者ID:SafPlusPlus,项目名称:pyweek19,代码行数:103,代码来源:__main__.py

示例6: Game

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import render [as 别名]
class Game(object):

  width = 50
  height = 40
  max_room_monsters = 3

  def __init__(self):
    self.__state = 'playing'
    self.__recompute_fov = True

  def setup(self):
    libtcod.console_set_custom_font('assets/dejavu16x16_gs_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(self.width, self.height, 'Pyrl', False)
    self.__con = libtcod.console_new(self.width, self.height)
    self.__map = Map(self.width, self.height, self.__con)
    self.__map.setup()
    self.__generate_entities()

  def __generate_entities(self):
    player_x, player_y = self.__map.rooms[0].center()
    self.__player = self.__create_entity(player_x, player_y, '@', 'player', libtcod.white, True, Fighter(hp=30, power=5, defense=2, on_death=self.__player_death))
    self.__generate_monsters()

  def __generate_monsters(self):
    for room in self.__map.rooms:
      num_monsters = libtcod.random_get_int(0, 0, self.max_room_monsters)
      for i in xrange(num_monsters):
        x = libtcod.random_get_int(0, room.x1, room.x2)
        y = libtcod.random_get_int(0, room.y1, room.y2)
        if Entity.has_blocker(x, y):
          continue
        if libtcod.random_get_int(0, 0, 1) == 0:
          self.__create_entity(x, y, 'g', 'goblin', libtcod.desaturated_amber, True, Fighter(hp=12, power=2, defense=1, on_death=monster_death), BasicMonster())
        else:
          self.__create_entity(x, y, 'k', 'kobold', libtcod.light_green, True, Fighter(hp=10, power=4, defense=0, on_death=monster_death), BasicMonster())

  def __create_entity(self, x, y, char, name, color, blocks=False, fighter=None, ai=None):
    return Entity.create(x, y, char, name, color, self.__con, self.__map, blocks, fighter, ai)

  def main_loop(self):
    while not libtcod.console_is_window_closed():
      self.__render_all()
      libtcod.console_flush()
      self.__clear_all()

      action = self.__handle_keys()
      if action == 'exit':
        break
      elif self.__state == 'playing' and action != 'pass':
        for entity in Entity.entities:
          if entity.ai:
            entity.ai.take_turn()

  def __render_all(self):
    if self.__recompute_fov:
      self.__recompute_fov = False
      self.__map.compute_fov(self.__player.x, self.__player.y)

    self.__map.render()

    for entity in Entity.entities:
      if entity.name != 'player':
        entity.draw()
    self.__player.draw()

    libtcod.console_blit(self.__con, 0, 0, self.width, self.height, 0, 0, 0)

  def __clear_all(self):
    for entity in Entity.entities:
      entity.clear()

  def __handle_keys(self):
    key = libtcod.console_wait_for_keypress(True)
    if key.vk == libtcod.KEY_ESCAPE:
      return 'exit'
    if self.__state == 'playing':
      if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        self.__player.move_or_attack(0, -1)
        self.__recompute_fov = True
      elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        self.__player.move_or_attack(0, 1)
        self.__recompute_fov = True
      elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        self.__player.move_or_attack(-1 ,0)
        self.__recompute_fov = True
      elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        self.__player.move_or_attack(1, 0)
        self.__recompute_fov = True
      else:
        return 'pass'

  def __player_death(self, player):
    self.__state = 'game-over'
    print 'You died!'
    player.char = '%'
    player.color = libtcod.dark_red
开发者ID:jimperio,项目名称:pyrl,代码行数:98,代码来源:game.py


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