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


Python Camera.render方法代码示例

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


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

示例1: Level

# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import render [as 别名]
class Level(GameState):
    MAP_BASE = "maps"
    MAX_OFFSET_X = 150
    MAX_OFFSET_Y = 75
    FACTOR = 10

    def __init__(self, definition_path, map_path):
        self.keyCode = None
        self.definition_path = definition_path
        self.map_path = map_path
        self.tile_engine = TileEngine(
            join(Level.MAP_BASE, definition_path),
            join(Level.MAP_BASE, map_path)
        )
        self.camera = Camera(self.tile_engine, pygame.Rect(
            0, 0, Globals.WIDTH, Globals.HEIGHT))
        self.tile_rect = self.tile_engine.get_tile_rect()
        self.enemySprites = pygame.sprite.Group()
        self.playerSprites = pygame.sprite.Group()
        self.turrets = list()
        self.init_player()
        self.init_enemies()

    def handle_stairs(self):
        pass

    def handle_escape(self):
        pass

    def handle_enemy_collision(self):
        pass

    def handle_special_collision(self, pair):
        self.replace_special_tile(pair)

    def replace_special_tile(self, pair):
        if pair.tile.is_replaceable:
            row, col = self.camera.tileEngine.get_tile_pos(pair.coords[0],
                                                           pair.coords[1])
            base = self.camera.tileEngine.get_tile_from_attr(
                pair.tile.replace_attr)
            if base is None:
                base = self.camera.tileEngine.get_tile_from_attr(
                    TileType.BASE_ATTR)
            self.camera.tileEngine.tileMap[row][col] = base

    def init_player(self):
        self.player = Player(
            Globals.WIDTH, Globals.HEIGHT,
            Globals.WIDTH / 2, Globals.HEIGHT / 2
        )
        self.playerSprites.add(self.player)

    def init_enemies(self):
        tile_map = self.tile_engine.tileMap
        base_tile = self.tile_engine.get_tile_from_attr(TileType.BASE_ATTR)
        for row_num in range(0, len(tile_map)):
            for col_num in range(0, len(tile_map[row_num])):
                if tile_map[row_num][col_num] is None:
                    continue
                if TileType.SPAWN_ATTR in \
                        tile_map[row_num][col_num].special_attr:
                    self.add_enemy(row_num, col_num)
                    tile_map[row_num][col_num] = base_tile
                elif TileType.TURRET_LEFT in \
                        tile_map[row_num][col_num].special_attr:
                    self.add_turret(row_num, col_num, True)
                elif TileType.TURRET_RIGHT in \
                        tile_map[row_num][col_num].special_attr:
                    self.add_turret(row_num, col_num, False)

    def add_enemy(self, row_num, col_num):
        y = self.tile_rect.height * row_num - self.camera.viewpoint.top
        x = self.tile_rect.width * col_num - self.camera.viewpoint.left
        self.enemySprites.add(Enemy(Globals.WIDTH, Globals.HEIGHT, x=x, y=y))

    def add_turret(self, row_num, col_num, left):
        row_num += 1
        if not left:
            col_num += 1
        y = self.tile_rect.height * row_num - self.camera.viewpoint.top
        x = self.tile_rect.width * col_num - self.camera.viewpoint.left
        self.turrets.append(Turret(x, y, left))

    def check_collisions(self):
        # radius = max(self.player.rect.size) * 1.5
        # center = self.player.rect.center
        for turret in self.turrets:
            for syringe in turret.syringeSprites:
                if self.player.rect.colliderect(syringe):
                    Globals.PLAYER_HEALTH += syringe.health_effect
                    print Globals.PLAYER_HEALTH
                    syringe.kill()

    def render(self):
        self.camera.render(Globals.SCREEN)
        self.enemySprites.draw(Globals.SCREEN)
        for turret in self.turrets:
            turret.render(Globals.SCREEN)
        self.playerSprites.draw(Globals.SCREEN)
#.........这里部分代码省略.........
开发者ID:elanas,项目名称:TheCrazySix,代码行数:103,代码来源:Level.py

示例2: TileTest

# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import render [as 别名]
class TileTest(GameState):
    FACTOR = 35
    INDEX_DOWN = 0
    INDEX_UP = 1
    INDEX_LEFT = 2
    INDEX_RIGHT = 3

    NUM_ENEMY = 13
    WALL_WIDTH = 50

    def __init__(self):
        self.tileEngine = TileEngine("test_def.txt", "test_map.txt", 1, 3)
        self.camera = Camera(self.tileEngine, pygame.Rect(
            0, 0, Globals.WIDTH, Globals.HEIGHT))
        self.keyCode = None
        self.testPoint = [Globals.WIDTH / 2, int(Globals.HEIGHT -
                          self.camera.tileEngine.get_tile_rect().height * 3.5)]
        self.object_radius = \
            self.camera.tileEngine.get_tile_rect().height * 1.5
        self.direction = -1
        self.has_collided = False
        self.enemySprites = pygame.sprite.Group()
        self.playerSprites = pygame.sprite.Group()

        # for x in range(MainGame.NUM_ENEMY):
        #     self.enemySprites.add(Enemy(Globals.WIDTH, Globals.HEIGHT))
        self.playerSprites.add(Player(Globals.WIDTH, Globals.HEIGHT,
                                      self.testPoint[0], self.testPoint[1]))

    def render(self):
        self.camera.render(Globals.SCREEN)
        self.checkCollisions()
        # pygame.draw.circle(Globals.SCREEN, (255, 0, 0), self.testPoint, 6)

        # Globals.SCREEN.fill(Globals.BACKGROUND_COLOR)
        # self.enemySprites.draw(Globals.SCREEN)
        self.playerSprites.draw(Globals.SCREEN)
        # self.wallSprites.draw(Globals.SCREEN)

    def checkCollisions(self):
        solid_tiles = \
            self.camera.get_solid_tiles(self.testPoint, self.object_radius)
        solid_rects = [pair.rect for pair in solid_tiles]
        # # curr_rect = \
        # #     pygame.Rect(self.testPoint[0] - 3, self.testPoint[1] - 3, 6, 6)
        # curr_rect = self.playerSprites.get
        # for i in curr_rect.collidelistall(solid_rects):

        for p in self.playerSprites:
            curr_rect = p.rect
            for i in curr_rect.collidelistall(solid_rects):

                wall_rect = solid_rects[i]
                if self.direction == TileTest.INDEX_UP:
                    curr_rect.top = wall_rect.bottom
                    self.has_collided = True
                elif self.direction == TileTest.INDEX_DOWN:
                    curr_rect.bottom = wall_rect.top
                    self.has_collided = True
                elif self.direction == TileTest.INDEX_LEFT:
                    curr_rect.left = wall_rect.right
                    self.has_collided = True
                elif self.direction == TileTest.INDEX_RIGHT:
                    curr_rect.right = wall_rect.left
                    self.has_collided = True
                else:
                    self.has_collided = False

        self.testPoint[1] = curr_rect.top + 3
        self.testPoint[0] = curr_rect.left + 3

        special_tiles = \
            self.camera.get_special_tiles(self.testPoint,
                                          self.object_radius)
        stair_rects = [pair.rect for pair in special_tiles
                       if pair.tile.special_attr == TileType.STAIR_ATTR]
        for p in self.playerSprites:
            num_stairs = len(p.rect.collidelistall(stair_rects))
            if num_stairs > 0:
                # fix the import and this should be done
                Globals.STATE = WinGame()
                pass

    def update(self, time):
        if self.keyCode is not None:
            if self.keyCode == pygame.K_UP:
                self.direction = TileTest.INDEX_UP
                if self.has_collided:
                    self.camera.move(0, 0)
                else:
                    self.camera.move(0, -TileTest.FACTOR)
            elif self.keyCode == pygame.K_DOWN:
                self.direction = TileTest.INDEX_DOWN
                if self.has_collided:
                    self.camera.move(0, 0)
                else:
                    self.camera.move(0, TileTest.FACTOR)
            elif self.keyCode == pygame.K_LEFT:
                self.direction = TileTest.INDEX_LEFT
                if self.has_collided:
#.........这里部分代码省略.........
开发者ID:elanas,项目名称:TheCrazySix,代码行数:103,代码来源:TileTest.py

示例3: LevelEditor

# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import render [as 别名]
class LevelEditor(GameState):
    HIDDEN_ATTR = [TileType.LEVER_RIGHT_ATTR, TileType.TURRET_ATTR,
                   TileType.GREENBALL_ATTR]
    IN_GAME_HIDDEN_EXTRA = [TileType.STAIR_DOWN_ATTR, TileType.RESPAWN_ATTR]
    RIGHT_PADDING_FACTOR = 4
    PADDING = 20
    HIGHLIGHT_COLOR = (255, 0, 255)
    HIGHLIGHT_ALPHA = 100
    HIGHLIGHT_BORDER = pygame.color.Color("red")
    SELECTION_ALPHA = 255
    QUICK_TIMEOUT = 1
    MESSAGE_TIMEOUT = 2
    INFO_TIMEOUT = 6
    MESSAGE_PADDING = 10
    MESSAGE_FONT = pygame.font.Font(None, 30)
    DEFAULT_MESSAGE_COLOR = pygame.color.Color("white")
    ERROR_MESSAGE_COLOR = pygame.color.Color("red")
    MESSAGE_BACKGROUND = pygame.color.Color("black")
    TITLE_FONT = pygame.font.Font(None, 35)
    TITLE = "Tiles:"
    SECOND_TITLE = "Combos:"
    TITLE_COLOR = pygame.color.Color("white")
    COMBO_DEF_PATH = join('maps', 'combo_def.txt')
    # TURRET_RIGHT_COMBO = ''

    def __init__(self, definition_path, map_path, globals=Globals,
                 in_game=False):
        self.globals = globals
        self.actions = list()
        self.browser = None
        self.message_time = 0
        self.message_surf = None
        self.message_rect = None
        self.key_code = None
        self.mouse_down = False
        self.info_mode = False
        self.delete_mode = False
        self.in_game = in_game
        loader = AssetLoader(join("images", "tiles"))
        TileType.create_empty(loader)
        self.base_image = loader.load_image("transparent.png")
        self.base_rect = self.base_image.get_rect()
        self.definition_path = definition_path
        self.map_path = map_path
        self.tile_engine = TileEngine(self.definition_path, self.map_path)
        self.combo_tile_manager = TileManager(LevelEditor.COMBO_DEF_PATH, None)
        self.tile_rect = self.tile_engine.get_tile_rect()
        self.right_padding = self.tile_rect.width * \
            LevelEditor.RIGHT_PADDING_FACTOR
        self.shift_factor = self.tile_rect.width
        self.init_camera()
        self.init_highlight()
        self.init_title()
        self.init_browser()
        self.init_second_title()
        self.init_combo_browser()
        self.in_combo = False

    def init_title(self):
        self.title_surf = LevelEditor.TITLE_FONT.render(
            LevelEditor.TITLE, False, LevelEditor.TITLE_COLOR)
        self.title_rect = self.title_surf.get_rect()
        self.title_rect.centerx = self.camera_dest.right + \
            (self.globals.WIDTH - self.camera_dest.right) / 2
        self.title_rect.top = self.camera_dest.top

    def init_second_title(self):
        self.second_title_surf = LevelEditor.TITLE_FONT.render(
            LevelEditor.SECOND_TITLE, False, LevelEditor.TITLE_COLOR)
        self.second_title_rect = self.second_title_surf.get_rect()
        self.second_title_rect.centerx = self.camera_dest.right + \
            (self.globals.WIDTH - self.camera_dest.right) / 2
        self.second_title_rect.top = self.browser.container.bottom + 10

    def init_browser(self):
        width = (self.globals.WIDTH - self.camera_dest.right) - 20
        height = self.globals.HEIGHT - self.title_rect.height * 2 - (32 * 3)
        c = pygame.Rect(0, self.title_rect.bottom + 5, width, height)
        c.centerx = self.title_rect.centerx
        # if self.browser is not None:
        #     pygame.draw.rect(self.globals.SCREEN, (0, 0, 0), self.browser.container)
        hidden_attr = LevelEditor.HIDDEN_ATTR
        if self.in_game:
            hidden_attr.extend(LevelEditor.IN_GAME_HIDDEN_EXTRA)
        self.browser = DefinitionBrowser(self.tile_engine.tileManager,
                                         self.tile_engine.get_tile_rect(), c,
                                         hidden_attr)

    def init_combo_browser(self):
        width = self.browser.container.width
        height = self.globals.HEIGHT - self.second_title_rect.bottom - 10
        c = pygame.Rect(0, self.second_title_rect.bottom + 5, width, height)
        c.centerx = self.browser.container.centerx
        self.combo_browser = DefinitionBrowser(
            self.combo_tile_manager, self.tile_engine.get_tile_rect(),
            c)

    def init_camera(self):
        self.camera_dest = pygame.Rect(
            LevelEditor.PADDING, LevelEditor.PADDING, self.globals.WIDTH -
#.........这里部分代码省略.........
开发者ID:elanas,项目名称:TheCrazySix,代码行数:103,代码来源:LevelEditor.py


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