def __init__(self, player_name, min_val, max_val, trials): #init some parameters of the game ... self.player_name = player_name self.min_val = min_val #the minimum value to guess self.max_val = max_val #the maximum value to guess self.init_trials = trials #keep the original trials amount in memory self.trials = trials #remaining number of trials #the number to guess: self.number = random.randint(self.min_val, self.max_val) self.guess = None #the current player guess self.e_quit = thorpy.make_button("Quit", func=thorpy.functions.quit_menu_func) self.e_restart = thorpy.make_button("Restart", func=self.restart) #a ghost for storing quit and restart: self.e_group_menu = thorpy.make_group([self.e_quit, self.e_restart]) #a counter displaying the trials and some hint/infos about the game self.e_counter = thorpy.make_text(text=self.get_trials_text(), font_color=(0, 0, 255)) #the inserter element in which player can insert his guess self.e_insert = thorpy.Inserter(name="Try:") self.e_background = thorpy.Background( color=(200, 200, 255), elements=[self.e_counter, self.e_insert, self.e_group_menu]) thorpy.store(self.e_background, gap=20) #reaction called each time the player has inserted something reaction_insert = thorpy.ConstantReaction( reacts_to=thorpy.constants.THORPY_EVENT, reac_func=self.reac_insert_func, event_args={ "id": thorpy.constants.EVENT_INSERT, "el": self.e_insert }) self.e_background.add_reaction(reaction_insert)
def _initialize(self): self.reac_keydown = thorpy.Reaction(pygame.KEYDOWN, self.func_keydown) self.e.add_reaction(self.reac_keydown) # self.reac_time = thorpy.ConstantReaction( thorpy.constants.THORPY_EVENT, self.func_time, {"id": thorpy.constants.EVENT_TIME}) self.e.add_reaction(self.reac_time)
def my_func_reaction1(el, reac_1): new_reaction = thorpy.ConstantReaction(reacts_to=pygame.MOUSEBUTTONDOWN, reac_func=my_func_reaction2) el.remove_reaction(reac_1) el.add_reaction(new_reaction) thorpy.functions.refresh_current_menu() #tell menu to refresh reactions! info_text.set_text("Reaction 1 will never be launched again") info_text.center() background.unblit_and_reblit() print("reaction 1 launched - replacing reac 1 by reac 2")
def __init__(self, game): self.game = game self.game.gui = self self.e_chars = {c: None for c in self.game.chars()} # import scenario def l_func_after(): ## self.game.element.blit() self.game.cam.show(self.game.screen) self.game.blit_things() self.e_pause.blit() pygame.display.flip() def launch_stats(): scenario.launch(self.get_stats(), l_func_after) def save_game(): game.autosave() thorpy.launch_blocking_alert("Game saved") l_func_after() self.e_controls = thorpy.make_button("See instructions", scenario.launch, { "e": game, "func": l_func_after }) # self.e_save = thorpy.make_button("Save game", save_game) self.e_stats = thorpy.make_button("Statistics", launch_stats) self.e_options = thorpy.make_button("Options", launch_options) # self.e_pause = thorpy.make_ok_cancel_box( [self.e_controls, self.e_save, self.e_stats, self.e_options], "Continue game", "Quit game") # self.pause_launcher = thorpy.get_launcher(self.e_pause, launching=game.element) self.e_options.user_params = {"game": game, "epause": self.e_pause} reac_esc = thorpy.ConstantReaction(pygame.KEYDOWN, self.pause_launcher.launch, {"key": pygame.K_ESCAPE}) self.game.element.add_reaction(reac_esc) self.e_pause.set_main_color((200, 200, 255, 100)) def quit_game(): thorpy.launch_blocking_choices( "This will quit the game. Make sure you saved the game.", [("Ok", thorpy.functions.quit_func), ("Cancel", None)]) l_func_after() self.e_pause.e_cancel.user_func = quit_game self.e_pause.e_cancel.user_params = {}
def add_reactions(self): reac_click = thorpy.Reaction(pygame.MOUSEBUTTONDOWN, self.lmb, {"button": 1}) self.me.e_box.add_reaction(reac_click) reac_click = thorpy.Reaction(pygame.MOUSEBUTTONDOWN, self.rmb, {"button": 3}) self.me.e_box.add_reaction(reac_click) reac_motion = thorpy.Reaction(pygame.MOUSEMOTION, self.mousemotion) self.me.e_box.add_reaction(reac_motion) ## reac_escape = thorpy.ConstantReaction(pygame.KEYDOWN, self.esc_menu, {"key":pygame.K_ESCAPE}) ## self.me.e_box.add_reaction(reac_escape) shortcuts = [(pygame.K_l, self.toggle_show_life), (pygame.K_ESCAPE, self.launch_map_menu), (pygame.K_PERIOD, self.find_free_unit), (pygame.K_BACKSPACE, self.cancel)] reacs = [] for key, func in shortcuts: reacs.append( thorpy.ConstantReaction(pygame.KEYDOWN, func, {"key": key})) self.me.e_box.add_reactions(reacs)
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")
sm.load_parameters() Camtype=parameters.get_camera_type() cam = Camtype(chunk=(0,0), pos=(0,0), seed=SEED, world_size=parameters.WORLD_SIZE) core.load_images() core.compute_parameters() wind = Wind((-1.,-1.),(1.,1.),(-1., -1.),(1.,1.),(10000,10000)) game = core.Game(cam, wind, climate, e_bckgr) game.set_ship(Ship(mass=0.3, maxvel=3., life=1., captain=None)) game.refresh_controllables() reac_time = thorpy.ConstantReaction(thorpy.constants.THORPY_EVENT, game.reac_time, {"id":thorpy.constants.EVENT_TIME}) reac_keydown = thorpy.Reaction(pygame.KEYDOWN, game.reac_keydown) e_bckgr.add_reaction(reac_keydown) e_bckgr.add_reaction(reac_time) gu = gui.GUI(game) if not savefile: #configure new game varset = gui.game_parameters_menu() # #difficulty : TREASURE_PROB, MAX_FLAG, FOOD_PER_TURN, MAX_CAMPS, OASIS_PROB difficulties = {"easy":(1., 10, 1, 5, 1.), "medium":(0.8, 5, 1, 3, 0.8), "hard":(0.4, 3, 1, 1, 0.7)} seed = varset.get_value("seed")
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
max_size=10) e_ship = thorpy.Image("../documentation/examples/boat_example.png", colorkey=(255, 255, 255)) if thorpy.constants.CAN_SHADOWS: #set shadow thorpy.makeup.add_static_shadow( e_ship, { "target_altitude": 5, "shadow_radius": 3, "sun_angle": 40, "alpha_factor": 0.6 }) e_background = thorpy.Background(image=thorpy.style.EXAMPLE_IMG, elements=[e_ship]) reac_time = thorpy.ConstantReaction(thorpy.constants.THORPY_EVENT, refresh, {"id": thorpy.constants.EVENT_TIME}) reac_space = thorpy.ConstantReaction(pygame.KEYDOWN, make_debris, {"key": pygame.K_SPACE}) e_background.add_reactions([reac_time, reac_space]) screen = thorpy.get_screen() infotext = "Press SPACE to spawn debris\n"+\ "LMB and RMB to spawn smokes\n"+\ "and move the mouse to move the boat." thorpy.launch_blocking_alert("Commands", infotext) menu = thorpy.Menu(e_background) pygame.key.set_repeat(30, 30) menu.play() app.quit()
"Remaining time", color=(255, 165, 0), text_color=(0, 0, 0), size=(200, 30), font_size=None, #keep default one type_="h") #h or v bar.center() counter = 0 def event_time(): global counter if counter % 4 == 0: life = min(1., counter / 500.) bar.set_life(life) bar.set_text(str(counter)) bar.unblit_and_reblit() if counter < 500: counter += 1 bar.add_reaction( thorpy.ConstantReaction(thorpy.THORPY_EVENT, event_time, {"id": thorpy.constants.EVENT_TIME})) menu = thorpy.Menu(bar) menu.play() application.quit()
new_reaction = thorpy.ConstantReaction(reacts_to=pygame.MOUSEBUTTONDOWN, reac_func=my_func_reaction2) el.remove_reaction(reac_1) el.add_reaction(new_reaction) thorpy.functions.refresh_current_menu() #tell menu to refresh reactions! info_text.set_text("Reaction 1 will never be launched again") info_text.center() background.unblit_and_reblit() print("reaction 1 launched - replacing reac 1 by reac 2") application = thorpy.Application(size=(300, 300), caption="Reaction tuto") info_text = thorpy.make_text("No reaction launched") info_text.center() background = thorpy.Background(elements=[info_text], color=(255, 255, 255)) reac_1 = thorpy.ConstantReaction(reacts_to=pygame.MOUSEBUTTONDOWN, reac_func=my_func_reaction1, params={ "el": background, "reac_1": None }) reac_1.params["reac_1"] = reac_1 background.add_reaction(reac_1) menu = thorpy.Menu(background) menu.play() application.quit()
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 build_gui_elements(self): #worst function ever e_hmap = thorpy.Image.make(self.cam.img_hmap) e_hmap.stick_to("screen", "right", "right", False) e_hmap.add_reaction(thorpy.Reaction(pygame.MOUSEMOTION, self.func_reac_mousemotion)) e_hmap.add_reaction(thorpy.Reaction(pygame.MOUSEBUTTONDOWN, self.func_reac_click)) e_hmap.add_reaction(thorpy.Reaction(pygame.MOUSEBUTTONUP, self.func_reac_unclick)) self.e_hmap = e_hmap box_hmap = thorpy.Box.make([e_hmap]) box_hmap.fit_children((self.box_hmap_margin,)*2) thorpy.makeup.add_basic_help(box_hmap, "Click to move camera on miniature map") ## e_title_hmap = guip.get_text("Map") ## self.topbox = thorpy.make_group([e_title_hmap, box_hmap], "v") self.topbox = box_hmap self.box_hmap = box_hmap ######################################################################## self.cam.set_gui_elements(e_hmap, box_hmap) ######################################################################## if len(self.zoom_cell_sizes) > 1: self.e_zoom = thorpy.SliderX.make(self.menu_width//4, (0, 100), "Zoom (%)", int, initial_value=100) def func_reac_zoom(e): levels = len(self.zoom_cell_sizes) - 1 level = int(levels*self.e_zoom.get_value()/self.e_zoom.limvals[1]) self.set_zoom(levels-level,False) ######################################################################## self.cell_info = gui.CellInfo(self, self.menu_rect.inflate((-10,0)).size, self.cell_rect.size, self.draw_no_update, e_hmap) self.unit_info = gui.UnitInfo(self,self.menu_rect.inflate((-10,0)).size, self.cell_rect.size, self.draw_no_update, e_hmap) ## self.misc_info = gui.MiscInfo(self.menu_rect.inflate((-10,0)).size) self.menu_button = thorpy.make_menu_button(force_convert_alpha=True) ######################################################################## elements =[ self.topbox, self.cell_info.e, self.unit_info.e, self.menu_button] if len(self.zoom_cell_sizes) > 1: elements.insert(0, self.e_zoom) self.e_box = thorpy.Element.make(elements=elements, size=self.menu_rect.size) self.e_box.set_main_color((200,200,200,160)) thorpy.store(self.e_box) self.e_box.stick_to("screen","right","right") ######################################################################## if len(self.zoom_cell_sizes) > 1: reac_zoom = thorpy.Reaction(reacts_to=thorpy.constants.THORPY_EVENT, reac_func=func_reac_zoom, event_args={"id":thorpy.constants.EVENT_SLIDE, "el":self.e_zoom}, reac_name="zoom slide") self.e_box.add_reaction(reac_zoom) ######################################################################## thorpy.add_keydown_reaction(self.e_box, pygame.K_KP_PLUS, self.increment_zoom, params={"value":-1}, reac_name="k plus") thorpy.add_keydown_reaction(self.e_box, pygame.K_KP_MINUS, self.increment_zoom, params={"value":1}, reac_name="k minus") wheel_reac1 = thorpy.ConstantReaction(pygame.MOUSEBUTTONDOWN, self.increment_zoom, {"button":4}, {"value":1}) wheel_reac2 = thorpy.ConstantReaction(pygame.MOUSEBUTTONDOWN, self.increment_zoom, {"button":5}, {"value":-1}) self.e_box.add_reactions([wheel_reac1, wheel_reac2]) ######################################################################## velocity = 0.2 thorpy.add_keydown_reaction(self.e_box, pygame.K_LEFT, self.move_cam_and_refresh, params={"delta":(-velocity,0)}, reac_name="k left") thorpy.add_keydown_reaction(self.e_box, pygame.K_RIGHT, self.move_cam_and_refresh, params={"delta":(velocity,0)}, reac_name="k right") thorpy.add_keydown_reaction(self.e_box, pygame.K_UP, self.move_cam_and_refresh, params={"delta":(0,-velocity)}, reac_name="k up") thorpy.add_keydown_reaction(self.e_box, pygame.K_DOWN, self.move_cam_and_refresh, params={"delta":(0,velocity)}, reac_name="k down") ######################################################################## self.help_box = gui.HelpBox([ ("Move camera", [("To move the map, drag it with", "<LMB>", "or hold", "<LEFT SHIFT>", "while moving mouse."), ("The minimap on the upper right can be clicked or hold with", "<LMB>", "in order to move the camera."), ("The","<KEYBOARD ARROWS>", "can also be used to scroll the map view.")]), ("Zoom", [("Use the","zoom slider","or","<NUMPAD +/- >", "to change zoom level."), ("You can also alternate zoom levels by pressing","<RMB>",".")]), ("Miscellaneous", [("Press","<g>","to toggle grid lines display.")]) ]) thorpy.add_keydown_reaction(self.e_box, pygame.K_g, self.toggle_show_grid_lines, reac_name="toggle grid")
my_launcher.default_func_before() #default stuff def my_func_after(): background.set_main_color((0,100,100)) #change background color my_launcher.default_func_after() #default stuff my_launcher.func_before = my_func_before my_launcher.func_after = my_func_after # ****************** Fourth launcher : event ****************** #This launcher is not linked to a ThorPy element, but instead user can activate #it by pressing SPACE unlaunch_button = thorpy.make_ok_box([thorpy.make_text("Ready to unlaunch?")]) unlaunch_button.stick_to("screen", "top", "top") invisible_launcher = thorpy.get_launcher(unlaunch_button, autocenter=False) # set focus to False for non-blocking behaviour: ##invisible_launcher.focus = False #this reaction will be added to the background: reac = thorpy.ConstantReaction(pygame.KEYDOWN, invisible_launcher.launch, {"key":pygame.K_SPACE}) #add a text so user knows what to do text4 = thorpy.make_text("Press space to launch invisible_launcher", 15) background = thorpy.Background(elements=[text4, button1, button2, button3]) background.add_reaction(reac) thorpy.store(background) menu = thorpy.Menu(background) menu.play() application.quit()
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 play(): ## if not DEBUG: if True: name = thorpy.Inserter.make("Choose your name", value="Hero") box = thorpy.make_ok_box([name]) thorpy.auto_ok(box) box.center() ## scenario.launch(box) thorpy.launch_blocking(box, e_bckgr) parameters.HERO_NAME = name.get_value() tit = thorpy.make_text("Choose vessel color") color = thorpy.ColorSetter.make("Choose vessel color") box = thorpy.make_ok_box([tit, color]) thorpy.auto_ok(box) box.center() ## scenario.launch(box) thorpy.launch_blocking(box) parameters.HERO_COLOR = color.get_value() print("setting", parameters.HERO_COLOR) # vc = gamelogic.ShowRanking("Choose a vessel", "Continue", [], False, True) vc.derotate() thorpy.set_theme("classic") if not DEBUG: scenario.launch_intro_text() scenario.launch_intro_text2() scenario.launch_help() thorpy.set_theme(parameters.THEME) init_game(vc.vessels[0]) parameters.AA = vs.get_value("aa") parameters.VISIBILITY = vs.get_value("visibility") while True: parameters.flush() while True: scene, goback = init_scene() if not goback: break reac = thorpy.ConstantReaction(thorpy.THORPY_EVENT, scene.func_time, {"id": thorpy.constants.EVENT_TIME}) g = thorpy.Ghost.make() parameters.ghost = g g.add_reaction(reac) thorpy.functions.playing(30, 1000 // parameters.FPS) m = thorpy.Menu(g, fps=parameters.FPS) m.play() gamelogic.refresh_ranking() cat_before, c1 = gamelogic.get_category(parameters.player.ranking - 1) sr = gamelogic.ShowRanking("Ranking", "Go to garage", scene.get_current_ranking_players(), results=True) gamelogic.refresh_ranking() sr.derotate() cat_after, c2 = gamelogic.get_category(parameters.player.ranking - 1) if c2 > c1: thorpy.launch_blocking_alert("Your category is now "+cat_after+\ "!\nCongratulations, "+parameters.HERO_NAME+".\nYou earned an extra bonus of 500 $."+\ "\n\nThe track length in this category is 1000m longer.") parameters.player.money += 500 parameters.ZFINISH += 1000 ## parameters.ENGINE_POWER += 0.005 parameters.CURRENT_QUALITY += 0.5 elif c2 < c1: thorpy.launch_blocking_alert("Your category is now "+cat_after+\ "!\nThis is very deceptive, "+parameters.HERO_NAME+".\n\n"+\ "The track length in this category is 1000m shorter.") parameters.ZFINISH -= 1000 parameters.CURRENT_QUALITY -= 0.5 parameters.flush() if parameters.player.ranking == parameters.players[0].ranking: scenario.launch_end() if parameters.player.vessel.life <= 0: parameters.player.vessel.life = 1 parameters.player.vessel.visible = True if random.random() < parameters.MERCHANT_PROBABILITY: garage.buy_part(None)