本文整理汇总了Python中dungeon.Dungeon.get_tile_at方法的典型用法代码示例。如果您正苦于以下问题:Python Dungeon.get_tile_at方法的具体用法?Python Dungeon.get_tile_at怎么用?Python Dungeon.get_tile_at使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dungeon.Dungeon
的用法示例。
在下文中一共展示了Dungeon.get_tile_at方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Application
# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import get_tile_at [as 别名]
class Application(object):
def __init__(self):
# Initialize ConfigParser and read settings.
config = configparser.ConfigParser()
config.read('config.ini')
self._width = int(config['Window'].get('Width', 480))
self._height = int(config['Window'].get('Height', 480))
self._quit = False
self._screen = None
self._font = None
# Initialize Pygame.
self.init_pygame((self._width, self._height))
# Initialize Dungeon.
self._dungeon = Dungeon()
# Initialize Player.
self._player = self.init_player()
def init_pygame(self, window_size):
pygame.init()
pygame.display.set_caption("Forge")
self._screen = pygame.display.set_mode(window_size)
self._font = pygame.font.SysFont("Courier New", 16)
def init_player(self):
viewport_size = screen_to_world_coords((self._width, self._height))
viewport = Viewport(self._dungeon.sloc, viewport_size)
return Player(viewport)
def start(self):
screen_center = self._screen.get_rect().center
time_step = 150
accumulated_time = 0
clock = pygame.time.Clock()
while not self._quit:
try:
dt = clock.tick(60)
accumulated_time += dt
self._screen.fill((0, 0, 0))
self._dungeon.update()
self._player.update()
self._player.calculate_visibility(self._dungeon)
self._dungeon.draw(self._screen, self._player)
self._player.draw(self._screen)
self._display_fps(int(round(clock.get_fps())))
pygame.display.flip()
for event in pygame.event.get():
if event.type == QUIT:
self._quit = True
elif event.type == KEYDOWN:
if event.key in [K_ESCAPE]:
self._quit = True
if event.key in [K_UP, K_w]:
self._player.try_move(self._dungeon, Direction.NORTH)
if event.key in [K_DOWN, K_s]:
self._player.try_move(self._dungeon, Direction.SOUTH)
if event.key in [K_LEFT, K_a]:
self._player.try_move(self._dungeon, Direction.WEST)
if event.key in [K_RIGHT, K_d]:
self._player.try_move(self._dungeon, Direction.EAST)
elif event.type == MOUSEBUTTONDOWN:
b1, b2, b3 = pygame.mouse.get_pressed()
mouse_x, mouse_y = pygame.mouse.get_pos()
mouse_pos = (mouse_x, mouse_y)
if True in [b3]:
d = get_direction(screen_center, mouse_pos)
self._player.try_move(self._dungeon, d)
if True in [b2]:
tilesize = self._dungeon.tilesize
dungeon_x = math.floor(mouse_x / tilesize) + self._player.viewport.rect.left
dungeon_y = math.floor(mouse_y / tilesize) + self._player.viewport.rect.top
t = self._dungeon.get_tile_at(dungeon_x, dungeon_y)
if t is not None:
t.onclick(self._player)
if accumulated_time >= time_step:
pk = pygame.key.get_pressed()
if True in [pk[K_RIGHT], pk[K_LEFT], pk[K_UP], pk[K_DOWN],
pk[K_d], pk[K_a], pk[K_w], pk[K_s]]:
if True in [pk[K_RIGHT], pk[K_d]]:
self._player.try_move(self._dungeon, Direction.EAST)
#.........这里部分代码省略.........