def draw(self, screen, area, focus): if not self.app.displaySettings.showObstacles: return from trosnoth.model.obstacles import Obstacle, Corner player = self.universe.universe.getPlayer(globaldebug.localPlayerId) attachedObstacle = player.attachedObstacle if player else None worldRect = viewRectToMap(focus, area) for block in getBlocksInRect(self.universe, worldRect): for obs in block.defn.obstacles: if isinstance(obs, Obstacle): pt1 = mapPosToScreen(obs.pt1, focus, area) pt2 = mapPosToScreen(obs.pt2, focus, area) c = (0, 255, 0) if obs is attachedObstacle else (255, 0, 0) pygame.draw.line(screen, c, pt1, pt2, 2) elif isinstance(obs, Corner): pt1 = mapPosToScreen( [obs.pt[i] - obs.offset[i] * 10 for i in (0, 1)], focus, area) pt2 = mapPosToScreen([ obs.pt[i] - (obs.offset[i] + obs.delta[i]) * 10 for i in (0, 1) ], focus, area) c = (0 if obs is attachedObstacle else 255, 255, 0) pygame.draw.line(screen, c, pt1, pt2, 2) pt2 = (int(pt2[0]), int(pt2[1])) pygame.draw.circle(screen, c, pt2, 3, 0)
def draw(self, screen, area, focus): worldRect = viewRectToMap(focus, area) regions = [] for block in getBlocksInRect(self.universe, worldRect): bd = block.defn pos = mapPosToScreen(bd.pos, focus, area) if bd.kind in ('top', 'btm'): if bd.zone is None: regions.append(pygame.Rect(pos, BODY_BLOCK_SCREEN_SIZE)) continue elif bd.zone1 is None or bd.zone2 is None: regions.append(pygame.Rect(pos, INTERFACE_BLOCK_SCREEN_SIZE)) continue x0, y0 = mapPosToScreen((0, 0), focus, area) if area.top < y0: r = pygame.Rect(area) r.bottom = y0 regions.append(r) if area.left < x0: r = pygame.Rect(area) r.right = x0 regions.append(r) x1, y1 = mapPosToScreen(self.universe.map.layout.worldSize, focus, area) if area.bottom > y1: r = pygame.Rect(area) r.top = y1 regions.append(r) if area.right > x1: r = pygame.Rect(area) r.left = x1 regions.append(r) clip = screen.get_clip() for region in regions: region = region.clip(clip) screen.set_clip(region) self.drawRegion(screen, region, worldRect.topleft) screen.set_clip(clip)
def drawShiftingBackground(self, screen, area, focus, trosballLocation): worldRect = viewRectToMap(focus, area) for block in getBlocksInRect(self.universe, worldRect): blueBlock = self.bkgCache.getForTeam(0, block) redBlock = self.bkgCache.getForTeam(1, block) if blueBlock is None or redBlock is None: continue blockHorizontalPosition = block.defn.pos[0] relativeLocation = trosballLocation - blockHorizontalPosition blockWidth = block.defn.rect.width relativeLocation = max(0, min(blockWidth, relativeLocation)) x = int(relativeLocation * MAP_TO_SCREEN_SCALE + 0.5) topleft = mapPosToScreen(block.defn.pos, focus, area) r = blueBlock.get_rect() r.width = x screen.blit(blueBlock, topleft, r) r = redBlock.get_rect() r.left = x screen.blit(redBlock, (topleft[0] + x, topleft[1]), r)
def drawStandardBackground(self, screen, area, focus): worldRect = viewRectToMap(focus, area) for block in getBlocksInRect(self.universe, worldRect): pic = self.bkgCache.get(block) if pic is not None: screen.blit(pic, mapPosToScreen(block.defn.pos, focus, area))