def _display(self): # map borders draw_rect((100, 100, 100), (0, 0, self.square_view_width * (self.interface.xcmax + 1), self.square_view_height * (self.interface.ycmax + 1)), 1) # backgrounds squares_to_view = [] for xc in range(0, self.interface.xcmax + 1): for yc in range(0, self.interface.ycmax + 1): sq = self.interface.server.player.world.grid[(xc, yc)] if sq in self.interface.server.player.detected_squares: color = (0, 25, 25) elif sq in self.interface.server.player.observed_squares: color = (0, 25, 0) elif sq in self.interface.server.player.observed_before_squares: color = (15, 15, 15) else: color = (0, 0, 0) continue if sq.high_ground: color = (color[0] * 2, color[1] * 2, color[2] * 2) draw_rect(color, self._get_rect_from_map_coords(xc, yc)) squares_to_view.append(sq) # walls for sq in squares_to_view: exits = set([e.o for e in sq.exits if not e.is_blocked()]) walls = set([-90, 90, 180, 0]) - exits x, y = self._xy_coords(sq.x, sq.y) for color, borders in (((100, 100, 100), walls), ((0, 0, 0), exits)): for o in borders: dx = cos(radians(o)) * self.square_view_width / 2 dy = -sin(radians(o)) * self.square_view_width / 2 draw_line(color, (x - dx - dy, y - dy - dx), (x - dx + dy, y - dy + dx))
def display(self, grid): xmin, ymin = grid.xy_coords(self.xmin, self.ymin) xmax, ymax = grid.xy_coords(self.xmax, self.ymax) if self.parent.target is None: color = (255, 255, 255) else: color = (150, 150, 150) draw_rect(color, xmin, ymin, xmax - xmin, ymax - ymin, 1)
def active_square_view_display(self): xc, yc = self.interface.coords_in_map(self.interface.place) x, y = xc * self.square_view_width, self.ymax - yc * self.square_view_height if self.interface.target is None: color = (255, 255, 255) else: color = (150, 150, 150) draw_rect(color, x, y - self.square_view_height, self.square_view_width, self.square_view_height, 1)
def _display_active_zone_border(self): if self.interface.zoom_mode: zoom = self.interface.zoom xmin, ymin = self._xy_coords(zoom.xmin, zoom.ymin) xmax, ymax = self._xy_coords(zoom.xmax, zoom.ymax) rect = xmin, ymin, xmax - xmin, ymax - ymin else: rect = self._get_rect_from_map_coords(*self.interface.coords_in_map(self.interface.place)) rect = list(rect) rect[0] += 3 rect[1] += 3 rect[2] -= 6 rect[3] -= 6 if self.interface.target is None: color = (255, 255, 255) else: color = (150, 150, 150) draw_rect(color, rect, 1)
def _display_active_zone_border(self): if self.interface.zoom_mode: zoom = self.interface.zoom xmin, ymin = self._xy_coords(zoom.xmin, zoom.ymin) xmax, ymax = self._xy_coords(zoom.xmax, zoom.ymax) rect = xmin, ymin, xmax - xmin, ymax - ymin else: rect = self._get_rect_from_map_coords( *self.interface.coords_in_map(self.interface.place)) rect = list(rect) rect[0] += 3 rect[1] += 3 rect[2] -= 6 rect[3] -= 6 if self.interface.target is None: color = (255, 255, 255) else: color = (150, 150, 150) draw_rect(color, rect, 1)
def display_object(self, o): if getattr(o, "is_inside", False): return if self.interface.target is not None and self.interface.target is o: width = 0 # fill circle else: width = 1 x, y = self._object_coords(o) if o.shape() == "square": rect = x - R, y - R, R * 2, R * 2 draw_rect(o.corrected_color(), rect, width) else: pygame.draw.circle(get_screen(), o.corrected_color(), (x, y), R, width) if getattr(o.model, "player", None) is not None: if o.id in self.interface.group: color = (0, 255, 0) elif o.player is self.interface.player: color = (0, 55, 0) elif o.player in self.interface.player.allied: color = (0, 0, 155) elif o.player.is_an_enemy(self.interface.player): color = (155, 0, 0) else: color = (0, 0, 0) pygame.draw.circle(get_screen(), color, (x, y), R / 2, 0) if getattr(o, "hp", None) is not None and \ o.hp != o.hp_max: hp_prop = 100 * o.hp / o.hp_max if hp_prop > 80: color = (0, 255, 0) ## elif hp_prop > 50: ## color = (0, 255, 0) else: color = (255, 0, 0) W = R - 2 if color != (0, 255, 0): pygame.draw.line(get_screen(), (0, 55, 0), (x - W, y - R - 2), (x - W + 2 * W, y - R - 2)) pygame.draw.line(get_screen(), color, (x - W, y - R - 2), (x - W + hp_prop * (2 * W) / 100, y - R - 2))
def display_object(self, o): if getattr(o, "is_inside", False): return if self.interface.target is not None and self.interface.target is o: width = 0 # fill circle else: width = 1 x, y = self._object_coords(o) if o.shape() == "square": rect = x-R, y-R, R*2, R*2 draw_rect(o.corrected_color(), rect, width) else: pygame.draw.circle(get_screen(), o.corrected_color(), (x, y), R, width) if getattr(o.model, "player", None) is not None: if o.id in self.interface.group: color = (0,255,0) elif o.player is self.interface.player: color = (0,55,0) elif o.player in self.interface.player.allied: color = (0,0,155) elif o.player.player_is_an_enemy(self.interface.player): color = (155,0,0) else: color = (0, 0, 0) pygame.draw.circle(get_screen(), color, (x, y), R/2, 0) if getattr(o, "hp", None) is not None and \ o.hp != o.hp_max: hp_prop = 100 * o.hp / o.hp_max if hp_prop > 80: color = (0, 255, 0) ## elif hp_prop > 50: ## color = (0, 255, 0) else: color = (255, 0, 0) W = R - 2 if color != (0, 255, 0): pygame.draw.line(get_screen(), (0, 55, 0), (x - W, y - R - 2), (x - W + 2 * W, y - R - 2)) pygame.draw.line(get_screen(), color, (x - W, y - R - 2), (x - W + hp_prop * (2 * W) / 100, y - R - 2))
def _display(self): # map borders draw_rect((100, 100, 100), (0, 0, self.square_view_width * (self.interface.xcmax + 1), self.square_view_height * (self.interface.ycmax + 1)), 1) # backgrounds squares_to_view = [] for xc in range(0, self.interface.xcmax + 1): for yc in range(0, self.interface.ycmax + 1): sq = self.interface.server.player.world.grid[(xc, yc)] color = style.get(sq.type_name, "color", warn_if_not_found=False) try: color = pygame.Color(color[0]) except: color = (0, 25, 0) if sq.high_ground: color = (color[0] * 2, color[1] * 2, color[2] * 2) if sq in self.interface.server.player.observed_before_squares \ and sq not in self.interface.server.player.observed_squares: color = (color[0] / 10 + 15, color[1] / 10 + 15, color[2] / 10 + 15) elif sq not in self.interface.server.player.observed_squares: color = (0, 0, 0) continue color = map(lambda x: min(x, 255), color) draw_rect(color, self._get_rect_from_map_coords(xc, yc)) squares_to_view.append(sq) # walls for sq in squares_to_view: exits = set([e.o for e in sq.exits if not e.is_blocked()]) walls = set([-90, 90, 180, 0]) - exits x, y = self._xy_coords(sq.x, sq.y) for color, borders in (((100, 100, 100), walls), ((0, 0, 0), exits)): for o in borders: dx = cos(radians(o)) * self.square_view_width / 2 dy = -sin(radians(o)) * self.square_view_width / 2 draw_line(color, (x - dx - dy, y - dy - dx), (x - dx + dy, y - dy + dx))
def _display(self): # map borders draw_rect((100, 100 ,100), (0, 0, self.square_view_width * (self.interface.xcmax + 1), self.square_view_height * (self.interface.ycmax + 1)), 1) # backgrounds squares_to_view = [] for xc in range(0, self.interface.xcmax + 1): for yc in range(0, self.interface.ycmax + 1): sq = self.interface.server.player.world.grid[(xc, yc)] color = style.get(sq.type_name, "color", warn_if_not_found=False) try: color = pygame.Color(color[0]) except: color = (0, 25, 0) if sq.high_ground: color = (color[0]*2, color[1]*2, color[2]*2) if sq in self.interface.server.player.observed_before_squares \ and sq not in self.interface.server.player.observed_squares: color = (color[0]/10 + 15, color[1]/10 + 15, color[2]/10 + 15) elif sq not in self.interface.server.player.observed_squares: color = (0, 0, 0) continue color = map(lambda x: min(x, 255), color) draw_rect(color, self._get_rect_from_map_coords(xc, yc)) squares_to_view.append(sq) # walls for sq in squares_to_view: exits = set([e.o for e in sq.exits if not e.is_blocked()]) walls = set([-90, 90, 180, 0]) - exits x, y = self._xy_coords(sq.x, sq.y) for color, borders in (((100, 100, 100), walls), ((0, 0, 0), exits)): for o in borders: dx = cos(radians(o)) * self.square_view_width / 2 dy = - sin(radians(o)) * self.square_view_width / 2 draw_line(color, (x - dx - dy, y - dy - dx), (x - dx + dy, y - dy + dx))
def _display(self): # backgrounds for xc in range(0, self.interface.xcmax + 1): for yc in range(0, self.interface.ycmax + 1): sq = self.interface.server.player.world.grid[(xc, yc)] x, y = xc * self.square_view_width, self.ymax - yc * self.square_view_height if sq in self.interface.server.player.detected_squares: color = (0, 25, 25) elif sq in self.interface.server.player.observed_squares: color = (0, 25, 0) elif sq in self.interface.server.player.observed_before_squares: color = (15, 15, 15) else: color = (0, 0, 0) continue if sq.high_ground: color = (color[0]*2, color[1]*2, color[2]*2) draw_rect(color, x, y - self.square_view_height, self.square_view_width, self.square_view_height, 0) # grid color = (100, 100, 100) for x in range(0, self.interface.xcmax + 2): draw_line(color, (x * self.square_view_width, 0), (x * self.square_view_width, (self.interface.ycmax + 1)* self.square_view_height)) for y in range(0, self.interface.ycmax + 2): draw_line(color, (0, y * self.square_view_height), ((self.interface.xcmax + 1) * self.square_view_width, y * self.square_view_height))