def draw(self): Render.clear_layer(5) self.opened = True print self.width, self.height x = 5 y = 5 button_text = 'Close' button = Button(button_text, self.width / 2, self.height - 3, function=close_window, target=Render.layers['overlay_console']) dragging = False click_x = None mouse = Input.mouse while True: Input.update() Render.clear_layer(Render.layers['overlay_console']) Render.draw_rect(Render.layers['overlay_console'], x, y, self.width, self.height, frame=True, f_color=terminal.color_from_argb(255, 100, 100, 255), bk_color=terminal.color_from_argb(192, 32, 32, 128), title="POP_UP TEST!") Render.print_rect(Render.layers['overlay_console'], x + 2, y + 2, self.width - 4, self.height - 4, self.text) if mouse.lbutton and x <= mouse.cx <= x + self.width and (mouse.cy == y or dragging): if click_x is None: click_x = mouse.cx - x x = mouse.cx - click_x # (width / 2) y = mouse.cy dragging = True else: dragging = False click_x = None if button.draw(x, y) == 'close': self.opened = False Render.clear_layer(Render.layers['overlay_console']) return # libtcod.console_flush() # graphics.draw_image(x, y, enlarge=True) # graphics.draw_image(x + 1, y + 1, enlarge=True) # graphics.clear() # graphics.draw_font(0,0) GameState.render_ui()
def blend(self, color2, bias=0.5, alpha=255 ): """Returns bltColor halfway between this color and color2""" colorA = self.getRGB() colorB = color2.getRGB() a = max(min(int(colorA[3] + ((colorB[3] - colorA[3]) * bias)), 255), 0) r = max(min(int(colorA[0] + ((colorB[0] - colorA[0]) * bias)), 255), 0) g = max(min(int(colorA[1] + ((colorB[1] - colorA[1]) * bias)), 255), 0) b = max(min(int(colorA[2] + ((colorB[2] - colorA[2]) * bias)), 255), 0) return bltColor(str(terminal.color_from_argb(a, r, g, b)))
def color(self): if self.label == TileType.WALL or self.label == TileType.CAVE: label = "WALL" else: label = "GROUND" if self.visible: light = "LIGHT" else: light = "DARK" return blt.color_from_argb(*Colors[f"{light}_{label}"].argb)
def __sub__(self, color2): r1, g1, b1, a1 = self.getRGB() r2, g2, b2, a2 = color2.getRGB() return Color( str( terminal.color_from_argb( a1, max(r1 - r2, 0), max(g1 - g2, 0), max(b1 - b2, 0), )))
def __add__(self, color2): r1, g1, b1, a1 = self.getRGB() r2, g2, b2, a2 = color2.getRGB() return Color( str( terminal.color_from_argb( a1, min(r1 + r2, 255), min(g1 + g2, 255), min(b1 + b2, 255), )))
def animate(self, current_map, animations, camera, config, animation_data): # Scale color based on ticks left. color = self.actor.color_fg[:] color[0] -= (50 - (self.ticks * 2)) terminal.bkcolor(terminal.color_from_argb(*color)) # Put visual up on each node in the path. for node in self.path: (x, y) = node if self.actor.x != x or self.actor.y != y: dx, dy = camera.to_camera_coords(x, y) terminal.put(dx * config['tile_spacing_x'], dy * config['tile_spacing_y'], ' ') # Make sure background stays the default color. terminal.bkcolor(terminal.color_from_argb(0, 0, 0, 0)) # Remove animation once its maximum ticks are reached. if self.ticks <= 0: animations.remove(self) self.ticks -= 1
def _draw(self): self.current_frame += 0.1 if self.current_frame >= self.delay: self.current_frame = 0 self.frame = self.vector.next_pos() if self.random_chr: self.chr = random.choice(self._chr_list) else: self.chr = next(self.chr_list) if self.random_color: self.color = random.choice(self._color_list) else: #determin percentage of travel index = int((float(self.loops) / float(self.max_size))*len(self._color_list)) # print "Loops: {0}, Max Size: {2}, Index: {1}".format(self.loops, index, self.max_size) self.color = self._color_list[min(index, len(self._color_list)-1)] # print "Loops: {0}, Max Size: {2}, Index: {1}".format(self.loops, index, self.max_size) self.loops += 1 if self.frame: for cell in self.frame: cam_x, cam_y = Utils.to_camera_coordinates(cell[0], cell[1]) # Determine where we should draw always_draw = True if (not GameState.current_level.is_blocked(cell[0], cell[1], ignore_mobs=True)\ and GameState.current_level.is_visible(pos=(cell[0], cell[1]))\ and cell != (GameState.player.x , GameState.player.y)) or always_draw == True: if not self.random_chr: # TEMP self.color = terminal.color_from_argb(max(255-((255/self.max_loops)*self.loops),0), 255, 196, 128) Render.print_line(10, cam_x, cam_y, "[align=center-center]{0}".format(self._chr_list[0]), f_color=self.color) else: if self.background: #Render.draw_char(10, cam_x, cam_y, Utils.get_unicode(219), color=random.choice(self._color_list), alpha=64) choice = random.choice(self._color_list) #print "CHOICE: {0}".format(choice) Render.draw_char(10, cam_x, cam_y, Utils.get_unicode(219), color=choice, alpha=64) Render.draw_char(10, cam_x, cam_y, self.chr, color=self.color) else: #print "Animation Done." return 'Done'
def __mul__(self, color2): if isinstance(color2, Color): r1, g1, b1, a1 = self.getRGB() r2, g2, b2, a2 = color2.getRGB() return Color( str( terminal.color_from_argb( a1, max(min(int(r1 * r2) // 255, 255), 0), max(min(int(g1 * g2) // 255, 255), 0), max(min(int(b1 * b2) // 255, 255), 0), ))) else: r1, g1, b1, a1 = self.getRGB() r2, g2, b2, a2 = color2, color2, color2, 1.0 return Color( str( terminal.color_from_argb( a1, max(min(int(r1 * r2), 255), 0), max(min(int(g1 * g2), 255), 0), max(min(int(b1 * b2), 255), 0), )))
def test_sprites(): blt.set("window.title='Omni: sprites'") blt.set("U+E000: ../Media/Background.jpg") blt.set("U+E001: ../Media/EasternDragon.png, resize=128x128, resize-filter=nearest") blt.set("U+E002: ../Media/FiveElements.bmp, resize=128x128, resize-filter=bilinear") c = (c_uint32 * 4)( blt.color_from_argb(128, 192, 64, 64), blt.color_from_argb(128, 64, 192, 64), blt.color_from_argb(128, 64, 64, 192), blt.color_from_argb(128, 192, 192, 64)) blt.set("U+E003: %d, raw-size=2x2, resize=128x128, resize-filter=bicubic" % addressof(c)) blt.clear() blt.color("black") blt.puts(2, 1, "[color=black]This primarily serves as a quick test of image format support") blt.puts(2, 3, "1. Background is loaded from a JPEG file") blt.puts(2, 5, "2. Dragon sprite is loaded from a PNG file\n image is upscaled 2x with nearest neighbourhood filter") blt.puts(2, 8, "3. Five elements diagram is loaded from BMP file\n image is downscaled with bilinear filer") blt.puts(2, 11, "4. Color gradient is loaded from 2x2 in-memory buffer\n image is upscaled 64x with bicubic filter") blt.color("white") blt.put(0, 0, 0xE000) # Background blt.put(5, 14, 0xE001) # Dragon blt.put(5+18*1, 14, 0xE002) # FiveElements blt.put(5+18*2, 14, 0xE003) # Gradient blt.refresh() key = None while key not in (blt.TK_CLOSE, blt.TK_ESCAPE): key = blt.read() blt.set("U+E000: none; U+E001: none; U+E002: none; U+E003: none")
def animate(self, current_map, animations, camera, config, animation_data): terminal.font("main") if not self.lingering: # Scale color based on ticks left. color = animation_data['soulrip']['color_bg'][:] color[0] = (50 + (self.ticks * 5)) terminal.bkcolor(terminal.color_from_argb(*color)) # Put color in aoe of the caster. for x in range(camera.width): for y in range(camera.height): dx, dy = x + camera.x, y + camera.y tile = current_map.tiles[dx][dy] if self.actor.distance_to(tile) <= self.aoe: if not tile.blocksLOS: dx, dy = camera.to_camera_coords(tile.x, tile.y) terminal.put(dx * config['tile_spacing_x'], dy * config['tile_spacing_y'], ' ') terminal.bkcolor( terminal.color_from_argb(*animation_data['soulrip']['color_bg'])) dx, dy = camera.to_camera_coords(self.target.x, self.target.y) terminal.put(dx * config['tile_spacing_x'], dy * config['tile_spacing_y'], ' ') # Make sure background stays the default color. terminal.bkcolor(terminal.color_from_argb(0, 0, 0, 0)) # Remove animation once its maximum ticks are reached. if self.ticks <= 0: if not self.lingering: self.ticks += 20 self.lingering = True else: animations.remove(self) self.ticks -= 1
def render(self): self.clear() term.layer(10) if self.cursor: term.color(term.color_from_argb(255, 64, 64, 64)) term.color for pos in self.bracket(): term.put(pos[X], pos[Y], 0x10FA) self.printString(np.array([2, -1]), "=== {:} ===".format(self.describe())) for button in self.button: button.render()
def print_map(self): terminal.clear() for y in range(self.w_ylen): for x in range(self.w_xlen): try: if self.zoom == 1: coord_y = self.w_top_y_coord + y coord_x = self.w_top_x_coord + x else: # calculate zoomed coordinates (?) coord_y = ((self.w_top_y_coord + y) - self.center_y) / self.zoom + self.center_y coord_x = ((self.w_top_x_coord + x) - self.center_x) / self.zoom + self.center_x w_chunk = self.world_tiles[(coord_y, coord_x)] chunk_color = w_chunk.tile.color terminal.color( terminal.color_from_argb(255, chunk_color[0], chunk_color[1], chunk_color[2])) terminal.put(x, y, w_chunk.tile.icon) except KeyError: # chunk is not rendered terminal.color(terminal.color_from_argb(255, 0, 0, 0)) terminal.put(x, y, u"█")
def character_screen(player: Entity, character_screen_width: int, character_screen_height: int, screen_width: int, screen_height: int): blt.bkcolor(blt.color_from_argb(*Colors.DARK_GREY.argb)) for i in range(5): blt.layer(i) blt.clear_area(0, 0, character_screen_width * 2, character_screen_height * 2) blt.bkcolor("none") # for i in range(5): # blt.puts() blt.puts(0, 1, "Character Information") blt.puts(0, 3, f"Level: {player.level.current_level}") blt.puts(0, 5, f"Experience: {player.level.current_xp}") blt.puts(0, 7, f"Experience to Level: {player.level.experience_to_next_level}") blt.puts(0, 11, f"Maximum HP: {player.fighter.max_hp}") blt.puts(0, 13, f"Attack: {player.fighter.power}") blt.puts(0, 15, f"Defense: {player.fighter.defense}")
def test_basic_output(): blt.set("window.title='Omni: basic output'") blt.clear() blt.color("white") # Wide color range n = blt.print_(2, 1, "[color=orange]1.[/color] Wide color range: ") long_word = "antidisestablishmentarianism." long_word_length = len(long_word) for i in range(long_word_length): factor = i / long_word_length red = int((1 - factor) * 255) green = int(factor * 255) blt.color(blt.color_from_argb(255, red, green, 0)) blt.put(2 + n + i, 1, long_word[i]) blt.color("white") blt.print_( 2, 3, "[color=orange]2.[/color] Backgrounds: [color=black][bkcolor=gray] grey [/bkcolor] [bkcolor=red] red " ) blt.print_( 2, 5, "[color=orange]3.[/color] Unicode support: Кириллица Ελληνικά α=β²±2°") blt.print_( 2, 7, "[color=orange]4.[/color] Tile composition: @ + [color=red]|[/color] = @[+][color=red]|[/color], a vs. ¨ a[+][color=red]¨[/color]" ) blt.printf(2, 9, "[color=orange]5.[/color] Box drawing symbols:") blt.print_( 5, 11, " ┌────────┐ \n" " │!......s└─┐\n" "┌──┘........s.│\n" "│............>│\n" "│...........┌─┘\n" "│<.@..┌─────┘ \n" "└─────┘ ■█┘╙ \n") blt.refresh() key = None while key not in (blt.TK_CLOSE, blt.TK_ESCAPE): key = blt.read()
def render(particle, emitter_pos): if particle.life > 0.0: #print("---------Render-----------") # int(particle.position["x"]), int(particle.position["y"]) offset = { "x": particle.position["x"] - emitter_pos["x"], "y": particle.position["y"] - emitter_pos["y"] } terminal.printf( int(emitter_pos["x"]), int(emitter_pos["y"]), "[offset={},{}][color={}]{}[/color]".format( int(offset["x"]), int(offset["y"]), terminal.color_from_argb(int(particle.color[0]), int(particle.color[1]), int(particle.color[2]), int(particle.color[3])), particle.glyph))
def test_basic_output(): blt.set("window.title='Omni: basic output'") blt.clear() blt.color("white") # Wide color range n = blt.print_(2, 1, "[color=orange]1.[/color] Wide color range: ") long_word = "antidisestablishmentarianism." long_word_length = len(long_word) for i in range(long_word_length): factor = i / long_word_length red = int((1 - factor) * 255) green = int(factor * 255) blt.color(blt.color_from_argb(255, red, green, 0)) blt.put(2 + n + i, 1, long_word[i]) blt.color("white") blt.print_(2, 3, "[color=orange]2.[/color] Backgrounds: [color=black][bkcolor=gray] grey [/bkcolor] [bkcolor=red] red ") blt.print_(2, 5, "[color=orange]3.[/color] Unicode support: Кириллица Ελληνικά α=β²±2°") blt.print_(2, 7, "[color=orange]4.[/color] Tile composition: @ + [color=red]|[/color] = @[+][color=red]|[/color], a vs. ¨ a[+][color=red]¨[/color]") blt.printf(2, 9, "[color=orange]5.[/color] Box drawing symbols:") blt.print_(5, 11, " ┌────────┐ \n" " │!......s└─┐\n" "┌──┘........s.│\n" "│............>│\n" "│...........┌─┘\n" "│<.@..┌─────┘ \n" "└─────┘ ■█┘╙ \n" ) blt.refresh() key = None while key not in (blt.TK_CLOSE, blt.TK_ESCAPE): key = blt.read()
def __init__(self, name, color, hp, dam_resist, x=0, y=0): self.x = x self.y = y self.area = None # свойства который идут из json self.name = name self.level = None self.hp = hp self.xp = 0 self.damage = 0 self.damage_resistance = dam_resist # for drawing self.color = terminal.color_from_argb( *[int(a) for a in color.split(' ')]) self.layer = 10 try: self.char = re.search(r'[A-ZА-Я]', name).group(0) except AttributeError: self.char = name[-1]
def render_all(player, current_map, fov, camera, under_mouse, animations, no_block_animations, widgets, targeting_action, game_state, config, animation_data): # Renders everything on the screen(Map, ui etc) in proper order. terminal.layer(0) render_map(player, current_map, fov, camera, under_mouse, config, game_state) render_ui(player, current_map, camera, under_mouse, config, game_state) render_animations(current_map, animations, no_block_animations, camera, config, animation_data) if game_state == GameState.show_inventory: render_inventory(player, widgets, config) if game_state == GameState.targeting: render_targeting(player, current_map, camera, under_mouse, config, targeting_action) terminal.bkcolor(terminal.color_from_argb(0, 0, 0, 0))
def create_window(x, y, w, h, title=None): last_bg = blt.state(blt.TK_BKCOLOR) blt.bkcolor(blt.color_from_argb(200, 0, 0, 0)) blt.clear_area(x, y, w + 1, h + 1) blt.bkcolor(last_bg) border = '[U+250C]' + '[U+2500]' * (w - 2) + '[U+2510]' blt.puts(x, y, '[font=small]' + border) for i in range(1, h): blt.puts(x, y + i, '[font=small][U+2502]') blt.puts(x + w - 1, y + i, '[font=small][U+2502]') border = '[U+2514]' + '[U+2500]' * (w - 2) + '[U+2518]' blt.puts(x, y + h, '[font=small]' + border) if title is not None: leng = len(title) offset = (w + 2 - leng) // 2 blt.clear_area(x + offset, y, leng, 1) blt.puts(x + offset, y, '[font=small]' + title)
def animate(self, current_map, animations, camera, config, animation_data): # Scale text color based on ticks left. terminal.font("text") color = self.color[:] color[0] += (self.ticks*3) # Display text at given coords. terminal.color(terminal.color_from_argb(*color)) dx, dy = camera.to_camera_coords(self.x, self.y) terminal.printf(dx*config['tile_spacing_x'], dy*config['tile_spacing_x'], str(self.text)) # Remove animation once its maximum ticks are reached. if self.ticks <= 0: animations.remove(self) self.ticks -= 1 # Shift the text slowly upward if self.ticks % 15 == 0: self.y -= 1
def color_map(color_list, keylist): # TODO: List should be tuple ( str , inex ) total_len = keylist[-1] current_key = 0 color_map = [] for k, key in enumerate(keylist): color_map.append(Color(color_list[k])) try: interp_num = keylist[current_key + 1] - keylist[current_key] - 1 bias_inc = 1.0 / (interp_num + 2) bias = bias_inc for n in range(interp_num): #TODO xrange to range color_a = Color(color_list[current_key]).getRGB() color_b = Color(color_list[current_key + 1]).getRGB() a = max( min( int(color_a[3] + ((color_b[3] - color_a[3]) * bias)), 255), 0) r = max( min( int(color_a[0] + ((color_b[0] - color_a[0]) * bias)), 255), 0) g = max( min( int(color_a[1] + ((color_b[1] - color_a[1]) * bias)), 255), 0) b = max( min( int(color_a[2] + ((color_b[2] - color_a[2]) * bias)), 255), 0) color_map.append( Color(str(terminal.color_from_argb(a, r, g, b)))) bias += bias_inc current_key += 1 except: pass return color_map
def render_path(player, current_map, camera, under_mouse, config, game_state): if game_state == GameState.targeting: return # Determine if path is walkable. walkable = False if under_mouse in current_map.items: walkable = True elif current_map.is_walkable((under_mouse.x, under_mouse.y)): # Only allow if tile was explored already. try: if under_mouse.explored: walkable = True except AttributeError: pass # Draws the walkable path to the current mouse position. if walkable: path = astar(current_map, (player.x, player.y), (under_mouse.x, under_mouse.y)) maxlength = player.alive.get_ap(False) # Walk each node in path and highlight it. for node in path: (x, y) = (node) # Dont highlight player's node and don't highlight end node. if (player.x != x or player.y != y) and (x != under_mouse.x or y != under_mouse.y): dx, dy = camera.to_camera_coords(x, y) terminal.color( terminal.color_from_argb( *config['mouse']['highlight']['default'])) terminal.put(dx * config['tile_spacing_x'], dy * config['tile_spacing_y'], '\u2610') # If player is in combat only draw the max path possible with players current ap. if player.alive.in_combat: maxlength -= player.alive.get_movement_cost() if maxlength == 0: under_mouse.highlight = config['mouse']['highlight'][ 'max_range'] del path[path.index(node):] break
def print_heightmap(self): terminal.clear() for y in range(self.w_ylen): for x in range(self.w_xlen): try: if self.zoom == 1: coord_y = self.w_top_y_coord + y coord_x = self.w_top_x_coord + x else: # calculate zoomed coordinates (?) coord_y = ((self.w_top_y_coord + y) - self.center_y) / self.zoom + self.center_y coord_x = ((self.w_top_x_coord + x) - self.center_x) / self.zoom + self.center_x scale_factor = int(self.heightmap[(coord_y, coord_x)] * 255) terminal.color( terminal.color_from_argb(scale_factor, 255, 255, 255)) terminal.put(x, y, u'█') except KeyError: pass
def draw(self, entity, x, y): if entity.hidden: return player = self.owner.player game_map = self.owner.levels.current_map # Draw the entity to the screen blt.layer(entity.layer) blt.color(entity.color) c = blt.color_from_name(entity.color) if not entity.cursor: light_map = player.player.lightmap argb = argb_from_color(c) a = argb[0] r = min(int(argb[1] * light_map[entity.y][entity.x]), 255) g = min(int(argb[2] * light_map[entity.y][entity.x]), 255) b = min(int(argb[3] * light_map[entity.y][entity.x]), 255) blt.color(blt.color_from_argb(a, r, g, b)) if not (player.light_source.fov_map.fov[entity.y, entity.x] and game_map.tiles[entity.x][entity.y].explored): blt.color("dark gray") # Cursor needs some offset in ascii if self.owner.options.gfx == "ascii" and entity.name == "cursor": blt.put_ext(x * self.owner.options.tile_offset_x, y * self.owner.options.tile_offset_y, -3 * self.owner.options.tile_offset_x, -5 * self.owner.options.tile_offset_y, entity.char) else: if entity.boss and not entity.fighter: blt.put((x - 1) * self.owner.options.tile_offset_x, (y - 1) * self.owner.options.tile_offset_y, entity.char) else: blt.put(x * self.owner.options.tile_offset_x, y * self.owner.options.tile_offset_y, entity.char)
def create_window(x, y, w, h, title=None): #test blt.composition(False) last_bg = blt.state(blt.TK_BKCOLOR) blt.bkcolor(blt.color_from_argb(200, 0, 0, 0)) blt.clear_area(x - 2, y - 2, w + 2, h + 2) blt.bkcolor(last_bg) # upper border border = '┌' + '─' * (w) + '┐' blt.puts(x - 1, y - 1, border) # sides for i in range(h): blt.puts(x - 1, y + i, '│') blt.puts(x + w, y + i, '│') # lower border border = '└' + '─' * (w) + '┘' blt.puts(x - 1, y + h, border) if title is not None: leng = len(title) offset = (w + 2 - leng) // 2 blt.puts(x + offset, y - 1, title)
def OBS_convert_color(color, alpha=255): if type(color) is libtcod.Color: return terminal.color_from_argb(alpha, color[0], color[1], color[2]) else: return color
def place_entities(self, room, entities): # Get a random number of monsters max_monsters_per_room = from_dungeon_level( table=[[2, 1], [3, 4], [5, 6]], dungeon_level=self.dungeon_level) max_items_per_room = from_dungeon_level( table=[[1, 1], [2, 4]], dungeon_level=self.dungeon_level) number_of_monsters: int = randint(0, max_monsters_per_room) number_of_items: int = randint(0, max_items_per_room) monster_chances = { 'orc': 80, 'troll': from_dungeon_level(table=[[15, 3], [30, 5], [60, 7]], dungeon_level=self.dungeon_level) } item_chances = { 'healing_potion': 35, 'sword': from_dungeon_level(table=[[5, 4]], dungeon_level=self.dungeon_level), 'shield': from_dungeon_level(table=[[15, 8]], dungeon_level=self.dungeon_level), 'lightning_scroll': from_dungeon_level([[25, 4]], self.dungeon_level), 'fireball_scroll': from_dungeon_level([[25, 6]], self.dungeon_level), 'confusion_scroll': from_dungeon_level([[10, 2]], self.dungeon_level) } for i in range(number_of_monsters): # Choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'orc': fighter_component: Fighter = Fighter(hp=10, base_defense=0, base_power=3) ai_component: BasicMonster = BasicMonster() monster = Entity(x=x, y=y, char='o', color=terminal.color_from_argb( 0, 63, 127, 63), name='Orc', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) else: fighter_component: Fighter = Fighter(hp=16, base_defense=1, base_power=4) ai_component: BasicMonster = BasicMonster() monster = Entity(x=x, y=y, char='T', color=terminal.color_from_argb( 0, 0, 127, 0), name='Troll', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) entities.append(monster) for i in range(number_of_items): x: int = randint(room.x1 + 1, room.x2 - 1) y: int = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=4) item: Entity = Entity(x=x, y=y, char='!', color=terminal.color_from_argb( 0, 238, 130, 238), name='Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable( slot=EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x=x, y=y, char='/', color=terminal.color_from_argb( 0, 153, 204, 255), name='sword', equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable( slot=EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x=x, y=y, char='[', color=terminal.color_from_argb( 0, 153, 204, 255), name='Shield', equippable=equippable_component) elif item_choice == 'fireball_scroll': item_component = Item( use_function=cast_fireball, targeting=True, targeting_message= '[color=blue]Left-click a target tile for the fireball, or right-click to cancel.[/color]', damage=12, radius=3) item = Entity(x=x, y=y, char='~', color=terminal.color_from_argb(0, 255, 0, 0), name='Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = Item( use_function=cast_confuse, targeting=True, targeting_message= '[color=blue]Left-click an enemy to confuse it, or right-click to cancel.[/color]' ) item = Entity(x=x, y=y, char='~', color=terminal.color_from_argb( 0, 255, 102, 255), name='Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item(use_function=cast_lightning, damage=20, maximum_range=5) item = Entity(x=x, y=y, char='~', color=terminal.color_from_argb( 0, 255, 255, 0), name='Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def highlight(self, panelPos, color=COLOR['WHITE']): if not self.contains(panelPos): return term.layer(3) term.color(term.color_from_argb(255, *color)) term.put(panelPos[X], panelPos[Y], 0x1020)
def blt_colour(self) -> int: return blt.color_from_argb(self.a, self.r, self.g, self.b)
def target_mode(source, target=None, ranged_componenet=None): """ Reset Params """ targets = [] target_x = 0 target_y = 0 if source is None: source = GameState.get_player() """ If no target supplied, Enter Targeting mode """ if target is None: tile_effected = set([]) # Utils.message('Choose Target. Left Click/Space to execute. Right Click/ESC to cancel.', libtcod.gold) ''' Get list of visible enemies to cycle through ''' target_list = GameState.current_level.closest_monsters(ranged_componenet.max_range) if target_list: target_list = cycle(target_list) target = next(target_list)[0] ''' Used to detect mouse movement ''' mouse = Input.mouse mouse_last_x, mouse_last_y = mouse.cx, mouse.cy mouse_moved = False while True: ''' Clear Screen ''' Render.clear_layer(layers['overlay_console']) """ Render.draw_rect(layers['overlay_console'], 0, 0, Constants.MAP_CONSOLE_WIDTH, Constants.MAP_CONSOLE_HEIGHT, frame=True, f_color=terminal.color_from_argb(255, 255, 100, 100), bk_color=terminal.color_from_name('transparent'), title="Targeting Mode - Right Click/ESC to Cancel") # """ ''' Get Inputs ''' Input.update() key = Input.key ''' determine if mouse moved, otherwise use auto-target ''' if mouse.cx != mouse_last_x or mouse.cy != mouse_last_y: mouse_moved = True moues_last_x, mouse_last_y = mouse.cx, mouse.cy if mouse_moved: target_x, target_y = Utils.to_map_coordinates(mouse.cx, mouse.cy) elif target: target_x, target_y = target.x, target.y else: target_x, target_y = source.x, source.y ''' determine line of fire (You may not be able to hit every enemy you see) ''' line = Utils.get_line((source.x, source.y), (target_x, target_y), walkable=True, ignore_mobs=True, max_length=ranged_componenet.max_range) for point in line: if point == (None, None): break point = Utils.to_camera_coordinates(point[0], point[1]) #libtcod.console_set_char_background(0, point[0], point[1], libtcod.lighter_blue, libtcod.BKGND_SET) Render.draw_char(layers['overlay_console'], point[0], point[1], 0x2588, terminal.color_from_argb(128, 64, 64, 255)) if len(line) > 0: index = Utils.find_element_in_list((None, None), line) if index is None: point = line[-1] else: point = line[index - 1] circle = Utils.get_circle_points(point[0], point[1], ranged_componenet.aoe) if circle: tile_effected = set(circle) for points in circle: points = Utils.to_camera_coordinates(points[0], points[1]) Render.draw_char(layers['overlay_console'], points[0], points[1], 0x2588, terminal.color_from_argb(128, 200, 32, 32)) Render.draw_char(layers['overlay_console'], points[0], points[1], 0xE000, terminal.color_from_argb(128, 255, 0, 0)) if mouse.lbutton_pressed or key == terminal.TK_SPACE: # target_tile = (target_x, target_y) # print tile_effected for target in tile_effected: # target = Map.to_map_coordinates(target[0], target[1]) monster = GameState.current_level.get_monster_at((target[0], target[1])) if monster is not None: print "Monster: " + str(monster) + " at " + str(target) targets.append(monster) break if mouse.rbutton_pressed or key == terminal.TK_ESCAPE: break if key == terminal.TK_F: if target_list: target = next(target_list)[0] GameState.render_ui() if not targets: # no enemy found within maximum range Utils.message('Cancelled.', Color('red')) Render.clear_layer(layers['overlay_console']) return 'cancelled' else: targets = GameState.current_level.get_monsters_in_range_at(target, ranged_componenet.aoe) Render.clear_layer(layers['overlay_console']) # TODO: Allow targeting Empty tiles # zap it! if ranged_componenet.animation: ranged_componenet.animation_params['origin'] = (source.x, source.y) ranged_componenet.animation_params['target'] = (target_x, target_y) ranged_componenet.animation_params['target_angle'] = Utils.get_angle(source.x, source.y, target_x, target_y) GameState.add_animation(ranged_componenet.animation, ranged_componenet.animation_params) for target in targets: if target.fighter: # TODO: Combat should handle all messages...... Utils.message('[color={1}]{2} [color={0}]takes [color={3}]{4} damage[color={0}].' ''.format(Constants.COMBAT_MESSAGE_DEFAULT_COLOR, Constants.COMBAT_MESSAGE_MONSTER_NAME_COLOR, target.name, Constants.COMBAT_MESSAGE_DAMAGE_COLOR, ranged_componenet.owner.equipment.power_bonus)) target.fighter.take_damage(ranged_componenet.owner.equipment.power_bonus) Render.clear_layer(5) return 'fired'
def draw(self): Render.clear_layer(5) self.opened = True print self.width, self.height x = 5 y = 5 button_text = 'Close' button = Button(button_text, self.width / 2, self.height - 3, function=close_window, target=Render.layers['overlay_console']) dragging = False click_x = None mouse = Input.mouse while True: Input.update() Render.clear_layer(Render.layers['overlay_console']) Render.draw_rect( Render.layers['overlay_console'], x, y, self.width, self.height, frame=True, f_color=terminal.color_from_argb(255, 100, 100, 255), bk_color=terminal.color_from_argb(192, 32, 32, 128), title="POP_UP TEST!") Render.print_rect(Render.layers['overlay_console'], x + 2, y + 2, self.width - 4, self.height - 4, self.text) if mouse.lbutton and x <= mouse.cx <= x + self.width and ( mouse.cy == y or dragging): if click_x is None: click_x = mouse.cx - x x = mouse.cx - click_x # (width / 2) y = mouse.cy dragging = True else: dragging = False click_x = None if button.draw(x, y) == 'close': self.opened = False Render.clear_layer(Render.layers['overlay_console']) return # libtcod.console_flush() # graphics.draw_image(x, y, enlarge=True) # graphics.draw_image(x + 1, y + 1, enlarge=True) # graphics.clear() # graphics.draw_font(0,0) GameState.render_ui()
def target_mode(source, target=None, ranged_componenet=None): """ Reset Params """ targets = [] target_x = 0 target_y = 0 if source is None: source = GameState.get_player() """ If no target supplied, Enter Targeting mode """ if target is None: tile_effected = set([]) # Utils.message('Choose Target. Left Click/Space to execute. Right Click/ESC to cancel.', libtcod.gold) ''' Get list of visible enemies to cycle through ''' target_list = GameState.current_level.closest_monsters( ranged_componenet.max_range) if target_list: target_list = cycle(target_list) target = next(target_list)[0] ''' Used to detect mouse movement ''' mouse = Input.mouse mouse_last_x, mouse_last_y = mouse.cx, mouse.cy mouse_moved = False while True: ''' Clear Screen ''' Render.clear_layer(layers['overlay_console']) """ Render.draw_rect(layers['overlay_console'], 0, 0, Constants.MAP_CONSOLE_WIDTH, Constants.MAP_CONSOLE_HEIGHT, frame=True, f_color=terminal.color_from_argb(255, 255, 100, 100), bk_color=terminal.color_from_name('transparent'), title="Targeting Mode - Right Click/ESC to Cancel") # """ ''' Get Inputs ''' Input.update() key = Input.key ''' determine if mouse moved, otherwise use auto-target ''' if mouse.cx != mouse_last_x or mouse.cy != mouse_last_y: mouse_moved = True moues_last_x, mouse_last_y = mouse.cx, mouse.cy if mouse_moved: target_x, target_y = Utils.to_map_coordinates( mouse.cx, mouse.cy) elif target: target_x, target_y = target.x, target.y else: target_x, target_y = source.x, source.y ''' determine line of fire (You may not be able to hit every enemy you see) ''' line = Utils.get_line((source.x, source.y), (target_x, target_y), walkable=True, ignore_mobs=True, max_length=ranged_componenet.max_range) for point in line: if point == (None, None): break point = Utils.to_camera_coordinates(point[0], point[1]) #libtcod.console_set_char_background(0, point[0], point[1], libtcod.lighter_blue, libtcod.BKGND_SET) Render.draw_char(layers['overlay_console'], point[0], point[1], 0x2588, terminal.color_from_argb(128, 64, 64, 255)) if len(line) > 0: index = Utils.find_element_in_list((None, None), line) if index is None: point = line[-1] else: point = line[index - 1] circle = Utils.get_circle_points(point[0], point[1], ranged_componenet.aoe) if circle: tile_effected = set(circle) for points in circle: points = Utils.to_camera_coordinates( points[0], points[1]) Render.draw_char( layers['overlay_console'], points[0], points[1], 0x2588, terminal.color_from_argb(128, 200, 32, 32)) Render.draw_char( layers['overlay_console'], points[0], points[1], 0xE000, terminal.color_from_argb(128, 255, 0, 0)) if mouse.lbutton_pressed or key == terminal.TK_SPACE: # target_tile = (target_x, target_y) # print tile_effected for target in tile_effected: # target = Map.to_map_coordinates(target[0], target[1]) monster = GameState.current_level.get_monster_at( (target[0], target[1])) if monster is not None: print "Monster: " + str(monster) + " at " + str(target) targets.append(monster) break if mouse.rbutton_pressed or key == terminal.TK_ESCAPE: break if key == terminal.TK_F: if target_list: target = next(target_list)[0] GameState.render_ui() if not targets: # no enemy found within maximum range Utils.message('Cancelled.', Color('red')) Render.clear_layer(layers['overlay_console']) return 'cancelled' else: targets = GameState.current_level.get_monsters_in_range_at( target, ranged_componenet.aoe) Render.clear_layer(layers['overlay_console']) # TODO: Allow targeting Empty tiles # zap it! if ranged_componenet.animation: ranged_componenet.animation_params['origin'] = (source.x, source.y) ranged_componenet.animation_params['target'] = (target_x, target_y) ranged_componenet.animation_params['target_angle'] = Utils.get_angle( source.x, source.y, target_x, target_y) GameState.add_animation(ranged_componenet.animation, ranged_componenet.animation_params) for target in targets: if target.fighter: # TODO: Combat should handle all messages...... Utils.message( '[color={1}]{2} [color={0}]takes [color={3}]{4} damage[color={0}].' ''.format(Constants.COMBAT_MESSAGE_DEFAULT_COLOR, Constants.COMBAT_MESSAGE_MONSTER_NAME_COLOR, target.name, Constants.COMBAT_MESSAGE_DAMAGE_COLOR, ranged_componenet.owner.equipment.power_bonus)) target.fighter.take_damage( ranged_componenet.owner.equipment.power_bonus) Render.clear_layer(5) return 'fired'
def draw_map(self): game_camera = self.owner.game_camera game_map = self.owner.levels.current_map player = self.owner.player # Set boundaries where to draw map bound_x = game_camera.bound_x * self.owner.ui.offset_x bound_y = game_camera.bound_y * self.owner.ui.offset_y bound_x2 = game_camera.bound_x2 * self.owner.ui.offset_x bound_y2 = game_camera.bound_y2 * self.owner.ui.offset_y # Clear what's drawn in camera self.clear_camera(6) # Set boundaries if map is smaller than viewport if game_map.width < game_camera.width: bound_x2 = game_map.width * self.owner.ui.offset_x if game_map.height < game_camera.height: bound_y2 = game_map.height * self.owner.ui.offset_y # Draw all the tiles within the boundaries of the game camera center = np.array([player.y, player.x]) entities = [] for dy, y in enumerate(range(bound_y, bound_y2, self.owner.ui.offset_y), start=1): for dx, x in enumerate(range(bound_x, bound_x2, self.owner.ui.offset_x), start=1): map_x, map_y = game_camera.x + dx, game_camera.y + dy if game_map.width < game_camera.width: map_x = dx if game_map.height < game_camera.height: map_y = dy visible = player.light_source.fov_map.fov[map_y, map_x] # Draw tiles within fov if visible: blt.layer(0) if self.owner.game_state == GameStates.TARGETING and not game_map.tiles[ map_x][map_y].targeting_zone: light_level = 0.5 elif player.fighter.revealing and game_map.tiles[map_x][ map_y].targeting_zone: light_level = 1.5 else: dist = float( cityblock(center, np.array([map_y, map_x]))) light_level = game_map.tiles[map_x][map_y].natural_light_level * \ (1.0 / (1.05 + 0.035 * dist + 0.025 * dist * dist)) player.player.lightmap[map_y][map_x] = light_level c = blt.color_from_name(game_map.tiles[map_x][map_y].color) argb = argb_from_color(c) a = argb[0] r = min(int(argb[1] * light_level), 255) g = min(int(argb[2] * light_level), 255) b = min(int(argb[3] * light_level), 255) blt.color(blt.color_from_argb(a, r, g, b)) blt.put(x, y, game_map.tiles[map_x][map_y].char) if len(game_map.tiles[map_x][map_y].layers) > 0: i = 1 for tile in game_map.tiles[map_x][map_y].layers: blt.layer(i) c = blt.color_from_name(tile[1]) argb = argb_from_color(c) a = argb[0] r = min(int(argb[1] * light_level), 255) g = min(int(argb[2] * light_level), 255) b = min(int(argb[3] * light_level), 255) blt.color(blt.color_from_argb(a, r, g, b)) blt.put(x, y, tile[0]) i += 1 # Set everything in fov as explored game_map.tiles[map_x][map_y].explored = True # Gray out explored tiles elif game_map.tiles[map_x][map_y].explored: blt.layer(0) blt.color("darkest gray") blt.put(x, y, game_map.tiles[map_x][map_y].char) if len(game_map.tiles[map_x][map_y].layers) > 0: i = 1 for tile in game_map.tiles[map_x][map_y].layers: blt.layer(i) blt.put(x, y, tile[0]) i += 1 if len(game_map.tiles[map_x][map_y].entities_on_tile) > 0: for n in game_map.tiles[map_x][map_y].entities_on_tile: if n not in entities: entities.append(n) self.draw_entities(entities) if len(self.light_sources) > 0: self.draw_light_sources()
def printString(self, string, color=COLOR['WHITE']): term.color(term.color_from_argb(255, *color)) term.printf(self.pos[X], self.pos[Y], string)
def printChar(self, pos, char, color=COLOR['WHITE']): term.color(term.color_from_argb(255, *color)) pos += self.pos term.put(pos[X], pos[Y], char)