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


Python Transform.update_viewport方法代码示例

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


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

示例1: ClientCommander

# 需要导入模块: from transform import Transform [as 别名]
# 或者: from transform.Transform import update_viewport [as 别名]
class ClientCommander(Character):
    def __init__(self, screen, server_commander):
        super(Character, self).__init__()
        self.screen = screen
        self.t = Transform(screen, (0, 100, 0, 100))
        self.server_commander = server_commander

    def key_control(self, key, event):
        Character.key_control(self, key, event)
        # Custom comamnder control

    def mouse_control(self, mouse_pos):
        pass

    def click_control(self, mouse_pos, button):
        removed = False
        wp = self.t.inv_transform_coord(mouse_pos)
        for waypoint in self.server_commander.waypoints:
            if dist(waypoint[0], waypoint[1], wp[0], wp[1]) < 0.25:
                self.server_commander.rmwp(waypoint[0], waypoint[1])
                removed = True
                break
        if not removed:
            self.server_commander.addwp(wp[0], wp[1])

    def update(self, game_map):
        pass

    def draw(self, game_map):
        self.t.update_viewport((0, game_map.rows, 0, game_map.cols))
        draw_bg(self.screen, self.t)
        draw_walls(self.screen, self.t, game_map)
        draw_hero(self.screen, self.t, game_map)
        draw_units(self.screen, self.t, game_map)
        draw_bullets(self.screen, self.t, game_map)
        draw_waypoints(self.screen, self.t, game_map)
        draw_letterbox(self.screen, self.t)
开发者ID:jerrywu64,项目名称:HeroRTS,代码行数:39,代码来源:client_commander.py

示例2: ClientHero

# 需要导入模块: from transform import Transform [as 别名]
# 或者: from transform.Transform import update_viewport [as 别名]
class ClientHero(Character):
    VIEW_SQ_RADIUS = 5.0
    def __init__(self, screen, server_hero):
        """
        screen: PyGame Surface object.
        t: Transform object to convert game coords to screen coords.
        server_hero: Temp reference to server hero object...
        """
        super(Character, self).__init__()
        self.screen = screen
        self.t = Transform(screen, (0, ClientHero.VIEW_SQ_RADIUS*2,
                                    0, ClientHero.VIEW_SQ_RADIUS*2))
        self.server_hero = server_hero
        self.vel = (0, 0)
        self.firing = False
        self.fired = False
        self.font = pygame.font.SysFont("monospace", 24)

    def key_control(self, key, event):
        Character.key_control(self, key, event)
        # Custom hero control
        if (key == pygame.K_w):
            if event == pygame.KEYDOWN:
                self.vel = (self.vel[0], self.vel[1]-1)
            elif event == pygame.KEYUP:
                self.vel = (self.vel[0], self.vel[1]+1)
        elif (key == pygame.K_s):
            if event == pygame.KEYDOWN:
                self.vel = (self.vel[0], self.vel[1]+1)
            elif event == pygame.KEYUP:
                self.vel = (self.vel[0], self.vel[1]-1)
        elif (key == pygame.K_a):
            if event == pygame.KEYDOWN:
                self.vel = (self.vel[0]-1, self.vel[1])
            elif event == pygame.KEYUP:
                self.vel = (self.vel[0]+1, self.vel[1])
        elif (key == pygame.K_d):
            if event == pygame.KEYDOWN:
                self.vel = (self.vel[0]+1, self.vel[1])
            elif event == pygame.KEYUP:
                self.vel = (self.vel[0]-1, self.vel[1])
        elif (key == pygame.K_SPACE):
            if event == pygame.KEYDOWN:
                self.firing = True
            elif event == pygame.KEYUP:
                self.firing = False

    def mouse_control(self, mouse_pos):
        # Mouse control assumes character is in the center of the screen
        delta_x = mouse_pos[0] - (self.screen.get_width()/2.0)
        delta_y = mouse_pos[1] - (self.screen.get_height()/2.0)
        self.server_hero.orientation = math.atan2(-delta_y, delta_x)

    def update(self, game_map):
        # Set direction
        if self.vel == (1, 0):
            direction = 0
        elif self.vel == (1, -1):
            direction = 1
        elif self.vel == (0, -1):
            direction = 2
        elif self.vel == (-1, -1):
            direction = 3
        elif self.vel == (-1, 0):
            direction = 4
        elif self.vel == (-1, 1):
            direction = 5
        elif self.vel == (0, 1):
            direction = 6
        elif self.vel == (1, 1):
            direction = 7
        else:
            direction = -1
        self.server_hero.move(direction, game_map)

        if self.firing:
            self.firing = False
            self.fired = True
            b = self.server_hero.make_bullet(game_map)
            if b is not None: game_map.bullets.append(b)

    def draw(self, game_map):
        if self.server_hero.dead:
            # Death!!
            self.screen.fill((230, 0, 0))
            label = self.font.render("Whoops. Ate too many bullets. Nom.", 1, (100, 0, 0))
            self.screen.blit(label, ((self.screen.get_width()-label.get_width())/2.0,
                                     self.screen.get_height()/2.0))
            return

        self.t.update_viewport((self.server_hero.location[1] - ClientHero.VIEW_SQ_RADIUS,
                                self.server_hero.location[1] + ClientHero.VIEW_SQ_RADIUS,
                                self.server_hero.location[0] - ClientHero.VIEW_SQ_RADIUS,
                                self.server_hero.location[0] + ClientHero.VIEW_SQ_RADIUS))
        draw_bg(self.screen, self.t)
        draw_walls(self.screen, self.t, game_map)
        draw_hero(self.screen, self.t, game_map)
        draw_units(self.screen, self.t, game_map)
        draw_bullets(self.screen, self.t, game_map)
        draw_fow(self.screen, self.t, game_map)
#.........这里部分代码省略.........
开发者ID:jerrywu64,项目名称:HeroRTS,代码行数:103,代码来源:client_hero.py


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