def init_turret(self, type, left, top, right, bottom): description = [[''], # Lines are this long: #"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Basic ["Your average machine of death.", "Minions not included."], # Fire ["Has strong personal magnetism, if", "you know what I mean..."], # Tesla ["Back at my old lab, I think I saw", "one of these babies fry an intern", "once."], # Lazor ["Sort of like a magnifying glass to", "an anthill..."] ][type] y = top for line in description: img = get_tiny_text(line) self.add_element(Image(left, y, img)) y += img.get_height() + 3
def init_turret(self, type, left, top, right, bottom): description = [ [''], # Lines are this long: #"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Basic ["Your average machine of death.", "Minions not included."], # Fire ["Has strong personal magnetism, if", "you know what I mean..."], # Tesla [ "Back at my old lab, I think I saw", "one of these babies fry an intern", "once." ], # Lazor ["Sort of like a magnifying glass to", "an anthill..."] ][type] y = top for line in description: img = get_tiny_text(line) self.add_element(Image(left, y, img)) y += img.get_height() + 3
def render(self, screen): self.playscene.render(screen) left = 140 top = 100 screen.blit(self.bg, (left, top)) left += 5 top += 5 y = top img = get_text(self.title, (255, 255, 255), 18) screen.blit(img, (left, y)) y += img.get_height() + 5 if len(self.pages) > 0: for line in self.pages[0]: img = get_tiny_text(line) screen.blit(img, (left, y)) y += img.get_height() + 3 self.counter += 1 if (self.counter // 5) % 2 == 0: img = get_text("<Press SPACE>", (0, 128, 255), 14) screen.blit(img, (left, top + self.bg.get_height() - img.get_height() - 8))
def draw_button(self, id, index, screen, caption, hotkey=None): y = 5 hide_border = False if index == 0: x = 2 hide_border = True elif index == 100: x = screen.get_width() - 50 else: x = 40 + 60 * (index - 1) screen.blit(self.buttons[id], (x, y)) if not hide_border: pygame.draw.rect( screen, (255, 255, 255) if self.hovering == index else (128, 128, 128), pygame.Rect(x, y, 40, 24), 1) if hotkey != None or id == 'main_exit': if hotkey != None: screen.blit(get_text(hotkey.upper(), (255, 255, 255), 12), (x + 40, y + 15)) tc = self.tiny_captions.get(id, None) if tc != None: screen.blit(get_tiny_text(tc), (x, y + 23))
def init_medtent(self, left, top, right, bottom): global advice_i a = self.building.x * 3 + 13 b = self.building.y * 7 + 4 papercuts = a % 36 facelifts = b % 17 warts = (a + b) % 4 y = top y += 4 + self.add_label(left, y, "Papercuts treated: " + str(papercuts), 14) y += 4 + self.add_label(left, y, "Facelifts performed: " + str(facelifts), 14) y += 4 + self.add_label(left, y, "Warts removed: " + str(warts), 14) y += 10 y += self.add_label(left, y, "First Aid Advice of the Day:", 14) + 3 hp = 1 + sum(b.btype == "medicaltent" for b in self.playscene.potato.get_all_buildings_of_player_SLOW(self.playscene.user_id)) self.playscene.player.hp = self.playscene.player.hp0 = hp advice = [ ['The medical leeches are intended for', 'external use only. Please do not', 'take them orally or as a suppository.'], ['You know, this would go a lot easier', 'for both of us if you stopped with', 'all the screaming!'], ['If you experience dizzyness, nausea,', 'headaches, stomaches, liveraches,', 'chest pains, diarrhea, and trouble', 'breathing, please go somewhere else.'], ['Undercooked space goats can lead to', 'discoloration of the stool. Do not', 'panic for this is temporary and', '(relatively) harmless.'], ['Pills here!'], ['Fever? Have you tried more cowbell?'], ['Dammit, we are doctors, not miracle', 'workers!'], ['My prescription: take two shots of', 'whiskey, and feel free not to call', 'me in the morning.'], ['How about a nice game of Operation?'] ] advice = advice[advice_i % len(advice)] advice_i += 1 for line in advice: img = get_tiny_text(line) self.add_element(Image(left, y, img)) y += img.get_height() + 2
def __init__(self, playscene, building): UiScene.__init__(self) self.user_id = playscene.user_id self.building = building self.playscene = playscene bg = pygame.Surface((200, 180)).convert_alpha() bg.fill((0, 0, 0, 180)) self.add_element(Image(100, 60, bg)) self.initialized = False self.hovering = -1 self.hover_regions = [] top = 65 left = 105 bottom = 240 - 5 right = 295 if building.btype == 'hq': self.init_hq(playscene, left, top, right, bottom) elif building.btype == 'radar': self.init_radar(left, top, right, bottom) elif building.btype == 'foundry': top = self.add_title(left, top, "Foundry") self.init_build_bot(1, playscene, left, top, right, bottom) elif building.btype == 'machinerylab': top = self.add_title(left, top, "Machinery Lab") self.init_build_bot(2, playscene, left, top, right, bottom) elif building.btype == 'sciencelab': top = self.add_title(left, top, "Science Lab") self.init_build_bot(3, playscene, left, top, right, bottom) elif building.btype == 'drill': top = self.add_title(left, top, "Drill") self.add_element( Image(left, top, get_tiny_text("Produces Chocolate"))) elif building.btype == 'quarry': top = self.add_title(left, top, "Quarry") self.init_quarry(left, top, right, bottom) elif building.btype == 'beacon': top = self.add_title(left, top, "Shield Generator") self.init_beacon(left, top, right, bottom) elif building.btype == 'turret': top = self.add_title(left, top, "Basic Turret") self.init_turret(1, left, top, right, bottom) elif building.btype == 'fireturret': top = self.add_title(left, top, "Fire Turret") self.init_turret(2, left, top, right, bottom) elif building.btype == 'teslaturret': top = self.add_title(left, top, "Tesla Turret") self.init_turret(3, left, top, right, bottom) elif building.btype == 'lazorturret': top = self.add_title(left, top, "Laz0r Turret") self.init_turret(4, left, top, right, bottom) elif building.btype == 'medicaltent': top = self.add_title(left, top, "Medical Tent") self.init_medtent(left, top, right, bottom) elif building.btype == 'launchsite': top = self.add_title(left, top, "Launch Site") self.init_launchsite(playscene, left, top, right, bottom) self.add_cancel_button(left, bottom)
def init_medtent(self, left, top, right, bottom): global advice_i a = self.building.x * 3 + 13 b = self.building.y * 7 + 4 papercuts = a % 36 facelifts = b % 17 warts = (a + b) % 4 y = top y += 4 + self.add_label(left, y, "Papercuts treated: " + str(papercuts), 14) y += 4 + self.add_label(left, y, "Facelifts performed: " + str(facelifts), 14) y += 4 + self.add_label(left, y, "Warts removed: " + str(warts), 14) y += 10 y += self.add_label(left, y, "First Aid Advice of the Day:", 14) + 3 hp = 1 + sum(b.btype == "medicaltent" for b in self.playscene.potato. get_all_buildings_of_player_SLOW(self.playscene.user_id)) self.playscene.player.hp = self.playscene.player.hp0 = hp advice = [[ 'The medical leeches are intended for', 'external use only. Please do not', 'take them orally or as a suppository.' ], [ 'You know, this would go a lot easier', 'for both of us if you stopped with', 'all the screaming!' ], [ 'If you experience dizzyness, nausea,', 'headaches, stomaches, liveraches,', 'chest pains, diarrhea, and trouble', 'breathing, please go somewhere else.' ], [ 'Undercooked space goats can lead to', 'discoloration of the stool. Do not', 'panic for this is temporary and', '(relatively) harmless.' ], ['Pills here!'], ['Fever? Have you tried more cowbell?'], ['Dammit, we are doctors, not miracle', 'workers!'], [ 'My prescription: take two shots of', 'whiskey, and feel free not to call', 'me in the morning.' ], ['How about a nice game of Operation?']] advice = advice[advice_i % len(advice)] advice_i += 1 for line in advice: img = get_tiny_text(line) self.add_element(Image(left, y, img)) y += img.get_height() + 2
def __init__(self, playscene, building): UiScene.__init__(self) self.user_id = playscene.user_id self.building = building self.playscene = playscene bg = pygame.Surface((200, 180)).convert_alpha() bg.fill((0, 0, 0, 180)) self.add_element(Image(100, 60, bg)) self.initialized = False self.hovering = -1 self.hover_regions = [] top = 65 left = 105 bottom = 240 - 5 right = 295 if building.btype == 'hq': self.init_hq(playscene, left, top, right, bottom) elif building.btype == 'radar': self.init_radar(left, top, right, bottom) elif building.btype == 'foundry': top = self.add_title(left, top, "Foundry") self.init_build_bot(1, playscene, left, top, right, bottom) elif building.btype == 'machinerylab': top = self.add_title(left, top, "Machinery Lab") self.init_build_bot(2, playscene, left, top, right, bottom) elif building.btype == 'sciencelab': top = self.add_title(left, top, "Science Lab") self.init_build_bot(3, playscene, left, top, right, bottom) elif building.btype == 'drill': top = self.add_title(left, top, "Drill") self.add_element(Image(left, top, get_tiny_text("Produces Chocolate"))) elif building.btype == 'quarry': top = self.add_title(left, top, "Quarry") self.init_quarry(left, top, right, bottom) elif building.btype == 'beacon': top = self.add_title(left, top, "Shield Generator") self.init_beacon(left, top, right, bottom) elif building.btype == 'turret': top = self.add_title(left, top, "Basic Turret") self.init_turret(1, left, top, right, bottom) elif building.btype == 'fireturret': top = self.add_title(left, top, "Fire Turret") self.init_turret(2, left, top, right, bottom) elif building.btype == 'teslaturret': top = self.add_title(left, top, "Tesla Turret") self.init_turret(3, left, top, right, bottom) elif building.btype == 'lazorturret': top = self.add_title(left, top, "Laz0r Turret") self.init_turret(4, left, top, right, bottom) elif building.btype == 'medicaltent': top = self.add_title(left, top, "Medical Tent") self.init_medtent(left, top, right, bottom) elif building.btype == 'launchsite': top = self.add_title(left, top, "Launch Site") self.init_launchsite(playscene, left, top, right, bottom) self.add_cancel_button(left, bottom)
def init_hq(self, playscene, left, top, right, bottom): y = top title = get_text("Headquarters", (255, 255, 255), 24) y += 5 self.add_element(Image(left, y, title)) y += 5 + title.get_height() text = get_tiny_text("Research available:") self.add_element(Image(left, y, text)) y += 5 + text.get_height() buildings = playscene.potato.buildings_to_research()[:4] if playscene.tutorial: if playscene.tutorial_instance.current_step == 2: buildings = [('foundry', settings.building_research['foundry']) ] else: buildings = [] for building in buildings: x = left icon = playscene.toolbar.buttons['build_' + building[0]] self.add_element(Image(x, y, icon)) x += icon.get_width() + 7 img = get_tiny_text(structure.get_structure_name(building[0])) self.add_element(Image(x, y + 5, img)) img = get_text( "Unlocked at: " + str(settings.building_research[building[0]]), (0, 128, 255), 14) self.add_element(Image(right - img.get_width() - 4, y + 2, img)) self.hover_regions.append( (building[0], left, y, right, y + icon.get_height())) y += icon.get_height() + 3 self.add_element( Image(left, y + 5, get_tiny_text("Research will cause a mainframe reboot"))) self.add_element( Image(left, y + 5 + 10, get_tiny_text("which lowers your shields during time.")))
def render(self, screen): self.playscene.render(screen) left = screen.get_width() // 2 - self.bg.get_width() // 2 top = screen.get_height() // 2 - self.bg.get_height() // 2 y = top screen.blit(self.bg, (left, top)) left += 5 y += 5 title = get_text("OH NOES!", (255, 0, 0), (24)) lines = [ get_tiny_text("Detecting the lowering of the sheilds"), get_tiny_text("a swarm of natives decide to use the"), get_tiny_text("opportunity to attack!") ] screen.blit(title, (left, y)) y += title.get_height() + 5 for line in lines: screen.blit(line, (left, y)) y += 3 + line.get_height()
def init_hq(self, playscene, left, top, right, bottom): y = top title = get_text("Headquarters", (255, 255, 255), 24) y += 5 self.add_element(Image(left, y, title)) y += 5 + title.get_height() text = get_tiny_text("Research available:") self.add_element(Image(left, y, text)) y += 5 + text.get_height() buildings = playscene.potato.buildings_to_research()[:4] if playscene.tutorial: if playscene.tutorial_instance.current_step == 2: buildings = [('foundry', settings.building_research['foundry'])] else: buildings = [] for building in buildings: x = left icon = playscene.toolbar.buttons['build_' + building[0]] self.add_element(Image(x, y, icon)) x += icon.get_width() + 7 img = get_tiny_text(structure.get_structure_name(building[0])) self.add_element(Image(x, y + 5, img)) img = get_text("Unlocked at: " + str(settings.building_research[building[0]]), (0, 128, 255), 14) self.add_element(Image(right - img.get_width() - 4, y + 2, img)) self.hover_regions.append((building[0], left, y, right, y + icon.get_height())) y += icon.get_height() + 3 self.add_element(Image(left, y + 5, get_tiny_text( "Research will cause a mainframe reboot"))) self.add_element(Image(left, y + 5 + 10, get_tiny_text( "which lowers your shields during time.")))
def render_bot_factory(self, screen): self.bot_data = None if self.build_bot_command != None and self.build_bot_command.has_response( ): r = self.build_bot_command.get_response() if r != None: self.build_bot_command = None if r.get('success', False): self.counts[0] = r.get('a', 0) self.counts[1] = r.get('b', 0) self.counts[2] = r.get('c', 0) self.render_bot_factory_invalidate() else: err = r.get('error', None) if err == 'capacity': jukebox.play_voice("arsenal_exceeded") elif err == 'resources': jukebox.play_voice("insufficient_resources") else: pass if not self.has_data: if self.bot_query.has_response(): self.has_data = True results = self.bot_query.get_response() if results != None: self.counts = [ results.get('a', 0), results.get('b', 0), results.get('c', 0) ] self.playscene.potato.apply_bot_snapshot( self.counts[0], self.counts[1], self.counts[2]) left = 105 top = 90 self.totals = [] y = top img = get_tiny_text("Builds " + settings.botnames[self.bot_type - 1] + 's') self.add_element(Image(left, y, img)) y += img.get_height() img = get_tiny_text("(Limit 3 per " + ('Foundry', 'Machinery Lab', 'Science Lab')[self.bot_type - 1] + ")") self.add_element(Image(left, y, img)) y += img.get_height() y += 5 for i in range(3): y += 5 + self.add_label( left, y, settings.botnames[i] + ": " + str(self.counts[i]), 18) self.totals.append(self.elements[-1]) handler = [self.add_bot1, self.add_bot2, self.add_bot3][self.bot_type - 1] costs = [ settings.BOT_COST_1, settings.BOT_COST_2, settings.BOT_COST_3 ][self.bot_type - 1] y += 13 rimages = [] for key in 'food water aluminum copper silicon oil'.split( ' '): if costs.get(key, 0) > 0: rimages.append(get_resource_icon(key)) rimages.append(get_tiny_text(costs[key])) x = left for img in rimages: self.add_element(Image(x, y, img)) x += img.get_width() + 2 y += 5 self.add_element( Button(left, y + 10, "Build " + settings.botnames[self.bot_type - 1], handler, True)) img = get_text("Cataloging the arsenal...", (255, 255, 255), 18) screen.blit(img, (screen.get_width() // 2 - img.get_width() // 2, screen.get_height() // 2 - img.get_height() // 2)) if self.initialized: pass
def render_bot_factory(self, screen): self.bot_data = None if self.build_bot_command != None and self.build_bot_command.has_response(): r = self.build_bot_command.get_response() if r != None: self.build_bot_command = None if r.get('success', False): self.counts[0] = r.get('a', 0) self.counts[1] = r.get('b', 0) self.counts[2] = r.get('c', 0) self.render_bot_factory_invalidate() else: err = r.get('error', None) if err == 'capacity': jukebox.play_voice("arsenal_exceeded") elif err == 'resources': jukebox.play_voice("insufficient_resources") else: pass if not self.has_data: if self.bot_query.has_response(): self.has_data = True results = self.bot_query.get_response() if results != None: self.counts = [results.get('a', 0), results.get('b', 0), results.get('c', 0)] self.playscene.potato.apply_bot_snapshot(self.counts[0], self.counts[1], self.counts[2]) left = 105 top = 90 self.totals = [] y = top img = get_tiny_text("Builds " + settings.botnames[self.bot_type - 1] + 's') self.add_element(Image(left, y, img)) y += img.get_height() img = get_tiny_text("(Limit 3 per " + ('Foundry', 'Machinery Lab', 'Science Lab')[self.bot_type - 1] + ")") self.add_element(Image(left, y, img)) y += img.get_height() y += 5 for i in range(3): y += 5 + self.add_label(left, y, settings.botnames[i] + ": " + str(self.counts[i]), 18) self.totals.append(self.elements[-1]) handler = [self.add_bot1, self.add_bot2, self.add_bot3][self.bot_type - 1] costs = [ settings.BOT_COST_1, settings.BOT_COST_2, settings.BOT_COST_3 ][self.bot_type - 1] y += 13 rimages = [] for key in 'food water aluminum copper silicon oil'.split(' '): if costs.get(key, 0) > 0: rimages.append(get_resource_icon(key)) rimages.append(get_tiny_text(costs[key])) x = left for img in rimages: self.add_element(Image(x, y, img)) x += img.get_width() + 2 y += 5 self.add_element(Button(left, y + 10, "Build " + settings.botnames[self.bot_type - 1], handler, True)) img = get_text("Cataloging the arsenal...", (255, 255, 255), 18) screen.blit(img, (screen.get_width() // 2 - img.get_width() // 2, screen.get_height() // 2 - img.get_height() // 2)) if self.initialized: pass