def render(self, screen): cursortile = terrain.nearesttile(self.you.x, self.you.y) worldmap.drawscene(screen, self.structures + self.sprites, (self.you.x, self.you.y)) if settings.showminimap: worldmap.drawminimap(screen, [self.you]) ax, ay = terrain.toModel(*cursortile) screen.blit(get_text("Position: %s %s" % (int(ax//1), int(ay//1)), (255, 0, 0), 18), (4, settings.sy-22))
def render(self, screen): cursortile = terrain.nearesttile(self.you.x, self.you.y) worldmap.drawscene(screen, self.structures + self.sprites, (self.you.x, self.you.y)) if settings.showminimap: worldmap.drawminimap(screen, [self.you]) ax, ay = terrain.toModel(*cursortile) screen.blit( get_text("Position: %s %s" % (int(ax // 1), int(ay // 1)), (255, 0, 0), 18), (4, settings.sy - 22))
def highlighttile(surf, x, y, looker=None): x, y = terrain.nearesttile(x, y) h, h0, (gx, gy), ps = terrain.tileinfo(x, y, looker) x0, x1 = min(x for x,y in ps), max(x for x,y in ps) y0, y1 = min(y for x,y in ps), max(y for x,y in ps) s = pygame.Surface(((x1-x0+1), (y1-y0+1))).convert_alpha() s.fill((0,0,0,0)) ps = [(x-x0,y-y0) for x,y in ps] pygame.draw.polygon(s, (255, 0, 0, 50), ps) # pygame.draw.lines(s, (255, 0, 0, 100), True, ps, 1) surf.blit(s, (x0,y0))
def deploy(self, scene, target, btype): X0, Y0 = terrain.toModel(target.x, target.y) #print self.hq.x, self.hq.y, X0, Y0, X0 - Y0, -X0 - Y0 r = 3 while True: theta = random.random() * 1000 X = int((X0 + r * math.sin(theta))//1) Y = int((Y0 + r * math.cos(theta))//1) x, y = terrain.nearesttile(X - Y, -X - Y) if not terrain.isunderwater(x, y) and not self.border.iswithin(x, y): break r += 0.2 alien = btype(X, Y) alien.settarget(target) self.attackers.append(alien)
def deploy(self, scene, target, btype): X0, Y0 = terrain.toModel(target.x, target.y) #print self.hq.x, self.hq.y, X0, Y0, X0 - Y0, -X0 - Y0 r = 3 while True: theta = random.random() * 1000 X = int((X0 + r * math.sin(theta)) // 1) Y = int((Y0 + r * math.cos(theta)) // 1) x, y = terrain.nearesttile(X - Y, -X - Y) if not terrain.isunderwater(x, y) and not self.border.iswithin( x, y): break r += 0.2 alien = btype(X, Y) alien.settarget(target) self.attackers.append(alien)
def drawfadinggrid(surf, xc, yc, r=None, looker=None): r = settings.cursorgridsize if r is None else r looker = looker or camera x0, y0 = terrain.nearesttile(xc, yc) s = pygame.Surface(surf.get_size()).convert_alpha() s.fill((0,0,0,0)) hs, ps, alphas = {}, {}, {} for dx in range(-r, r+2): for dy in range(-r, r+2): x, y = x0 - 1 + dx + dy, y0 + dx - dy h = terrain.iheight(x, y) hs[(dx,dy)] = h ps[(dx,dy)] = looker.screenpos(x, y, h) alphas[(dx,dy)] = max(int(50 * (1 - math.sqrt(((x-xc)**2 + (y-yc)**2) / (r+1)**2))), 0) for dx in range(-r, r+1): for dy in range(-r, r+2): if hs[(dx,dy)] or hs[(dx+1,dy)]: a = alphas[(dx,dy)] + alphas[(dx+1,dy)] pygame.draw.line(s, (255,255,255,a), ps[(dx,dy)], ps[(dx+1,dy)]) if hs[(dy,dx)] or hs[(dy,dx+1)]: a = alphas[(dy,dx)] + alphas[(dy,dx+1)] pygame.draw.line(s, (255,255,255,a), ps[(dy,dx)], ps[(dy,dx+1)]) surf.blit(s, (0, 0))
def __init__(self, playscene, a, b, c): self.bot_a = a self.bot_b = b self.bot_c = c self.next = self self.playscene = playscene player = self.playscene.player tx, ty = terrain.nearesttile(player.x, player.y) self.target_user = 0 self.mx, self.my = playscene.mousex, playscene.mousey self.deploy_request = None for user_id in playscene.potato.borders_by_user.keys(): bord = playscene.potato.borders_by_user[user_id] if (tx, ty) in bord.tiles: self.target_user = user_id break self.ok_button = None self.cancel_button = None self.deployed = False
def iswithin(self, x, y): return terrain.nearesttile(x,y) in self.tiles
def is_wild(self, x, y): tx, ty = terrain.nearesttile(x, y) sx, sy = terrain.toiModel(tx, ty) borders = self.potato.get_borders_near_sector(sx // 60, sy // 60) return not any(border.iswithin(tx, ty) for border in borders)
def iswithin(self, x, y): return terrain.nearesttile(x, y) in self.tiles