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


Python Tile.draw_foreground方法代码示例

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


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

示例1: TileMap

# 需要导入模块: from tile import Tile [as 别名]
# 或者: from tile.Tile import draw_foreground [as 别名]
class TileMap():
    height = 12
    width = 12
    BLOCK_SIZE = (60, 60)
    TILE_UP = -1
    TILE_DOWN = -2
    TILE_LEFT = -1
    TILE_RIGHT = -2

    def __init__(self, filename):
        self.x = 0
        self.y = 0
        self.save_path = filename
        self.load()
        mapdata = json.loads(open(MAPS_DIR + 'main_map.json').read())
        self.tilemapping = map(None, *mapdata["map"])
        self.tile = Tile(self.save_path, self.tilemapping[self.x][self.y])

    def save(self, player):
        self.tile.save()
        player.save(self.save_path)
        with open('{0}current_tile.json'.format(self.save_path), 'w') as f:
            f.write(json.dumps(self.to_json()))

    def load(self):
        with open('{0}current_tile.json'.format(self.save_path), 'r') as f:
            data = json.loads(f.read())
            self.x = data['x']
            self.y = data['y']

    def to_json(self):
        json = {'x': self.x, 'y': self.y}
        return json

    def set_tile(self, player, x, y):
        self.x = x
        self.y = y
        self.save(player)
        self.tile = Tile(self.save_path, self.tilemapping[self.x][self.y], TileMap.BLOCK_SIZE)


    def update(self, player, enemy_group):
        
        (px, py) = player.isOutOfBounds(
            self.width, 
            self.height, 
            TileMap.TILE_LEFT, 
            TileMap.TILE_RIGHT, 
            TileMap.TILE_UP, 
            TileMap.TILE_DOWN
        )

        for enemy in enemy_group:
            enemy.isOutOfBounds(
                self.width,
                self.height,
                TileMap.TILE_LEFT,
                TileMap.TILE_RIGHT,
                TileMap.TILE_UP,
                TileMap.TILE_DOWN
            )

        if (px == TileMap.TILE_LEFT and self.x - 1 >= 0 and self.tilemapping[self.x-1][self.y]):
            self.x -= 1
            self.save(player)
            self.tile = Tile(self.save_path, self.tilemapping[self.x][self.y])
            player.coords = (self.width-1, py)
            return False
        elif (px == TileMap.TILE_RIGHT and self.x + 1 < len(self.tilemapping) and self.tilemapping[self.x+1][self.y]):
            self.x += 1
            self.save(player)
            self.tile = Tile(self.save_path, self.tilemapping[self.x][self.y])
            player.coords = (0, py)
            return False
        
        if (py == TileMap.TILE_UP and self.y - 1 >= 0 and self.tilemapping[self.x][self.y-1]):
            self.y -= 1
            self.save(player)
            self.tile = Tile(self.save_path, self.tilemapping[self.x][self.y])
            player.coords = (px, self.height-1)
            return False
        elif (py == TileMap.TILE_DOWN and self.y + 1 < len(self.tilemapping[self.x]) and self.tilemapping[self.x][self.y+1]):
            self.y += 1
            self.save(player)
            self.tile = Tile(self.save_path, self.tilemapping[self.x][self.y])
            player.coords = (px, 0)
            return False
        
        return True

    def draw(self, surface):
        self.tile.draw_background(surface)
        self.tile.draw_foreground(surface)
        self.tile.draw_top(surface)
开发者ID:nhandler,项目名称:cs429,代码行数:96,代码来源:tileMap.py


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