def _generate_image(self): t = clamp((self.time + self.TOTAL_TIME) * (1 / self.TOTAL_TIME), 0, 1) t2 = clamp((self.time - (self.KILL_TIME - 0.25)) * 4, 0, 1) self._height = t * 50 + 1 self._width = (1 - t2) * 250 self.image = pygame.Surface((self._width, self._height), pygame.SRCALPHA) if self.time < 0: self.image.fill(PICO_WHITE) else: self.image.fill(PICO_BLACK) s1 = text.render_multiline(self.name, "small", PICO_YELLOW, 220, True) self.image.blit(s1, (self._width // 2 - s1.get_width() // 2, 8)) s2 = text.render_multiline(self.description, "small", PICO_WHITE, 220, True) self.image.blit(s2, (self._width // 2 - s2.get_width() // 2, self._height // 2 + 8 - s2.get_height() // 2)) if self._height >= 4: pygame.draw.rect(self.image, PICO_PINK, (1, 1, self._width - 2, self._height - 2), 1) if self.time >= 0 and self.time < self.DITHER_TIME: self.image.blit(self.dither_image, (0, 0)) self._recalc_rect()
def _generate_image(self): t = clamp((self.time + self.TOTAL_TIME) * (1 / self.TOTAL_TIME), 0, 1) t2 = clamp((self.time - (self.KILL_TIME - 0.25)) * 4, 0, 1) self._height = t * 28 + 1 self._width = (1-t2) * 250 self.image = pygame.Surface((self._width, self._height), pygame.SRCALPHA) if self.time < 0: self.image.fill(PICO_WHITE) else: self.image.fill(PICO_BLACK) s1 = text.render_multiline("New Intel: '%s'" % self.name, "small", PICO_YELLOW, 220, True) self.image.blit(s1, (self._width // 2 - s1.get_width() // 2, 6)) s2 = text.render_multiline("See Intel menu to read it!", "small", PICO_WHITE, 220, True) self.image.blit(s2, (self._width // 2 - s2.get_width() // 2, 16)) if self._height >= 4: pygame.draw.rect(self.image, PICO_GREEN, (1,1,self._width - 2, self._height - 2), 1) if self.time >= 0 and self.time < self.DITHER_TIME: self.image.blit(self.dither_image, (0,0)) self._recalc_rect()
def _generate_image(self): yo = 5 w = game.Game.inst.game_resolution.x t = clamp((self.time - START_TIME) / FINISH_TIME, 0, 1)**1.5 t3 = text.render_multiline(self.description, "small", PICO_LIGHTGRAY, wrap_width=400, center=False) h = clamp(t * 8, 0, 1) * (55 + t3.get_height()) self.image = pygame.Surface((w, h + yo * 2), pygame.SRCALPHA) dx1 = t * w * 0.6 dx2 = t * w * 0.6 + h z = clamp((self.time - KILL_TIME + 0.3) * 4, 0, 1) * ((h / 2) - yo) points = [ (int(w / 2 - dx1), 0 + z + yo), (int(w / 2 + dx1), 0 + z + yo), (int(w / 2 + dx2), h - z - yo), (int(w / 2 - dx2), h - z - yo), ] for x in range(int(w / 2 - dx1 - 8 + (self.time * 23) % 8), int(w / 2 + dx1), 8): l = 4 pygame.draw.line(self.image, PICO_WHITE, (x, yo + z - 2), (x + l, yo + z - 2), 1) pygame.draw.line(self.image, PICO_WHITE, (w - x, h - z - yo + 2), (w - x + l, h - z - yo + 2), 1) pygame.draw.polygon(self.image, PICO_DARKBLUE, points, 0) pygame.draw.polygon(self.image, PICO_WHITE, points, 1) #pygame.draw.polygon(self.image, PICO_BLACK, points, 1) pygame.draw.line(self.image, PICO_WHITE, points[3], points[0], 2) pygame.draw.line(self.image, PICO_WHITE, points[2], points[1], 2) if t >= 0.25 and self.time < KILL_TIME - 0.35: t1 = text.render_multiline("- SECTOR %d -" % self.number, "small", PICO_BLUE, wrap_width=500, center=False) self.image.blit(t1, (w / 2 - t1.get_width() / 2, 11)) t2 = text.render_multiline(self.name, "big", PICO_YELLOW, wrap_width=500, center=False) self.image.blit(t2, (w / 2 - t2.get_width() / 2, 29)) i = int( clamp((self.time - START_TIME - FINISH_TIME) * 0.8, 0, 1) * len(self.description)) t4 = text.render_multiline(self.description[0:i], "small", PICO_WHITE, wrap_width=400, center=False) self.image.blit(t4, (w / 2 - t3.get_width() / 2, 49)) self._width = w self._height = h self._recalc_rect()
def _draw_text(self, surf, s, color, pos, width): for i,char in enumerate(s): csb = text.render_multiline(char, "logo", PICO_WHITE) cs = text.render_multiline(char, "logo", color) csw, csh = cs.get_size() # split the width into (chars * 2) pieces tx = width / (len(s) * 2) * (i * 2 + 1) + pos.x surf.blit(csb, (tx - csw / 2, pos.y + 1)) surf.blit(csb, (tx - csw / 2, pos.y - 1)) surf.blit(csb, (tx - csw / 2 - 1, pos.y)) surf.blit(csb, (tx - csw / 2 + 1, pos.y)) surf.blit(cs, (tx - csw / 2, pos.y))
def draw_debug_console(self): y = 0 for line in debug.DEBUG_LOG[-20:]: surf = text.render_multiline(line, "small", PICO_GREEN, 500, False) pygame.draw.rect(self.scaled_screen, PICO_BLACK, (0, y, self.scaled_screen.get_width(), surf.get_height() + 2), 0) self.scaled_screen.blit(surf, (2, y + 1)) y += surf.get_height() + 2
def _generate_image(self): w = 65 h = 74 + self.expand_timer * 15 self.image = pygame.Surface((w, h), pygame.SRCALPHA) self.image.fill(PICO_BLACK) pygame.draw.rect(self.image, PICO_DARKGREEN, (1,1,w - 2, h - 2), 1) ships = self.civ.get_all_combat_ships() data = defaultdict(lambda : 0) for s in ships: name = s['name'] if name not in ORDER: name = 'other' data[name] += 1 for i,name in enumerate(ORDER): x = i % 2 * 30 + 5 y = (i // 2) * 19 + 15 img = self.images[name] color = PICO_GREEN if data[name] <= 0: color = PICO_DARKGRAY color_mask = pygame.mask.from_threshold(img, (*PICO_GREEN,255), (2,2,2,255)) img = color_mask.to_surface(setcolor=(*color,255), unsetcolor=(0,0,0,0)) self.image.blit(img, (x,y + 2)) text.render_multiline_to(self.image, pygame.Vector2(x + 16, y), str(data[name]), "tiny", color) color = PICO_LIGHTGRAY upkeep = int(self.civ.get_fleet_o2_upkeep(len(ships)) * 100) if upkeep >= 100: color = PICO_RED elif upkeep >= 50: color = PICO_ORANGE elif upkeep > 0: color = PICO_YELLOW pygame.draw.rect(self.image, color, (3, 3, w - 6, 10), 0) shipstext = text.render_multiline("SHIPS: %d" % len(ships), "tiny", PICO_BLACK) self.image.blit(shipstext, (6, 0)) if self.expand_timer >= 1: pygame.draw.rect(self.image, color, (3, h - 13, w - 6, 10), 0) s = text.render_multiline("+%d" % upkeep, "tiny", PICO_BLACK) self.image.blit(s, pygame.Vector2(6, h - 16)) self.image.blit(self._percent_o2_use, (6 + s.get_width() - 2, h - 11)) self._width, self._height = w,h self._recalc_rect()
def _generate_image(self): w = 400 nw = 100 pad = 4 icon = None icon_size = 0 title = "?" description = "Gather this intel by exploring more of the game" color = PICO_DARKGRAY title_offset = 0 if self.enabled: description = self.intel['description'] title = self.intel['name'] color = PICO_WHITE icon = self.icon_sheet.subsurface( (self.intel['icon'] * 23, 0, 23, 23)) title_offset = 4 icon_size = 26 description_surf = text.render_multiline(description, "small", color, wrap_width=w - nw - pad * 2, center=False) title_surf = text.render_multiline(title, 'small', color, wrap_width=nw - pad * 2, center=False) h1 = description_surf.get_height() h2 = title_surf.get_height() + icon_size h = max(h1, h2) + pad * 2 self.image = pygame.Surface((w, h), pygame.SRCALPHA) self.image.fill(PICO_BLACK) pygame.draw.rect(self.image, PICO_DARKGRAY, (nw, 0, 1, h), 0) self.image.blit(title_surf, (nw // 2 - title_surf.get_width() // 2, h // 2 - h2 // 2 + title_offset + 2)) if icon: self.image.blit( icon, (nw // 2 - icon.get_width() // 2, h // 2 - h2 // 2 + 12)) self.image.blit(description_surf, (pad * 2 + nw, h // 2 - h1 // 2 + 2)) self._width, self._height = w, h self._recalc_rect()
def _generate_image(self, hover=False): w = 240 h = 31 pad = 6 resource_color = RESOURCE_COLORS[self.upgrade.resource_type] upgrade_color = UPGRADE_CATEGORY_COLORS[self.upgrade.category] desc_rect = text.render_multiline(self.upgrade.description, "small", PICO_WHITE, 200, False).get_rect() h = desc_rect[3] + 19 self.image = pygame.Surface((w, h), pygame.SRCALPHA) if hover: pygame.draw.rect(self.image, PICO_BLACK, (0, 0, w, h), 0) text_color = PICO_LIGHTGRAY else: pygame.draw.rect(self.image, PICO_DARKGRAY, (0, 0, w, h), 0) text_color = PICO_LIGHTGRAY icon = upgradeicon.generate_upgrade_image(self.upgrade) self.image.blit(icon, (pad - 2, pad - 3)) text.FONTS["small"].render_to(self.image, (31 + pad, pad - 1), self.upgrade.title, upgrade_color) text.render_multiline_to(self.image, (31 + pad, pad + 12), self.upgrade.description, "small", text_color, 200, False) if self.time < WHITE_TIME: pygame.draw.rect(self.image, PICO_BLUE, (0, 0, w, h), 0) cw = w // 2 ch = h // 2 question_mark = text.render_multiline("?", "big", PICO_BLACK) self.image.blit(question_mark, (cw - question_mark.get_width() // 2, ch - question_mark.get_height() // 2)) elif self.time < DITHER_WHITE_TIME: pygame.draw.rect(self.image, PICO_WHITE, (0, 0, w, h), 0) elif self.time < REVEAL_TIME: self.image.blit(self.dither_image, (0, 0)) self._width = w self._height = h self._recalc_rect()
def _generate_image_noreward(self): ts1 = text.render_multiline(self.sector_title, "small", PICO_BLUE) tw = ts1.get_width() + 16 self.image = pygame.Surface((tw, REWARD_ICON_WIDTH), pygame.SRCALPHA) pygame.draw.rect( self.image, PICO_DARKBLUE, (0, 3, self.image.get_width(), self.image.get_height() - 6), 0) self.image.blit(ts1, (tw // 2 - ts1.get_width() // 2, 8)) self._width, self._height = self.image.get_size() self._recalc_rect()
def _generate_image(self): ts1 = text.render_multiline(self.sector_title, "small", PICO_BLUE) ts2 = text.render_multiline("Reward:", "small", PICO_BLUE) tw = ts1.get_width() + ts2.get_width() + 16 self.image = pygame.Surface( (tw + REWARD_ICON_WIDTH - 1, REWARD_ICON_WIDTH), pygame.SRCALPHA) pygame.draw.rect( self.image, PICO_DARKBLUE, (0, 3, self.image.get_width(), self.image.get_height() - 6), 0) self.image.blit(ts1, (4, 8)) self.image.blit(ts2, (ts1.get_width() + 18, 8)) w = REWARD_ICON_WIDTH h = REWARD_ICON_WIDTH x = w * REWARD_ICONS_ORDER[self.reward_name] self.image.blit(self.icon_sheet, (self.image.get_width() - REWARD_ICON_WIDTH - 1, 0), (x, 0, w, h)) self._width, self._height = self.image.get_size() self._recalc_rect()
def redraw(self): xmin, xmax, ymin, ymax = 0,0,0,0 outerpad = 3 for ci in self._controls: control = ci['control'] pos = ci['pos'] xmax = max(pos.x + control.width, xmax) ymax = max(pos.y + control.height, ymax) tab_width = 0 if self.tab: icon_offset = 0 icon = None if 'icon' in self.tab: icon = pygame.image.load(resources.resource_path(self.tab['icon'])) icon_offset = icon.get_width() + 4 tab_foreground = PICO_BLACK if sum(self.tab['color']) < 90 * 3: tab_foreground = PICO_WHITE tab_text = text.render_multiline(self.tab['text'], 'small', tab_foreground) tab_width = tab_text.get_size()[0] + 8 + icon_offset box_width = xmax + self.padding * 2 box_height = ymax + self.padding * 2 tab_offset = 0 if self.tab: tab_offset = 14 total_height = box_height + tab_offset self.image = pygame.Surface((box_width, box_height + tab_offset), pygame.SRCALPHA) pygame.draw.rect(self.image, PICO_DARKBLUE, (outerpad,outerpad + tab_offset, box_width - outerpad * 2, box_height - outerpad * 2), 0) self._width = box_width self._height = box_height + tab_offset # pygame.draw.rect(self.image, PICO_WHITE, (0, tab_offset, 1, box_height), 1) if self.tab: pygame.draw.rect(self.image, self.tab['color'], (outerpad, outerpad, tab_width, tab_offset), 0) # pygame.draw.rect(self.image, PICO_WHITE, (0, 0, 1, tab_offset + 1), 1) if 'icon' in self.tab: self.image.blit(icon, (4 + outerpad,4 + outerpad)) self.image.blit(tab_text, (4 + icon_offset + outerpad, 4 + outerpad)) self._background_offset = V2(self.padding, self.padding + tab_offset) pygame.draw.line(self.image, PICO_WHITE, (0,0), (4,0)) pygame.draw.line(self.image, PICO_WHITE, (0,0), (0,4)) pygame.draw.line(self.image, PICO_WHITE, (box_width - 4, total_height-1), (box_width, total_height-1)) pygame.draw.line(self.image, PICO_WHITE, (box_width - 1, total_height-4), (box_width - 1, total_height)) self._reposition_children() self._recalc_rect()
def _generate_image(self, upgrade=None): w,h = 120, 120 self.image = pygame.Surface((w,h), pygame.SRCALPHA) self.image.fill(self.color) pygame.draw.rect(self.image, PICO_WHITE, (2,2,w-4,h-4), 1) t1 = text.render_multiline("PLAYER %d" % self.number, "small", PICO_WHITE, wrap_width=120) self.image.blit(t1, (10, 10)) self.image.blit(self.input_image, (w - 32, 22)) t2 = text.render_multiline("%s" % self.name, "big", PICO_WHITE, wrap_width=120) self.image.blit(t2, (10, 26)) if self.upgrade: surf = upgradeicon.generate_upgrade_image(self.upgrade) self.image.blit(surf, (w // 2 - surf.get_width() // 2, 48)) t3 = text.render_multiline("%s" % self.upgrade.title, "small", PICO_WHITE, wrap_width=100) self.image.blit(t3, (w // 2 - t3.get_width() // 2, 84)) else: pygame.draw.rect(self.image, PICO_LIGHTGRAY, (w // 2 - 10,51,23,23), 1) self._width, self._height = w,h self._recalc_rect()
def _generate_image(self, hover=False): self._width, self._height = (150, 50) bgcolor = PICO_WHITE if self.bought: bgcolor = PICO_YELLOW elif not self.can_afford: bgcolor = PICO_DARKGRAY elif hover: bgcolor = PICO_LIGHTGRAY self.image = pygame.Surface((self._width, self._height), pygame.SRCALPHA) self.image.fill(bgcolor) ts = text.render_multiline(self.name, "tiny", PICO_BLACK, 100) self.image.blit(ts, (3, -1)) ts = text.render_multiline("%d credits" % self.price, "tiny", PICO_BLACK, 50) self.image.blit(ts, (self._width - ts.get_width() - 3, -1)) ts = text.render_multiline(self.description, "tiny", PICO_BLACK, 100, center=False) self.image.blit(ts, (33, 12)) pygame.draw.polygon(self.image, (0, 0, 0, 0), [ (self._width - 5, self._height), (self._width, self._height - 5), (self._width, self._height), ], 0) self._recalc_rect()
def _generate_image(self): self.image = pygame.Surface((self._width, self._height), pygame.SRCALPHA) ts = text.render_multiline(OFFER_NAMES[self.offer], "small", PICO_WHITE, wrap_width=120) pygame.draw.rect(self.image, PICO_PINK, (3, 4, self._width - 6, self._height - 7), 1) frame = starmapscene.REWARD_ICONS_ORDER[self.offer] pygame.draw.rect(self.image, (0, 0, 0, 0), (0, 0, ts.get_width() + 15, 13)) self.image.blit(self.icon_sheet, (-7, -6), (frame * 23, 0, 23, 23)) self.image.blit(ts, (11, 2)) self._recalc_rect()
def _generate_image(self, hover=False): padding = 4 delta = self.option_pos - self.pos is_left = delta.x > 0 is_top = delta.y > 0 lsurf = text.render_multiline(self.label, "small", PICO_WHITE) self._width = lsurf.get_width() + abs(delta.x) + padding self._height = lsurf.get_height() + abs(delta.y) + padding self.image = pygame.Surface((self._width, self._height), pygame.SRCALPHA) # X and Y position to place the text if is_left: x = padding else: x = self._width - lsurf.get_width() - padding if is_top: y = padding else: y = self._height - lsurf.get_height() - padding if hover: pygame.draw.rect(self.image, PICO_BLUE, (x - 2, y - 1, lsurf.get_width() + 4, 10), 0) self.image.blit(lsurf, (x, y)) # Figure out the points for the label line if is_left: p1x = x + lsurf.get_width() + 2 p1y = y + 4 else: p1x = x - 3 p1y = y + 3 if is_left: p2x = self._width - padding else: p2x = padding if is_top: p2y = self._height - padding else: p2y = padding sdx = 1 if delta.x >= 0 else -1 sdy = 1 if delta.y >= 0 else -1 p3x = p2x + (abs(p2y - p1y)) * -sdx p3y = p1y pygame.draw.line(self.image, PICO_BLUE, (p1x, p1y), (p3x, p3y), 1) pygame.draw.line(self.image, PICO_BLUE, (p3x, p3y), (p2x, p2y), 1) pygame.draw.line(self.image, PICO_BLUE, (p1x, p1y - 4), (p1x, p1y + 4), 1) self._recalc_rect()
def _generate_image(self): ts = text.render_multiline(self.price_label, "small", PICO_BLACK, wrap_width=120) w = self._width = ts.get_width() + 7 h = self._height = 10 self.image = pygame.Surface((self._width, self._height), pygame.SRCALPHA) color = PICO_YELLOW if self.bought: color = PICO_WHITE elif not self.can_buy: color = PICO_GREYPURPLE pygame.draw.polygon(self.image, color, [(0, h // 2), (h // 2, 0), (w, 0), (w, h - 1), (h // 2, h - 1)]) self.image.blit(ts, (5, 1)) pygame.draw.line(self.image, PICO_BLACK, (h // 2, h - 1), (w, h - 1)) pygame.draw.line(self.image, PICO_BLACK, (0, h // 2), (h // 2, h)) self._recalc_rect()
def redraw(self): xmin, xmax, ymin, ymax = 0,0,0,0 for ci in self._controls: control = ci['control'] pos = ci['pos'] xmax = max(pos.x + control.width, xmax) ymax = max(pos.y + control.height, ymax) box_width = xmax + self.padding * 2 box_height = ymax + self.padding * 2 tab_offset = 0 if self.tab: tab_offset = 14 self.image = pygame.Surface((box_width, box_height + tab_offset), pygame.SRCALPHA) pygame.draw.rect(self.image, PICO_DARKBLUE, (0,tab_offset, box_width, box_height), 0) self._width = box_width self._height = box_height + tab_offset pygame.draw.rect(self.image, PICO_WHITE, (0, tab_offset, box_width, box_height), 1) if self.tab: icon_offset = 0 icon = None if 'icon' in self.tab: icon = pygame.image.load(resources.resource_path(self.tab['icon'])) icon_offset = icon.get_width() + 4 tab_text = text.render_multiline(self.tab['text'], 'small', PICO_BLACK) tab_width = tab_text.get_size()[0] + 8 + icon_offset pygame.draw.rect(self.image, self.tab['color'], (0, 0, tab_width, tab_offset + 1), 0) pygame.draw.rect(self.image, PICO_WHITE, (0, 0, tab_width, tab_offset + 1), 1) if 'icon' in self.tab: self.image.blit(icon, (4,4)) self.image.blit(tab_text, (4 + icon_offset, 4)) self._background_offset = V2(self.padding, self.padding + tab_offset) self._reposition_children() self._recalc_rect()
def render(self): t = time.time() #self.game.screen.fill(PICO_BLACK) self.update_layers() if game.DEV: for spr in self.background_group.sprites( ) + self.game_group.sprites() + self.ui_group.sprites(): if spr.image is None and spr.visible: print(spr, "bad image") self.background_group.draw(self.game.screen) self.particle_group.draw(self.game.screen) self.game_group.draw(self.game.screen) if self.shake_sprite: self.shake_sprite.render(self.game.screen) if self.debug: for k, v in self.fleet_managers.items(): for fleet in v.current_fleets: fleet.debug_render(self.game.screen) gi = pygame.Surface(self.game.screen.get_size(), pygame.SRCALPHA) gi.fill((0, 0, 0, 0)) ff = list(self.flowfield.fields.values())[self.flowfielddebug] if self.flowfielddebugstage > 0: for col in range(1, len(ff.base_grid[0])): x = col * flowfield.GRIDSIZE + ff.offset.x pygame.draw.line(gi, (255, 255, 255, 50), (x, ff.offset.y), (x, ff.offset.y + game.RES[1]), 1) for row in range(1, len(ff.base_grid)): y = row * flowfield.GRIDSIZE + ff.offset.y pygame.draw.line(gi, (255, 255, 255, 50), (ff.offset.x, y), (ff.offset.x + game.RES[0], y), 1) if self.flowfielddebugstage == 1: for y, gr in enumerate(ff.base_grid): for x, gc in enumerate(gr): pt = V2(x * flowfield.GRIDSIZE, y * flowfield.GRIDSIZE) + ff.offset s = "-" if gc: s = "O" FONTS['tiny'].render_to(gi, (pt.x + 2, pt.y + 2), s, (128, 255, 128, 180)) if self.flowfielddebugstage == 2: for y, gr in enumerate(ff.dgrid): for x, gc in enumerate(gr): pt = V2(x * flowfield.GRIDSIZE, y * flowfield.GRIDSIZE) + ff.offset if isinstance(gc, tuple): s = "-" elif gc is None: s = "??" else: s = str(gc % 10) FONTS['tiny'].render_to(gi, (pt.x + 2, pt.y + 2), s, (128, 255, 128, 180)) elif self.flowfielddebugstage == 3: for y, gr in enumerate(ff.grid): for x, gc in enumerate(gr): p1 = V2((x + 0.5) * flowfield.GRIDSIZE, (y + 0.5) * flowfield.GRIDSIZE) + ff.offset if gc is not None: p2 = p1 + gc * flowfield.GRIDSIZE * 0.75 pygame.draw.line(gi, (0, 0, 255), p1, p2) pygame.draw.circle(gi, (0, 0, 255), p1, 1) else: pygame.draw.circle(gi, (255, 0, 255), p1, 3, 1) if False: for y in range(len(self.objgrid.grid)): for x in range(len(self.objgrid.grid[0])): x1 = x * self.objgrid.grid_size y1 = y * self.objgrid.grid_size pygame.draw.rect(gi, (0, 255, 0, 150), (x1, y1, self.objgrid.grid_size + 1, self.objgrid.grid_size + 1), 1) FONTS['tiny'].render_to( gi, (x1 + 2, y1 + 2), "%d" % len(self.objgrid.grid[y][x]), (128, 255, 128, 180)) self.game.screen.blit(gi, (0, 0)) self.pause_sprite.visible = self.paused if self.stage_name.time < 2 and self.stage_name.alive(): self.pause_sprite.visible = False if not self.cinematic: self.ui_group.draw(self.game.screen) self.tutorial_group.draw(self.game.screen) if self.debug: self.enemy.render(self.game.screen) debug_render(self.game.screen, self) self.update_times['render'] = time.time() - t #FONTS['small'].render_to(self.game.screen, (5,game.RES[1] - 25), "%d" % self.time, (255,255,255,255)) if self.debug: for i, s in enumerate([ "%s:%.1f" % (a, b * 1000) for a, b in self.update_times.items() ]): FONTS['tiny'].render_to(self.game.screen, (30, 100 + i * 8), s, (128, 255, 128, 180)) FONTS['tiny'].render_to( self.game.screen, (30, 50), "diagram: %.1f MAX, %.1f MEAN" % (self.fleet_diagram.max_debug_time * 1000, self.fleet_diagram.mean_debug_time * 1000), (128, 255, 255, 180)) if game.DEV: FONTS['tiny'].render_to(self.game.screen, (game.RES[0] - 120, 4), "%d" % self.time, (128, 255, 128, 180)) res = self.game.game_resolution if self.cinematic: surf = pygame.Surface(res, pygame.SRCALPHA) pygame.draw.rect(surf, PICO_DARKBLUE, (0, 0, res.x, 40), 0) pygame.draw.rect(surf, PICO_DARKBLUE, (0, res.y - 40, res.x, 40), 0) #surf.set_alpha(160) self.game.screen.blit(surf, (0, 0)) tri = [V2(0, 0), V2(4, 4), V2(0, 8)] if self.game_speed > 1: color = PICO_BLUE if ((self.time % 2) > 1) else PICO_WHITE pygame.draw.rect(self.game.screen, PICO_BLUE, (0, 0, res.x, res.y), 1) pygame.draw.polygon(self.game.screen, color, [(z + V2(res.x - 12, res.y - 12)) for z in tri], 0) pygame.draw.polygon(self.game.screen, color, [(z + V2(res.x - 7, res.y - 12)) for z in tri], 0) elif not self.cinematic: ctl = "Space" if self.game.input_mode == "joystick": ctl = "L1" t = text.render_multiline(ctl, "small", PICO_LIGHTGRAY, wrap_width=130) self.game.screen.blit(t, (res.x - t.get_width() - 16, res.y - 12)) pygame.draw.polygon(self.game.screen, PICO_LIGHTGRAY, [(z + V2(res.x - 12, res.y - 12)) for z in tri], 0) pygame.draw.polygon(self.game.screen, PICO_LIGHTGRAY, [(z + V2(res.x - 7, res.y - 12)) for z in tri], 0) #FONTS['small'].render_to(self.game.screen, PICO_BLUE, "") return None
def setup(self, start_planet, end, end_planet=None): thickness = 6 ht = thickness / 2 color = PICO_LIGHTGRAY end_offset = 0 start_offset = 20 if end_planet: end = V2(end_planet.pos) color = PICO_WHITE end_offset = (end_planet.radius + 6) pt1 = V2(start_planet.pos) pt2 = end if not end: self.visible = False return delta = pt2 - pt1 if delta.length_squared() < 25**2: self.visible = False return self.visible = True w, h = tuple(game.Game.inst.game_resolution) forward = helper.try_normalize(delta) side = V2(forward.y, -forward.x) pt1 += forward * start_offset pt2 += forward * -end_offset points = [] points.append(pt1 + side * -ht) points.append(pt1 + side * ht) points.append(pt2 + side * ht + forward * -15) points.append(pt2 + side * 15 + forward * -15) points.append(pt2) points.append(pt2 + side * -15 + forward * -15) points.append(pt2 + side * -ht + forward * -15) points = [tuple(p) for p in points] self.image = pygame.Surface((w, h), pygame.SRCALPHA) pygame.draw.polygon(self.image, color, points, 0) self._width = w self._height = h self.pos = V2(0, 0) self._recalc_rect() if self.last_end is None: self.last_end = end civ = start_planet.owning_civ if civ is not None: fighter_range = fighter.Fighter.estimate_flight_range( civ, end_planet) * 0.9 ranges = {"Fighter Range": fighter_range} #if civ.challenge_max_fuel: # ranges["Ship Range"] = colonist.Colonist.estimate_flight_range(civ, end_planet) * 0.9 title = "Fighter Range" if delta.length_squared() > fighter_range**2: ang = -delta.as_polar()[1] if ang < -90: ang += 180 side = -side if ang > 90: ang -= 180 side = -side pt2 = pt1 + forward * (fighter_range - start_offset) points = [] ht = thickness / 2 ht2 = thickness + 3 mid1 = pt1 + forward * ( (fighter_range - start_offset) / 2 - 42) mid2 = pt1 + forward * ( (fighter_range - start_offset) / 2 + 42) pygame.draw.line(self.image, PICO_YELLOW, tuple(pt1 + side * ht), tuple(pt1 + side * ht2), 1) pygame.draw.line(self.image, PICO_YELLOW, tuple(pt1 + side * ht2), tuple(mid1 + side * ht2), 1) pygame.draw.line(self.image, PICO_YELLOW, tuple(mid2 + side * ht2), tuple(pt2 + side * ht2), 1) pygame.draw.line(self.image, PICO_YELLOW, tuple(pt2 + side * ht), tuple(pt2 + side * ht2), 1) ts = text.render_multiline(title, "small", PICO_YELLOW) ts2 = pygame.transform.rotate(ts, ang) center = (pt1 + pt2) / 2 + 6 * side self.image.blit( ts2, tuple(center + V2(-ts2.get_width() / 2, -ts2.get_height() / 2))) if civ.challenge_max_fuel: ship_range = colonist.Colonist.estimate_flight_range( civ, end_planet) * 0.9 if delta.length_squared() > ship_range**2: o1s = fighter_range - start_offset o2s = ship_range - start_offset mid3 = pt1 + forward * ((o2s - o1s) / 2 - 22 + o1s) mid4 = pt1 + forward * ((o2s - o1s) / 2 + 22 + o1s) pt3 = pt1 + forward * (ship_range - start_offset) pygame.draw.line(self.image, PICO_YELLOW, tuple(pt2 + side * ht2), tuple(mid3 + side * ht2), 1) pygame.draw.line(self.image, PICO_YELLOW, tuple(mid4 + side * ht2), tuple(pt3 + side * ht2), 1) pygame.draw.line(self.image, PICO_YELLOW, tuple(pt3 + side * ht), tuple(pt3 + side * ht2), 1) ts = text.render_multiline("Others", "small", PICO_YELLOW) ts2 = pygame.transform.rotate(ts, ang) center = (mid3 + mid4) / 2 + 6 * side self.image.blit( ts2, tuple(center + V2(-ts2.get_width() / 2, -ts2.get_height() / 2))) if (end - self.last_end).length_squared() > 10**2: if end_planet: sound.play("short2") else: sound.play("short1") self.last_end = end
def _generate_text_image(self, hover=False): color = self.color text_color = PICO_WHITE if sum(color) > 180 * 3: text_color = PICO_BLACK if hover: if self.color == PICO_WHITE: color = PICO_LIGHTGRAY else: color = PICO_WHITE text_color = PICO_BLACK text_img = text.render_multiline(self.text, self.size, text_color) tw = text_img.get_width() pad = SIZE_PADDING[self.size] w = tw + pad * 4 h = HEIGHTS[self.size] + pad * 2 text_offset = 0 y_offset = 0 icon = None if self.label: h += 10 y_offset = 10 if self.joy_button: text_offset += 16 if self.icon: icon = pygame.image.load(resource_path(self.icon)).convert_alpha() w += icon.get_width() + 4 text_offset += icon.get_width() / 2 if icon.get_height() > HEIGHTS[self.size]: h += int((icon.get_height() - HEIGHTS[self.size])) y_offset += int((icon.get_height() - HEIGHTS[self.size]) / 2) w = self.fixed_width or w self.image = pygame.Surface((w, h), pygame.SRCALPHA) pygame.draw.rect(self.image, color, (0, 0, w, h), 0) text_x = w / 2 - tw / 2 + text_offset icon_x = text_x #text.FONTS[self.size].render_to(self.image, (text_x, pad + y_offset), self.text, text_color) self.image.blit(text_img, (text_x, pad + y_offset)) if icon: icon_x = text_x - 4 - icon.get_width() icon_y = pad + y_offset + int( (HEIGHTS[self.size] - icon.get_height()) / 2) pygame.draw.rect( self.image, PICO_BLACK, (icon_x - 1, icon_y, icon.get_width() + 2, icon.get_height())) pygame.draw.rect( self.image, PICO_BLACK, (icon_x, icon_y - 1, icon.get_width(), icon.get_height() + 2)) self.image.blit(icon, (icon_x, icon_y)) if self.label: #text.render_multiline_to(self.image, (icon_x, pad), self.label, "tiny", text_color) text.FONTS['tiny'].render_to(self.image, (icon_x, pad - 4), self.label, text_color) z = { 'tiny': 2, 'small': 3, 'medium': 3, 'big': 4, 'huge': 5 }[self.size] pygame.draw.polygon(self.image, (255, 255, 255, 0), [(w - z, 0), (w, 0), (w, z)]) if self.joy_button: btn_img = text.render_multiline(self.joy_button, "huge", text_color) self.image.blit(btn_img, (4, h // 2 - btn_img.get_height() // 2)) if self.asset_border: pygame.draw.line(self.image, PICO_BLACK, (0, 0), (0, h)) pygame.draw.line(self.image, PICO_BLACK, (0, h - 1), (w, h - 1)) self._width = w self._height = h self._recalc_rect()