本文整理汇总了Python中track.Track.coordinates方法的典型用法代码示例。如果您正苦于以下问题:Python Track.coordinates方法的具体用法?Python Track.coordinates怎么用?Python Track.coordinates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类track.Track
的用法示例。
在下文中一共展示了Track.coordinates方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Level
# 需要导入模块: from track import Track [as 别名]
# 或者: from track.Track import coordinates [as 别名]
class Level():
def __init__(self, width, height):
self.controls = None
self.round_manager = RoundManager(self)
self.ui_font = font.Font("./fonts/FreeSansBold.ttf", 12)
self.round_label_font = font.Font("./fonts/FreeSansBold.ttf", 20)
self.mouse_position = (0, 0)
self.placing_tower = False
self.selected_place_tower = build_tower(self, BALLISTA_TOWER)
self.selected_active_tower = None
self.ui_tower_image = build_tower(self, BALLISTA_TOWER).image
self.generate_tower_placement_sprite()
self.tower_select_index = 0
self.money = 20000
self.lives = 50
self.start_tile = 16, 16
self.width, self.height = width, height
self.entities = pygame.sprite.Group()
self.towers = pygame.sprite.Group()
self.projectiles = pygame.sprite.Group()
self.explosions = pygame.sprite.Group()
total_level_width = width*16
total_level_height = height*16
self.generate_background_image()
self.track = Track()
self.camera = Camera(complex_camera, total_level_width, total_level_height)
def generate_background_image(self):
self.background_image = Surface((WIN_WIDTH, WIN_HEIGHT))
self.background_image.fill(DEFAULT_BACKGROUND_COLOR)
def generate_tower_placement_sprite(self):
self.tower_placement_sprite = pygame.sprite.Sprite()
if not self.selected_place_tower: return
self.tower_placement_sprite.image = self.selected_place_tower.image #self.placing_tower.image
self.tower_placement_sprite.mask = pygame.mask.from_surface(self.selected_place_tower.image)
def add_entity(self, entity):
x, y = self.track.coordinates(0)
entity.set_coordinates(x, y)
self.entities.add(entity)
def lose_game(self):
raise(SystemExit, "GAME OVER")
def update(self, screen):
screen.blit(self.background_image, ( 0, 0 ))
screen.blit(self.track.image, ( 0, 0))
self.update_towers(screen)
if self.round_manager.round_active:
self.round_manager.update()
self.update_entities(screen)
self.update_projectiles(screen)
self.update_explosions(screen)
self.update_tower_placement(screen)
self.update_ui(screen)
self.update_round_label(screen)
def update_towers(self, screen):
for t in self.towers:
if t.stun_counter <= 0: t.update(self, screen)
else: t.stun_counter -= 1
screen.blit(t.image, (t.rect.left, t.rect.top))
def update_entities(self, screen):
for e in self.entities:
e.update(self.track)
screen.blit(e.image, (e.rect.left, e.rect.top))
x, y = e.rect.center
if x < -1*MAX_OUTSIDE_DISTANCE or x > WIN_WIDTH + MAX_OUTSIDE_DISTANCE or y < -1*MAX_OUTSIDE_DISTANCE or y > WIN_HEIGHT + MAX_OUTSIDE_DISTANCE:
self.lives -= e.damage
if self.lives <= 0: self.lose_game()
self.remove_entity(e)
def update_projectiles(self, screen):
for p in self.projectiles:
if p.rect.right < 0 or p.rect.left > WIN_WIDTH or p.rect.bottom < 0 or p.rect.top > WIN_HEIGHT:
self.remove_projectile(p)
return
screen.blit(p.image, (p.rect.left, p.rect.top))
p.rect.left += p.xvel
p.rect.top += p.yvel
for e in self.entities:
if pygame.sprite.collide_mask(p, e): p.collide_with(e)
def update_explosions(self, screen):
for x in self.explosions:
screen.blit(x.image, (x.rect.left, x.rect.top))
x.update(self)
for e in self.entities:
if pygame.sprite.collide_mask(x, e): x.collide_with(e)
def update_tower_placement(self, screen):
if not self.placing_tower: return
width, height = self.selected_place_tower.rect.width/2, self.selected_place_tower.rect.height/2
screen.blit(self.selected_place_tower.transparent_image, (self.mouse_position[0] - width, self.mouse_position[1] - height))
radius = self.selected_place_tower.range
if radius <= 0: return
self.draw_range_circle(screen, radius)
#.........这里部分代码省略.........