def init_loading_bar(self): screen = thorpy.get_screen() screen.fill((255, 255, 255)) loading_bar = thorpy.LifeBar.make( " ", size=(thorpy.get_screen().get_width() // 2, 30)) loading_bar.center(element="screen") self.loading_bar = loading_bar
def launch_end(): S = parameters.W screen = thorpy.get_screen() title_text = "The End" title = thorpy.make_text(title_text, thorpy.style.TITLE_FONT_SIZE, TCOLOR) text = "You are the first of the Intergalatic Ranking." end_text = "... You are free now." end_text = thorpy.pack_text(400, end_text) end = thorpy.make_text(end_text, thorpy.style.TITLE_FONT_SIZE, TCOLOR) letter = thorpy.make_text(thorpy.pack_text(int(0.7 * S), text)) w = letter.get_fus_rect().w + 10 boxletter = thorpy.Box.make([letter], (w, S // 2)) boxletter.refresh_lift() thorpy.style.BOX_RADIUS += 10 background = thorpy.load_image("PaulinaRiva.png") background = thorpy.get_resized_image(background, (parameters.W, parameters.H // 2), type_=max) ## background = thorpy.Background.make(image=background) thorpy.get_screen().blit(background, (0, 0)) pygame.display.flip() box = thorpy.make_ok_box([title, boxletter, end], "Ok") box.e_ok.user_func = thorpy.functions.quit_menu_func box.e_ok.user_params = {} boxletter.set_main_color((200, 200, 200, 50)) box.set_main_color((200, 200, 255, 100)) box.center() thorpy.style.BOX_RADIUS -= 10 launch(box)
def launch_intro_text2(): S = parameters.W screen = thorpy.get_screen() title_text = "The beginning (2)" title = thorpy.make_text(title_text, thorpy.style.TITLE_FONT_SIZE, TCOLOR) end_text = "... My only hope now is to become the greatest racer.." end_text = thorpy.pack_text(400, end_text) end = thorpy.make_text(end_text, thorpy.style.TITLE_FONT_SIZE, TCOLOR) letter = thorpy.make_text(thorpy.pack_text(int(0.7 * S), INTRO2)) w = letter.get_fus_rect().w + 10 boxletter = thorpy.Box.make([letter], (w, S // 2)) boxletter.refresh_lift() thorpy.style.BOX_RADIUS += 10 background = thorpy.load_image("PaulinaRiva.png") background = thorpy.get_resized_image(background, (parameters.W, parameters.H // 2), type_=max) ## background = thorpy.Background.make(image=background) thorpy.get_screen().blit(background, (0, 0)) pygame.display.flip() box = thorpy.make_ok_box([title, boxletter, end], "Ok") box.e_ok.user_func = thorpy.functions.quit_menu_func box.e_ok.user_params = {} boxletter.set_main_color((200, 200, 200, 50)) box.set_main_color((200, 200, 255, 100)) box.center() thorpy.style.BOX_RADIUS -= 10 launch(box)
def build_map(self, me, fast=False, use_beach_tiler=True, load_tilers=False, graphical_load=True): """ <fast> : quality a bit lower if true, loading time a bit faster. <use_beach_tiler>: quality much better if true, loading buch slower. Requires Numpy ! <load_tilers> : use precomputed textures from disk. Very slow but needed if you don't have Numpy but still want beach_tiler. """ if graphical_load: #just ignore this - nothing to do with map configuration screen = thorpy.get_screen() screen.fill((255,255,255)) loading_bar = thorpy.LifeBar.make(" ", size=(thorpy.get_screen().get_width()//2,30)) loading_bar.center(element="screen") self.loading_bar = loading_bar self.update_loading_bar("Building height map...", 0.) build_hmap(me) for x,y,h in self.heights: me.hmap[x][y] = h if graphical_load: img = thorpy.get_resized_image(me.original_img_hmap, screen.get_size(), max) screen.blit(img, (0,0)) self.update_loading_bar("Building tilers...",0.1) self.build_materials(me, fast, use_beach_tiler, load_tilers) self.update_loading_bar("Building map surfaces...",0.2) build_lm(me) self.update_loading_bar("Adding static objects...",0.3) self.add_static_objects(me) self.add_user_objects(me) #Now that we finished to add objects, we generate the pygame surface self.update_loading_bar("Building surfaces", 0.8) me.build_surfaces() me.build_gui_elements()
def launch_help(func=None): S = parameters.W title = thorpy.make_text("Instructions", thorpy.style.TITLE_FONT_SIZE, TCOLOR) elements = [] # text = "SPACE BAR : Accelerate (this uses fuel)" elements.append(make_instruction(text)) text = "LEFT/RIGHT/UP/DOWN : Change way (turn left/right/up/down)" elements.append(make_instruction(text)) text = "Race: The goal of a race is to reach the finish line as fast as possible.\n"+\ "If your vessel is destructed or if you cannot reach the finish line, you loose the race." elements.append(make_instruction(text)) text = "Obstacles: Obstacles are on the track. Some of them can move and rotate. Obstacles damage your vessel and slow it down." elements.append(make_instruction(text)) text = "Vessel: A vessel is constituted of a nose, a cockpit, a tail, two wings and one engine.\n"+\ "These parts determine how fast the vessel can run, how well it turns and how resistant it is to obstacles." elements.append(make_instruction(text)) text = "Life: The current damage state of your vessel in indicated on the top-left of the HUD. "+\ "The more you damage your vessel, the more you will pay for repairing it." elements.append(make_instruction(text)) text = "Garage: You prepare the next race in your garage. You can buy/sell parts and modify/repair your vessel." elements.append(make_instruction(text)) text = "Ranking: The Intergalactic Ranking works as follow - the winner of each race wins a point and the loser loses one point.\n"+\ "The Intergalactif League is subdivided in three categories: national, international and intergalactic. "+\ "Note that the money prize of each race is determined by the category." elements.append(make_instruction(text)) # thorpy.style.BOX_RADIUS += 10 boxletter = thorpy.Box.make(elements, (int(0.75 * S), int(0.85 * parameters.H))) boxletter.refresh_lift() box = thorpy.make_ok_box([title, boxletter]) box.e_ok.user_func = thorpy.functions.quit_menu_func box.e_ok.user_params = {} ## boxletter.set_main_color((200,200,200,50)) box.set_main_color((200, 200, 255, 100)) box.center() thorpy.style.BOX_RADIUS -= 10 background = thorpy.load_image("PaulinaRiva.png") background = thorpy.get_resized_image(background, (parameters.W, parameters.H // 2), type_=max) ## background = thorpy.Background.make(image=background) thorpy.get_screen().blit(background, (0, 0)) pygame.display.flip() launch(box) if func: func()
def initialize(): global bullet_img, smoke_gen, fire_gen, debris_hero, all_debris, rocket_img, laser_gen, container_imgs thorpy.get_screen().blit(thorpy.load_image("Calinou2.png"), (0, 0)) title = get_title() title.blit() loadbar = thorpy.LifeBar.make("Building smoke generators...", size=(int(0.9 * W), 30), font_size=10) loadbar.center() loadbar.set_life(0.) pygame.display.flip() bullet_img = thorpy.graphics.get_aa_ellipsis((BULLET_SIZE, BULLET_SIZE), BULLET_COLOR) bullet_img = thorpy.graphics.get_shadow(bullet_img, color=(255, 155, 0)) # ## rocket_img = thorpy.graphics.get_aa_ellipsis((ROCKET_SIZE,ROCKET_SIZE), ## ROCKET_COLOR) rocket_img = thorpy.load_image("rocket.png", (255, 255, 255)) rocket_img = pygame.transform.scale(rocket_img, (ROCKET_SIZE, ROCKET_SIZE)) ## rocket_img = thorpy.graphics.get_shadow(rocket_img, color=(255,155,0)) # smoke_gen = thorpy.fx.get_smokegen(n=NSMOKE, color=(20, 20, 20), grow=0.6) fire_gen = thorpy.fx.get_fire_smokegen(n=NSMOKE, color=(20, 20, 20), grow=0.4, black_increase=3. / NSMOKE) loadbar.set_text("Building explosions gifs...") loadbar.set_life(0.1) loadbar.unblit_and_reblit() for size in range(3): loadbar.set_life(0.1 + size / 3. * 0.4) loadbar.unblit_and_reblit() for i in range(10): ## e = thorpy.AnimatedGif.make(random.choice(["explosion-illugion.gif", ## "explosion.gif"])) e = thorpy.AnimatedGif.make(random.choice(["explosion.gif"])) e.resize_frames(expl_sizes[size]) e.set_visible(False) e.nread = 8 e.low = 6 explosions[size].append(e) all_explosions.append(e) for name in "life", "bullet", "rocket", "nuke", "bullet", "laser": img = thorpy.load_image(name + ".png", colorkey=(255, 255, 255)) img = pygame.transform.smoothscale(img, CONTAINER_SIZE) img.convert() container_imgs[name] = img return loadbar
def __init__(self): self.hfull = thorpy.load_image("heart_full.png", (255, 255, 255)) self.hempty = thorpy.load_image("heart_empty.png", (255, 255, 255)) self.heart_size = self.hfull.get_size() self.heart_spacing = self.heart_size[0] + 5 self.xlife = -self.heart_spacing + 5 self.ylife = 5 # self.e_speed = thorpy.make_text("0 km/h", thorpy.style.FONT_SIZE + 8, (255, 255, 0)) self.e_speed.stick_to("screen", "top", "top") self.e_speed.stick_to("screen", "right", "right", False) self.e_speed.move((-50, 5)) # self.e_fuel = LifeBar("Fuel", text_color=(255, 0, 0), font_size=thorpy.style.FONT_SIZE + 8) self.e_fuel.stick_to("screen", "top", "top") # self.e_pos = thorpy.make_text("Xth position", thorpy.style.FONT_SIZE + 8, (255, 255, 0)) self.e_pos.stick_to("screen", "bottom", "bottom") # self.screen = thorpy.get_screen() self.scene = None self.hero = None
def launch_options(game, epause, mainmenu=False): els = get_options_elements() box = thorpy.make_ok_box(els) box.e_ok.user_func = thorpy.functions.quit_menu_func box.e_ok.user_params = {} box.center() m = thorpy.Menu(box) m.play() parameters.set_approx_memory_usage(els[6].get_value()) parameters.MUSIC = els[2].get_value() if not parameters.MUSIC: pygame.mixer.music.stop() # parameters.REFLECT = els[9].get_value() hasclouds = els[10].get_value() parameters.RAIN_IMPACTS = els[11].get_value() if hasclouds: parameters.NCLOUDS = 5 else: parameters.NCLOUDS = 0 need_bisurf = hasclouds or parameters.RAIN_IMPACTS > 0 or parameters.REFLECT if need_bisurf != parameters.BISURFACE: print("Changing camera type", need_bisurf) parameters.BISURFACE = not (parameters.BISURFACE) if not mainmenu: game.refresh_camera() if not mainmenu: if need_bisurf and parameters.NCLOUDS == 0: game.cam.clouds = [] if not mainmenu: game.cam.show(thorpy.get_screen()) game.blit_things() epause.blit() pygame.display.flip()
def load(filename): thorpy.launch_blocking_choices("What do you want to do ?", [("Load", None), ("Delete", delete), ("Cancel", cancel_func)]) if not Choice.value: game.savefile = filename thorpy.functions.quit_menu_func() thorpy.functions.quit_menu_func() else: if Choice.value == "del": if thorpy.launch_binary_choice(" Are you sure? \n\n"): os.remove(filename) thorpy.functions.quit_menu_func() else: thorpy.get_screen().fill((255, 255, 255)) frame.blit() pygame.display.flip()
def __init__(self, game, units, defender, distance): self.battle_duration = BATTLE_DURATION self.defender_start_shooting = BATTLE_DURATION // 10 self.projectile_class = Projectile self.distance = distance self.defender = defender self.agressors = [u for u in units if not (u is defender)] units = self.get_units_dict_from_list(units) assert defender in units.values() nb_defender = len( [u for u in units.values() if u.team == defender.team]) assert nb_defender == 1 #Map objects self.units_dict = units self.game = game self.surface = thorpy.get_screen() self.surface_rect = self.surface.get_rect() self.W, self.H = self.surface.get_size() self.right = units.get(RIGHT) self.left = units.get(LEFT) self.up = units.get(UP) self.down = units.get(DOWN) self.center = units.get(CENTER) # zoom_level = None if zoom_level is None: for i, s in enumerate(self.game.me.zoom_cell_sizes): if s == 32: zoom_level = i break self.z = zoom_level self.original_zoom = self.game.me.zoom_level ## self.game.me.set_zoom(self.z) self.cell_size = None self.f1 = [] self.f2 = [] self.f = [] self.deads = [] self.to_remove = [] self.fights = [] self.fight_t = 0 self.fight_frame_walk = 0 self.fight_frame_attack = 0 self.fight_frame_attack_slow = 0 self.finished = 0 self.background = None self.mod_display = 1 self.blit_this_frame = True self.show_footprints = True self.show_splash = True self.is_splash = None self.is_footprint = None self.nx = None self.ny = None self.projectiles = [] self.before_f1 = None self.before_f2 = None
def __init__(self, e_background, hero): self.e_background = e_background self.screen = thorpy.get_screen() self.ships = [] self.bullets = deque() self.rockets = deque() self.hero = hero self.rail = shipm.Rail(self.hero) self.add_ship(self.rail) self.add_ship(hero) self.i = 1 self.hero_dead = GameEvent(50,thorpy.functions.quit_menu_func,self) self.events = [self.hero_dead] self.hud = HUD() self.score = 0 # self.ship_flux = 50 self.ship_prob = 0.5 self.ennemy_prob = 0.5 # self.damage_rail_m = -1 self.damage_rail_M = W + 1 self.tot_time = 1000 self.remaining_time = self.tot_time self.hints = [] self.hints_ids = set([]) self.laser = 0 hlaser = self.hero.pos.y-self.hero.rect.h/2. ## self.laser_img = pygame.Surface((p.LASER_W,hlaser)) ## self.laser_img.fill((255,255,0)) self.laser_img = g.get_laser_img(self) self.laser_rect = self.laser_img.get_rect() # self.a_imgs = {} self.a_imgs["nice"] = g.get_imgs_alert("Right kill !", (200,255,0)) self.a_imgs["bad"] = g.get_imgs_alert("Bad kill", (155,0,0), 20, 30) self.a_imgs["dead"] = g.get_imgs_alert("You are dead", (155,0,0), 40, 60) self.a_imgs["nuke"] = g.get_imgs_alert("Nuke!!!", size1=60, size2=90) self.a_imgs["item"] = g.get_imgs_alert("Got item", size1=20, size2=30) self.alerts = [] # self.sounds = thorpy.SoundCollection() self.sounds.add("MikeKoenig2.wav", "bullet") self.sounds.add("SoundExplorer2.wav", "nuke") self.sounds.add("MikeKoenig3b.wav", "rocket") self.sounds.add("MikeKoenig4.wav", "laser") self.sounds.add("ljudman2.wav", "explosion") self.sounds.bullet.set_volume(0.1) # self.e_pause = thorpy.make_text("Pause - press a key to continue", 20, (255,255,0)) self.e_pause.center(element=self.e_background) # self.scenario = Scenario() self.success = False ## self.options = menus.get_options() self.last_rocket =-10
def __init__(self, name="Unnamed map"): self.name = name self.screen = thorpy.get_screen() self.W, self.H = self.screen.get_size() #self.screen size, wont change self.hmap = None #values below are default values; they can change and # self.refresh_derived_parameters() must be called self.fps = 80 self.box_hmap_margin = 20 #box of the minimap self.menu_width = 200 self.zoom_cell_sizes = [20,16,10] self.world_size = (128,128) self.nframes = 16 #number of different tiles for one material (used for moving water) self.max_wanted_minimap_size = 128 #in pixels. self.show_grid_lines = False # self.chunk = None self.n_octaves = None self.persistance = None self.reverse_hmap = False self.colorscale_hmap = None # self.lm = None self.cam = None #camera, to be built later self.map_rects = None self.zoom_level = 0 self.materials = {} self.material_couples = None self.dynamic_objects = [] self.modified_cells = [] self.object_types = {} ## self.last_cell_clicked = None # self.cursor_color = 0 #0 = normal, 1 = select self.cursors = None self.idx_cursor = 0 self.img_cursor = None self.cursor_slowness = None #gui self.original_img_hmap = None self.e_box = None self.cell_info = None self.unit_info = None ## self.misc_info = None self.e_hmap = None self.box_hmap = None # self.ap = gui.AlertPool() self.e_ap_move = gui.get_infoalert_text("To move the map, drag it with", "<LMB>", "or hold", "<left shift>", "while moving mouse") self.ap.add_alert_countdown(self.e_ap_move, guip.DELAY_HELP * self.fps) # self.map_initializer = None self.game = None self.objects_dict = {}
def fade_to_black_screen(t=1., n=None, color=(0,0,0), target_alpha=255., fps=60): """n = number of steps until black. t = time in secondes until black. Excludes n.""" if n is None: n = int(t * fps) screen = thorpy.get_screen() rect = pygame.Surface(screen.get_size()).convert() rect.fill(color) clock = pygame.time.Clock() for i in range(n+1): alpha = min(int(target_alpha * i / n), 255) rect.set_alpha(alpha) screen.blit(rect, (0,0)) pygame.display.flip() clock.tick(fps)
def __init__(self, nx, ny, cell_size, level, outside_imgs): ## cell_size = material_couples[0].get_cell_size(zoom_level) PygameGrid.__init__(self, int(nx), int(ny), cell_size=(cell_size,)*2, topleft=(0,0)) self.level = level self.outside_imgs = outside_imgs self.cell_size = cell_size for coord in self: self[coord] = GraphicalCell() self.surfaces = None self.nframes = len(self.outside_imgs) # self.submap_size_pix = None self.submap_size_cells = None self.n_submaps = None self.screen_rect = thorpy.get_screen().get_rect() self.colorkey = None self.lm = None
def mainmenu(): W, H = thorpy.functions.get_screen_size() title = graphics.get_title() ## box = thorpy.make_textbox("Credits", text, hline=100) ## box.set_main_color((200,200,200,100)) ## thorpy.launch_blocking(box) e_start = thorpy.make_button("Start game", thorpy.functions.quit_menu_func) e_options, vs = get_options() e_credits = thorpy.make_button("Credits", launch_credits) e_quit = thorpy.make_button("Quit", thorpy.functions.quit_func) space_img = image = thorpy.load_image("Calinou3.png") bck_pos = [0, 0] screen = thorpy.get_screen() def menureac(): if bck_pos[0] - W <= -space_img.get_width(): bck_pos[0] = 0 if bck_pos[1] - H <= -space_img.get_height(): bck_pos[1] = 0 bck_pos[0] -= 0.3 bck_pos[1] -= 0.2 ## bck_pos[1] += sgny * 0.2 screen.blit(space_img, bck_pos) e.blit() pygame.display.flip() e_start.add_reaction( thorpy.ConstantReaction(thorpy.THORPY_EVENT, menureac, {"id": thorpy.constants.EVENT_TIME})) e = thorpy.Ghost.make( elements=[title, e_start, e_options, e_credits, e_quit]) thorpy.store(e) e.center() # m = thorpy.Menu(e, fps=80) m.play() # parameters.SOUND = vs.get_value("sound") parameters.NSMOKE = vs.get_value("smokes") parameters.DEBRIS = vs.get_value("debris")
def launch_end_text(score): screen = thorpy.get_screen() title_text = "The End - Score : " + str(score) + " days" title = thorpy.make_text(title_text, thorpy.style.TITLE_FONT_SIZE, gui.TCOLOR) text = "Your expedition was a success. After that long trip, you are back to civilization. "+\ " Perigeo's compass and seals were undoubtedly recognizable, and their memory will now be teached at school." end_text = "Regarding yourself and your crew, you will be recorded in the centuries to come as the first to complete a round aroud the world.\n"+\ " Which has been proven to be a torus." end_text = thorpy.pack_text(400,end_text) end = thorpy.make_text(end_text, thorpy.style.TITLE_FONT_SIZE, gui.TCOLOR) letter = thorpy.make_text(thorpy.pack_text(int(0.7*parameters.S),text)) w = letter.get_fus_rect().w + 10 boxletter = thorpy.Box.make([letter],(w,parameters.S//2)) boxletter.refresh_lift() thorpy.style.BOX_RADIUS += 10 box = thorpy.make_ok_box([title,boxletter,end],"Quit") box.e_ok.user_func = thorpy.functions.quit_menu_func box.e_ok.user_params = {} box.set_main_color((200,200,255)) box.center() thorpy.style.BOX_RADIUS -= 10 launch(box)
def refresh_and_draw(self): self.hints.blit() hero = parameters.game.hero self.score.set_text("Score: " + str(parameters.game.score)) self.life.blit(thorpy.get_screen(), hero.life / hero.max_life) self.bullets.set_life(hero.bullets / hero.max_bullets) ## self.bullets.blit() self.rockets.set_text("Rockets: " + str(hero.rockets)) ## self.rockets.blit() newlaser = "Laser: " + str(hero.laser) if self.laser.get_text() != newlaser: self.laser.set_text(newlaser) newnuke = "Nuke: " + str(hero.nuke) if self.nuke.get_text() != newnuke: self.nuke.set_text(newnuke) ## self.laser.blit() ## self.nuke.blit() self.br.blit() self.ln.blit() self.score.blit() self.time.set_life(parameters.game.remaining_time) self.time.blit()
def refresh(): pos = pygame.mouse.get_pos() e_ship.set_center(pos) #ship follows mouse # process smoke smokegen1.kill_old_elements() smokegen2.kill_old_elements() pressed = pygame.mouse.get_pressed() if pressed[0]: #left mouse button smokegen1.generate(V2(pos)) elif pressed[2]: #left mouse button smokegen2.generate(V2(pos)) smokegen1.update_physics(V2(0)) smokegen2.update_physics(V2(0)) # process debris debrisgen.kill_old_elements(screen.get_rect()) debrisgen.update_physics(dt=0.1) # refresh screen e_background.blit() debrisgen.draw(thorpy.get_screen()) smokegen1.draw(screen) smokegen2.draw(screen) pygame.display.flip()
def launch_perigeo_text(): screen = thorpy.get_screen() title_text = "Dear visitor,\nI apologize for the welcome, which could have been warmer...\n" title = thorpy.make_text(title_text, thorpy.style.TITLE_FONT_SIZE, gui.TCOLOR) text = "But the crew's death does not help. I tried my best to prove that the world is toroidal."+\ " According to the theory, my ship has gone beyond the half-perimeter, and we still did not recognize any of the landscapes"+\ " that some of us saw as members of former Settentrio's expeditions. As a result, I am convinced of the toroidal nature of the world."+\ " As a proof of my presence so far on the East - well, it is actually the West side of the world now - let my bones on the wild. But..." end_text = "... bring my compass and my seal back to civilization, and show them that I was right.\n Gottfried Perigeo" end_text = thorpy.pack_text(400,end_text) end = thorpy.make_text(end_text, thorpy.style.TITLE_FONT_SIZE, gui.TCOLOR) letter = thorpy.make_text(thorpy.pack_text(int(0.7*parameters.S),text)) w = letter.get_fus_rect().w + 10 boxletter = thorpy.Box.make([letter],(w,parameters.S//2)) boxletter.refresh_lift() thorpy.style.BOX_RADIUS += 10 box = thorpy.make_ok_box([title,boxletter,end],"Accept") box.e_ok.user_func = thorpy.functions.quit_menu_func box.e_ok.user_params = {} box.set_main_color((200,200,255)) box.center() thorpy.style.BOX_RADIUS -= 10 launch(box)
def __init__(self): self.players = None self.light = None self.objs = [] self.hero = None self.track = None self.opponents = None self.cam = None self.screen = thorpy.get_screen() self.screen_rect = self.screen.get_rect().move((0,parameters.H//2)) self.i = 0 #frame self.vessels = [] self.background = thorpy.load_image(parameters.BACKGROUNDS[parameters.CURRENT_QUALITY]) self.background = thorpy.get_resized_image(self.background, (parameters.W,parameters.H//2), type_=max) self.hud = hud.HUD() self.debris = [] ## self.background = pygame.transform.smoothscale(self.background, (parameters.W,parameters.H//2)) self.start_i = 5 self.start_delay = 10 + int(random.random()*1000)//40 self.ranking = [] self.hero_dead = None self.abandon = False
def launch_load_game(game, show): show_loading() thorpy.get_screen().fill((255, 255, 255)) import os, savemanager files = [f for f in os.listdir("./") if f.endswith(".dat")] savelist = [] class Choice: value = None def delete(): Choice.value = "del" def cancel_func(): Choice.value = "cancel" def load(filename): thorpy.launch_blocking_choices("What do you want to do ?", [("Load", None), ("Delete", delete), ("Cancel", cancel_func)]) if not Choice.value: game.savefile = filename thorpy.functions.quit_menu_func() thorpy.functions.quit_menu_func() else: if Choice.value == "del": if thorpy.launch_binary_choice(" Are you sure? \n\n"): os.remove(filename) thorpy.functions.quit_menu_func() else: thorpy.get_screen().fill((255, 255, 255)) frame.blit() pygame.display.flip() for f in files: date, size, epochtime, score = savemanager.get_infos(f) success = "" if float(score) > 0: success = "\n*** Game successfully ended at day " + str( int(score)) + " ***" ## infos.append(epochtime, date, size, f) b = thorpy.make_button(date + "\n" + "World size: " + size + success, load, {"filename": f}) savelist.append((epochtime, b)) savelist.sort(key=lambda x: x[0], reverse=True) elist = [e for t, e in savelist] thorpy.style.BOX_RADIUS += 10 box = thorpy.Box.make(elist, (int(0.6 * parameters.S), int(0.8 * parameters.S))) box.refresh_lift() thorpy.style.BOX_RADIUS -= 10 title = thorpy.make_text("Load game", font_size=thorpy.style.FONT_SIZE + 3, font_color=TCOLOR) cancel = thorpy.make_button("Cancel", thorpy.functions.quit_menu_func) frame = thorpy.Element.make(elements=[title, box, cancel]) thorpy.store(frame) frame.center() pygame.display.flip() m = thorpy.Menu(frame) m.play() # show() pygame.display.flip()
def draw(self): if self.visible: thorpy.get_screen().blit(graphics.rocket_img, self.pos) if parameters.DEBRIS: graphics.fire_gen.generate(self.pos + self.smokedelta)
def draw(self): if self.visible: thorpy.get_screen().blit(graphics.bullet_img, self.pos)
def __init__(self, game, time_remaining=-1): game.update_loading_bar("Building gui elements", 0.95) self.game = game game.gui = self # self.font_colors_mat = {} for m in self.game.me.materials: n = m.lower() if "snow" in n or "sand" in n: self.font_colors_mat[m] = (0, ) * 3 else: self.font_colors_mat[m] = (255, ) * 3 # self.surface = thorpy.get_screen() game.me.cam.ui_manager = self self.me = game.me self._debug = True self.enhancer = GuiGraphicsEnhancement( self, zoom=0, #work only for a given zoom level splashes=True, footprints=True) # self.last_destination_score = {} self.destinations_mousemotion = [] self.destinations_lmb = [] self.forced_gotocell = False self.selected_unit = None self.cell_under_cursor = None self.blue_highlights = [] self.red_highlights = [] # self.color_dest_lmb = (255, 0, 0) self.color_dest_mousemotion = (255, 255, 0) self.dest_alpha_amplitude = 20 self.dest_alpha0 = 100 self.dest_period = self.me.lm.nframes * 3. self.dest_omega = 2. * math.pi / self.dest_period # self.e_cant_move = guip.get_infoalert_text("Can't go there") self.e_cant_move_another = guip.get_infoalert_text( "Another unit is already going there") self.e_wrong_team = guip.get_infoalert_text( "You cannot command another player's units") self.e_already_moved = guip.get_infoalert_text( "This unit has already moved in this turn") # self.moving_units = [] self.add_reactions() self.life_font_size = guip.NFS self.life_font_color = (255, 255, 255) self.font_life = pygame.font.SysFont(guip.font_gui_life, self.life_font_size) self.show_lifes = True self.interaction_objs = [] # #here you can add/remove buttons to/from the menu e_options = thorpy.make_button("Options", self.show_options) e_save = thorpy.make_button("Save", io.ask_save, {"me": self.me}) e_load = thorpy.make_button("Load", io.ask_load) e_quit = thorpy.make_button("Quit game", quit_func) self.menu = thorpy.make_ok_box( [get_help_box().launcher, e_options, e_save, e_load, e_quit]) self.menu.center() self.set_map_gui() e_ap_cancel_move = elements.get_infoalert_text( "To cancel last move, press", "<RETURN>") self.me.alert_elements.append(e_ap_cancel_move) self.me.ap.add_alert_countdown(e_ap_cancel_move, guip.DELAY_HELP * self.me.fps) self.has_moved = [] # self.e_add = { key: thorpy.make_button("+") for key in ["left", "right", "top", "down"] } self.e_rem = { key: thorpy.make_button("-") for key in ["left", "right", "top", "down"] } self.last_move = None
def __init__(self, cam, wind, climate, element): summer = Season( "Summer", colorscale.get_summer(), parameters.SUMMER_LEVEL, 2, "Summer comes in 5 days.\nHigh temperatures are back again, and ices will melt." ) winter = Season( "Winter", colorscale.get_winter(), parameters.WINTER_LEVEL, -20, "Winter comes in 5 days.\nBe sure that the ship is far from the lands, or it will become captive of the ices" ) self.clouds = [] for i in range(3): img = thorpy.load_image("clouds" + str(i) + ".png", (0, 0, 0)) img.set_alpha(parameters.CLOUD_ALPHA) self.clouds.append(img) #characters a = Character("Astronomer", parameters.A_COLOR) a.death_text = "Without astronomer, we won't know our position anymore..." h = Character("Hunter", parameters.H_COLOR) h.hunting = 0.6 h.death_text = "Without hunter, we will have troubles in finding extra food..." c = Character("Captain", parameters.C_COLOR) c.ship_skill = 0.5 c.death_text = "Without captain, the ship will be slower and weaker against rocks..." # self.save = None self.saved = False self.a, self.h, self.c = a, h, c self.cam = cam self.wind = wind self.climate = climate self.screen = thorpy.get_screen() self.element = element self.peaks = {} self.cam.game = self self.gui_pos = np.zeros(2) self.campos = np.array( [float(self.cam.pos[0]), float(self.cam.pos[1])]) self.ship = None self.input_direction = Vector2() self.direction = False self.i = 0 self.tx, self.ty = None, None self.controlled = None self.controllables = None self.last_key_action = 0 self.current_wind_draw = None self.height = 0 self.alt_text = 0 self.temp = 0 self.temp_pix = 0 self.temp_text = 0 self.day = 0 gui.set_game_gui(self, compass_pos, compass, thermo_pos, thermo) #declare attributes self.pos_int = Vector2() # self.refresh_ship_life = True self.stats = Statistics(self) self.can_board = False self.near_village = None self.near_camp = None self.near_forest = None self.can_flag = False ## self.villages = {(0,0):Village((houses[0],houses[1]),Vector2(100,100),12)} self.villages = [] self.oasises = [] ## self.firs = [] self.monitor = gui.AlertMonitor(self) self.aboard = True self.swimming = False self.flags = [] self.near_flag = None self.journal = Journal(self) self.living_chars = list(self.chars()) self.building_map = False self.collision_factor = 0. self.collision_factor_summer = 0. self.can_camp = False self.ncamps = 0 self.infinite_stock = FoodStock(100000000000) self.infinite_stock.food = 1000000000 self.side = 0 # self.storm = None self.storm_duration = 0 self.storms = np.random.randint(2, 10000, 400).tolist() ## self.storms[0] = 1 self.rain = fx.Rain(self, 150) self.snow = fx.Rain(self, 150, thorpy.load_image("snowflake.png", (0, 0, 0))) self.falls = self.rain self.seasons = [summer, winter] self.season_idx = 0 self.set_season(self.season_idx) self.next_season = parameters.SEASON_MOD_DAYS self.instructions = instructions self.does_perigeo = False self.score = -1 # self.n_hunt = parameters._INIT_N_HUNT self.is_winter = False self.treasures = [] self.treasures_taken = [] self.treasures_put = [] self.near_treasure = None self.waiting = False
SEED = 66 ##SEED = 0 S = terrain.S parameters.set_S(S) METADATA_PATH = "./metadata" #create a file for storing data on application mdm = thorpy.MetaDataManager() mdm.read_data(METADATA_PATH) app = thorpy.Application((S,S)) mdm.load_font_data(METADATA_PATH) gui.show_loading() gui.playing() #set key delay thorpy.set_theme("human") screen = thorpy.get_screen() e_bckgr = thorpy.Ghost.make() sound.play_random_music() terrain.cache() savefile=gui.launch_main_menu() #xxx climate = terrain.Climate(0) if savefile: gui.show_loading() sm = savemanager.SaveManager(savefile) SEED = int(sm.d["cam"]["seed"]) sm.load_parameters() Camtype=parameters.get_camera_type() cam = Camtype(chunk=(0,0), pos=(0,0), seed=SEED,
def __init__(self, title, ok_text, ranking, results=False, choosevessel=False): refresh_ranking() # light_pos = V3(0, 1000, -1000) light_m = V3(20, 20, 20) light_M = V3(200, 200, 200) self.light = light.Light(light_pos, light_m, light_M) self.viewport = pygame.Surface((400, int(parameters.H * 0.6))) self.viewport_color = (200, 200, 200) self.viewport.fill(self.viewport_color) self.viewport_rect = pygame.Rect((0, 0), self.viewport.get_size()) self.viewport_rect.centerx = parameters.W // 2 + 100 self.viewport_rect.centery = parameters.H // 2 self.cam = camera.Camera(self.viewport, fov=512, d=2, objs=[]) self.screen = thorpy.get_screen() self.displayed_vessel = None self.i = 0 # if results: ranking[0].points += 1 ranking[0].money += 300 + (parameters.NPLAYERS - ranking[0].ranking) * 100 ranking[2].points -= 1 ranking[2].money += 100 ranking[1].money += 200 if ranking[2].points < 0: ranking[2].points = 0 # self.trophy = None if choosevessel: self.e_players = [] def other_vessel(): self.vessels[0] = create_vessel(parameters.HERO_COLOR) self.vessels[0].set_pos(V3(0, -1 * 4.5, 20)) self.vessels[0].move(V3(0, 4, 0)) self.displayed_vessel = self.vessels[0] #replace self.ve new_ve = get_vessel_element(self.vessels[0]) self.e_bckgr.replace_element(self.ve, new_ve) thorpy.functions.refresh_current_menu() self.ve = new_ve self.e_bckgr.unblit_and_reblit() b = thorpy.make_button("Generate another vessel", other_vessel) c = thorpy.make_button("Done", thorpy.functions.quit_menu_func) self.e_players.append(b) self.e_players.append(c) from main import create_vessel self.vessels = [create_vessel(parameters.HERO_COLOR)] self.displayed_vessel = self.vessels[0].get_copy() self.ve = get_vessel_element(self.vessels[0]) self.e_players.append(self.ve) else: if results: self.e_players = [ p.get_element(str(i + 1) + ") ") for i, p in enumerate(ranking) ] else: self.e_players = [ p.get_element() for i, p in enumerate(ranking) ] self.vessels = [p.vessel.get_copy() for p in ranking] if results: import core3d from light import Material self.trophy = core3d.Object3D("trophy1.stl") self.trophy.set_color(Material((255, 215, 0))) ## self.trophy.set_color((255,255,0)) self.trophy.set_pos(V3(5., -0 * 4.5 - 0.2, 15)) self.trophy.rotate_around_center_z(90.) self.trophy.rotate_around_center_x(-65.) self.trophy.move(V3(0, 4, 0)) self.background = thorpy.load_image("background1.jpg") self.background = thorpy.get_resized_image( self.background, (parameters.W, parameters.H // 2), type_=max) self.e_bckgr = thorpy.Background.make(image=self.background, elements=self.e_players) # vw, vh = self.viewport_rect.size self.e_viewport_frame = thorpy.Element() painter = thorpy.painterstyle.ClassicFrame((vw + 3, vh + 3), color=self.viewport_color, pressed=True) self.e_viewport_frame.set_painter(painter) self.e_viewport_frame.finish() self.e_viewport_frame.set_center(self.viewport_rect.center) # reaction = thorpy.ConstantReaction(thorpy.THORPY_EVENT, self.refresh_display, {"id": thorpy.constants.EVENT_TIME}) self.e_bckgr.add_reaction(reaction) if not choosevessel: for i, v in enumerate(self.vessels): pos = self.e_players[i].get_fus_rect().center v.set_pos(V3(0, -i * 4.5, 20)) v.move(V3(0, 4, 0)) else: self.vessels[0].set_pos(V3(0, -1 * 4.5, 20)) self.vessels[0].move(V3(0, 4, 0)) # self.displayed_vessel.set_pos(V3(0, -1 * 4.5, 20)) self.displayed_vessel.move(V3(0, 4, 0)) # thorpy.store(self.e_bckgr, gap=40) for e in self.e_players: e.stick_to(self.viewport_rect, "left", "right", align=False) e.move((-5, 0)) self.e_title = get_etitle(title) if not choosevessel: self.e_ok = get_eok(ok_text) self.e_bckgr.add_elements( [self.e_viewport_frame, self.e_title, self.e_ok]) else: self.e_bckgr.add_elements([self.e_viewport_frame, self.e_title]) self.goback = False def return_garage(): self.derotate() self.goback = True thorpy.functions.quit_menu_func() if not results and not choosevessel: self.e_back = thorpy.make_button("Return to garage", return_garage) self.e_back.stick_to(self.e_ok, "left", "right") self.e_back.move((-20, 0)) self.e_bckgr.add_elements([self.e_back]) if not results: reaction = thorpy.Reaction(pygame.MOUSEMOTION, self.mousemotion) self.e_bckgr.add_reaction(reaction) m = thorpy.Menu(self.e_bckgr) m.play()
def launch_main_menu(): np.random.seed() from colorscale import get_summer terrain.DEEP_CONSTANT = 4 if parameters.BISURFACE: camtype = terrain.CameraBisurface else: camtype = terrain.Camera cam = camtype(chunk=(100, 100), pos=(0, 0), seed=np.random.randint(0, 1000), world_size=(2, 2)) if parameters.BISURFACE: cam.iter_ship = parameters.nothing class FakeGame: def __init__(self): self.villages = [] self.try_building_village = self.n self.try_building_oasis = self.n self.try_putting_treasure = self.n self.try_building_firs = self.n self.clouds = [] self.storm = False self.is_winter = False self.savefile = None class FakeControlled: def __init__(self): self.velocity = -Vector2(0.1, 0.1) self.controlled = FakeControlled() def n(self, a, b): pass cam.game = FakeGame() game = cam.game for i in range(3): img = thorpy.load_image("clouds" + str(i) + ".png", (0, 0, 0)) img.set_alpha(parameters.CLOUD_ALPHA) game.clouds.append(img) cam.set_colorscale(get_summer()) screen = thorpy.get_screen() show_loading() ## tmp = parameters.REFLECT ## parameters.REFLECT = False class Pos: pos = np.zeros(2) def show(): if parameters.BISURFACE: cam.iter_clouds() cam.show(screen) etitle.solo_blit() box.blit() pygame.display.flip() Pos.pos += (0.4, 0.4) cam.pos = np.array(Pos.pos, dtype=int) # def launch_credits(): text = "Author: Yann Thorimbert ([email protected])\n"+\ "Libraries used: NumPy, Pygame, ThorPy (www.thorpy.org)\n\n"+\ "If you are interested in the procedural world generation technique used in this game, please do not hesitate to contact the author." text = thorpy.pack_text(int(0.8 * parameters.S), text) thorpy.launch_blocking_alert(text) etitle = thorpy.make_text("The Torus", font_size=2 * thorpy.style.TITLE_FONT_SIZE, font_color=(0, 0, 100)) etitle.stick_to("screen", "top", "top") etitle.move((0, 30)) eplay = thorpy.make_button("New Game", func=thorpy.functions.quit_menu_func) eload = thorpy.make_button("Load game", launch_load_game, { "game": game, "show": show }) eoptions, memory = get_options() ecredits = thorpy.make_button("Credits", launch_credits) equit = thorpy.make_button("Quit", func=thorpy.functions.quit_func) box = thorpy.Box.make([eplay, eload, eoptions, ecredits, equit]) box.add_reaction(thorpy.ConstantReaction(thorpy.USEREVENT + 2, show)) box.center() box.set_main_color((200, 200, 255, 150)) eoptions.user_func = launch_options eoptions.user_params = {"game": None, "epause": box, "mainmenu": True} m = thorpy.Menu(box, fps=parameters.FPS) show() pygame.time.set_timer(thorpy.USEREVENT + 2, 1000 // parameters.FPS) m.play() pygame.time.set_timer(thorpy.USEREVENT + 2, 0) terrain.DEEP_CONSTANT = 1 parameters.set_approx_memory_usage(memory.get_value()) #in MB ## if parameters.REFLECT != tmp: #may have been changed ## if not parameters.REFLECT: ## parameters.REFLECT = True return game.savefile
def __init__(self): ## if not parameters.canonic_vessels: ## get_all_parts() self.vessel = parameters.player.vessel.get_copy() self.ovessel = parameters.player.vessel self.screen = thorpy.get_screen() # light_pos = V3(0,1000,-1000) light_m = V3(20,20,20) light_M = V3(200,200,200) self.light = light.Light(light_pos, light_m, light_M) # self.e_bckgr = thorpy.Background.make((255,255,255)) self.vessel.set_pos(parameters.GARAGE_POS) reaction = thorpy.ConstantReaction(thorpy.THORPY_EVENT, self.refresh_display, {"id":thorpy.constants.EVENT_TIME}) self.e_bckgr.add_reaction(reaction) reaction = thorpy.Reaction(pygame.MOUSEMOTION, self.mousemotion) self.e_bckgr.add_reaction(reaction) # self.viewport = pygame.Surface((400,400)) self.viewport_color = (200,200,200) self.viewport_rect = pygame.Rect((0,0),self.viewport.get_size()) self.viewport_rect.right = parameters.W - 20 self.viewport_rect.centery = parameters.H//2 self.cam = camera.Camera(self.viewport, fov=512, d=2, objs=[]) # # # self.e_ok = thorpy.make_button("Go to next race", func=thorpy.functions.quit_menu_func) self.e_ok.set_main_color((0,255,0)) self.e_ok.set_font_size(thorpy.style.FONT_SIZE+3) self.e_ok.scale_to_title() # # def refresh_repair(): damages = str(round(100.*(1. - self.ovessel.life/self.ovessel.max_life))) self.e_damage.set_text("Vessel damages: " + damages + "%") self.e_money.set_text("Money: "+str(parameters.player.money)+" $") def choice_repair(): cost = (self.ovessel.max_life - self.ovessel.life)*300 if cost <= parameters.player.money: if thorpy.launch_binary_choice("Are you sure? This will cost "+\ str(cost)+"$"): self.ovessel.life = self.ovessel.max_life parameters.player.money -= cost refresh_repair() elif thorpy.launch_binary_choice("Repairing costs "+str(cost)+\ " $. You don't have enough money.\n"+\ "Do you want to use all your money for"+\ " repairing as much as possible?"): #(after_repair - self.ovessel.life)*300 = money #==> after_repair = money/300 + self.ovessel.life repaired = int(parameters.player.money/300. + self.ovessel.life) parameters.player.money -= (repaired - self.ovessel.life)*300 self.ovessel.life = repaired refresh_repair() self.e_bckgr.blit() self.refresh_display() pygame.display.flip() self.e_repair = thorpy.make_button("Repair vessel",choice_repair) # damages = str(round(100.*(1. - self.ovessel.life/self.ovessel.max_life))) self.e_damage = thorpy.make_text("Vessel damages: " + damages + "%") self.e_ranking = thorpy.make_button("See rankings", launch_rankings, {"garage":self}) ## self.e_ranking = get_rankings_box() def quit_forever(): if thorpy.launch_binary_choice("Are you sure ?"): thorpy.functions.quit_func() else: self.e_bckgr.unblit_and_reblit() self.e_menu = thorpy.make_button("Stop career and die (forever)", func=quit_forever) self.e_menu.set_main_color((255,0,0)) self.e_menu.set_font_size(thorpy.style.FONT_SIZE-2) self.e_menu.scale_to_title() # vw,vh = self.viewport_rect.size self.e_viewport_frame = thorpy.Element() painter = thorpy.painterstyle.ClassicFrame((vw+3,vh+3), color=self.viewport_color, pressed=True) self.e_viewport_frame.set_painter(painter) self.e_viewport_frame.finish() self.e_viewport_frame.set_center(self.viewport_rect.center) # import hud fuel = str(round(100*self.ovessel.engine.fuel/self.ovessel.engine.max_fuel)) self.e_fuel = hud.LifeBar("Fuel: "+fuel+" %",text_color=(255,0,0),size=(100,30)) self.e_fuel.set_life(self.ovessel.engine.fuel/self.ovessel.engine.max_fuel) def refresh_refuel(): life = self.ovessel.engine.fuel / self.ovessel.engine.max_fuel self.e_fuel.set_life(life) self.e_fuel.set_text("Fuel: "+str(round(life*100))+" %") self.e_money.set_text("Money: "+str(parameters.player.money)+" $") def choice_refuel(): cost = (self.ovessel.engine.max_fuel - self.ovessel.engine.fuel)//2 if cost <= parameters.player.money: if thorpy.launch_binary_choice("Are you sure? This will cost "+\ str(cost)+"$"): self.ovessel.engine.fuel = self.ovessel.engine.max_fuel parameters.player.money -= cost refresh_refuel() ## self.e_fuel.set_life(1.) ## self.e_fuel.set_life_text("Fuel: 100 %") ## parameters.player.money -= cost ## self.e_money.set_text("Money: "+str(parameters.player.money)+" $") ## self.ovessel.engine.fuel = self.ovessel.engine.max_fuel elif thorpy.launch_binary_choice("Refueling costs "+str(cost)+" $. You don't have enough money.\n"+\ "Do you want to spend all your money to refuel as much as possible?"): #cost = (newfuel - fuel)//2 ==> 2*cost + fuel = newfuel self.ovessel.engine.fuel += 2*parameters.player.money parameters.player.money = 0 refresh_refuel() ## thorpy.launch_blocking_alert("Refueling costs "+str(cost)+" $. You don't have enough money.") self.e_bckgr.blit() self.refresh_display() pygame.display.flip() self.e_refuel = thorpy.make_button("Refuel",choice_refuel) self.e_money = thorpy.make_text("Money: "+str(parameters.player.money)+" $", thorpy.style.TITLE_FONT_SIZE,(255,0,0)) self.e_money.stick_to("screen","top","top") self.e_money.move((0,30)) # self.e_box = thorpy.Box.make([self.e_damage,self.e_repair, thorpy.Line.make(100,"h"),self.e_fuel, self.e_refuel, thorpy.Line.make(100,"h"), self.e_ranking,self.e_ok]) self.e_bckgr.add_elements([self.e_box,self.e_menu]) thorpy.store(self.e_bckgr, x = 200) self.e_skills = get_vessel_element(parameters.player.vessel) self.e_bckgr.add_elements([self.e_viewport_frame,self.e_money, self.e_skills]) self.e_menu.move((0,30)) self.e_skills.stick_to(self.e_viewport_frame, "left", "right") self.i = 0
def buy_part(parent): background = thorpy.load_image("background_garage.jpg") background = thorpy.get_resized_image(background, (parameters.W,parameters.H), type_=max) thorpy.get_screen().blit(background,(0,0)) pygame.display.flip() title = thorpy.make_text("Vessel merchant", thorpy.style.TITLE_FONT_SIZE+4, (255,0,0)) hbar = thorpy.Line.make(200, "h") intro = "Hello, "+str(parameters.player.name)+"."+\ "\nHere is what I have to sell today:" intro = thorpy.make_text(intro, thorpy.style.TITLE_FONT_SIZE, thorpy.style.TITLE_FONT_COLOR) # money = thorpy.Element(thorpy.pack_text(200,"Your money: "+str(parameters.player.money)+" $.")) money.set_painter(thorpy.functions.obtain_valid_painter(thorpy.painterstyle.DEF_PAINTER, pressed=True)) money.finish() money.scale_to_title() # info = thorpy.Element(thorpy.pack_text(200,"Remember that any part you buy will replace your current one.")) info.set_painter(thorpy.functions.obtain_valid_painter(thorpy.painterstyle.DEF_PAINTER, pressed=True)) info.finish() info.scale_to_title() money_info = thorpy.Ghost.make([info, money]) thorpy.store(money_info, mode="h") money_info.fit_children() # part1, skills1, price1 = get_random_element() part2, skills2, price2 = get_random_element() choices = thorpy.Ghost.make(elements=[part1,part2]) thorpy.store(choices, mode="h") choices.fit_children() cancel = thorpy.make_button("No, thanks", thorpy.functions.quit_menu_func) # def buy(part, cost): if cost > parameters.player.money: thorpy.launch_blocking_alert("Not enough money", "You don't have enough money to buy this part.",transp=False) box.unblit_and_reblit() else: parameters.player.money -= cost name = part.pop(0) if name == "wings": parts = [getattr(parameters.player.vessel, "lwing"), getattr(parameters.player.vessel, "rwing")] else: parts = [getattr(parameters.player.vessel, name)] for part_obj in parts: for skillname, factor in part: if skillname == "agility": skillname = "turn" elif skillname == "power": parameters.player.vessel.engine_force *= (1.+factor) elif skillname == "max_fuel": parameters.player.vessel.engine.max_fuel *= (1.+factor) elif skillname == "mass": parameters.player.vessel.engine_force *= parameters.player.vessel.mass parameters.player.vessel.mass *= (1.+factor) parameters.player.vessel.engine_force /= parameters.player.vessel.mass parameters.player.vessel.max_life = int(parameters.player.vessel.mass * parameters.LIFE_FACTOR) else: current_value = getattr(parameters.player.vessel, skillname) new_value = current_value + factor*current_value/6. setattr(parameters.player.vessel, skillname, new_value) thorpy.functions.quit_menu_func() part1.e_ok.user_func = buy part1.e_ok.user_params = {"part":skills1, "cost":price1} part2.e_ok.user_func = buy part2.e_ok.user_params = {"part":skills2, "cost":price2} # box = thorpy.Box.make([title,hbar,intro,money_info,choices,cancel]) box.center() thorpy.launch_blocking(box)