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 __init__(self, full=style.HEART_FULL, empty=style.HEART_EMPTY, n=5, spacing=5, x0=5, y0=5): self.full = load_image(full, (255, 255, 255)) self.empty = load_image(empty, (255, 255, 255)) self.n = n self.heart_size = self.full.get_size() self.heart_spacing = self.heart_size[0] + spacing self.xlife = -self.heart_spacing + x0 self.ylife = y0
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 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 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 __init__(self, editor, fns, name="", factor=1., relpos=(0,0), build=True, new_type=True, str_type=None): """<factor> : size factor. Object that looks the same at each frame""" self.editor = editor ref_size = editor.zoom_cell_sizes[0] self.frame_imgs = [] self.original_imgs = [] if isinstance(fns, str): fns = [fns] self.fns = fns thing = None for thing in fns: if thing: if isinstance(thing,str): img = thorpy.load_image(thing, colorkey=(255,255,255)) else: img = thing img = thorpy.get_resized_image(img, (factor*ref_size,)*2) else: img = None self.frame_imgs.append(img) self.original_imgs.append(img) self.nframes = len(self.original_imgs) self.factor = factor self.relpos = [0,0] self.imgs_z_t = None self.cell = None self.name = name self.str_type = name if str_type is None else str_type self.ncopies = 0 self.min_relpos = [-0.4, -0.4] self.max_relpos = [0.4, 0.4] self.quantity = 1 #not necessarily 1 for units self.build = build if build and thing: # print("BUILDING", self.name, self.fns) self.build_imgs() self.new_type = new_type if new_type: #then detect type already = self.editor.object_types.get(self.str_type) if already: self.int_type = already else: self.int_type = MapObject.current_id MapObject.current_id += 1 self.editor.register_object_type(self) else: #will probably be set within copy() method self.int_type = None self.anim_path = [] self.vel = 0.1 self.get_current_frame = None self._refresh_frame_type = 1 self.set_frame_refresh_type(self._refresh_frame_type) self.is_ground = False #always drawn first self.can_interact = False self.always_drawn_last = False self.is_static = False self.hide = False self.game = None
def get_intro_text(): image = thorpy.load_image("message_in_a_bottle_by_solid_pawn.png") image = pygame.transform.scale(image, (parameters.S,parameters.S)) title_text = "Dear friend,\nA few years ago, I found a message in a bottle near the sea...\n" title = thorpy.make_text(title_text, thorpy.style.TITLE_FONT_SIZE, gui.TCOLOR) text = "At that time, I was working hard on that famous Topological Astronomy Problem and I began to inattentively read the message..."+\ "But to my great surprise, it appeared that the author of the letter, a certain Gottfried Perigeo,"+\ " was trying to complete a mad - though so brave! - travel around the world, following West-East axis, almost one century ago.\n\n"+\ " Except the fact that the poor explorer sent a desperate SOS message that was obviously received hundred year too late,"+\ " my interest was peaked by the singular axis he was travelling. Here the story joins the Topological Astronomy Problem.\n\n"+\ " Indeed, my dear friend, I was - and I'm still - one of the rare physicists to believe that the world has the topology of a torus"+\ " (explain uneducated people that it's like donut). Despite several celestial hints, most of my colleagues give no credit in this theory, and invest"+\ "all their energy in proving that our planet is spherical. The situation was the same during Perigeo's life ; since the famous"+\ "explorer Girato Settentrio completed the South-North around the world travel, it was clear that Gottfried Perigeo thought the planet"+\ "is a torus , otherwise the travel he initiated was a suicide, because of the absolute extreme difficulty of the West-East round trip, if it exists.\n\n"+\ " I know you trust in my science, my friend, and I have to admit you are one of the few ones. Here is my demand:\n"+\ "Take all my money. Buy ship, hire mens, prepare a big exploration trip. Find Perigeo's shipwreck, pursue his travel, and finish what he began. Bring back with you a keepsake of Perigeo. He deserves it.\n"+\ "\n You cannot let him in here." end_text = "Prove the world that our planet is toroidal!" 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.set_main_color((200,200,255,50)) 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,80)) box.center() background = thorpy.Background(image=image,elements=[box]) thorpy.style.BOX_RADIUS -= 10 return background
def get_smokegen(n=15, color=(99, 99, 99), grow=0.4, i=2, prob=0.3, alpha0=255, size0=None): smoke_image1 = thorpy.load_image("smoke.png", (255, 255, 255)) smoke_image2 = thorpy.load_image("smoke2.png", (255, 255, 255)) return SmokeGenerator([smoke_image1, smoke_image2], n=n, prob=prob, grow=grow, i=i, color=color, alpha0=alpha0, size0=size0)
def __init__(self, full=style.HEART_FULL, empty=style.HEART_EMPTY, n=5, spacing=5, x0=5, y0=5, size=None): self.full = load_image(full, (255, 255, 255)) self.empty = load_image(empty, (255, 255, 255)) if size: self.full = pygame.transform.scale(self.full, size) self.empty = pygame.transform.scale(self.empty, size) self.n = n self.heart_size = self.full.get_size() self.heart_spacing = self.heart_size[0] + spacing self.xlife = -self.heart_spacing + x0 self.ylife = y0
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 __init__(self, hero): W, H = thorpy.functions.get_screen_size() tile = thorpy.load_image("rail.png", colorkey=(255, 255, 255)) w, h = tile.get_size() size = (W, h) pos = (W // 2, hero.pos.y) img = pygame.Surface(size) x = 0 while x < W: img.blit(tile, (x, 0)) x += tile.get_width() Ship.__init__(self, Mesh(img), pos, 0, shadow=False) self.img.set_colorkey((0, 0, 0)) self.can_explode = False life = 100000 #osef
def __init__(self, editor, fns, name="", factor=1., relpos=(0, 0), build=True, new_type=True): """<factor> : size factor. Object that looks the same at each frame""" self.editor = editor ref_size = editor.zoom_cell_sizes[0] self.frame_imgs = [] self.original_imgs = [] if isinstance(fns, str): fns = [fns] self.fns = fns for thing in fns: if thing: if isinstance(thing, str): img = thorpy.load_image(thing, colorkey=(255, 255, 255)) else: img = thing img = thorpy.get_resized_image(img, (factor * ref_size, ) * 2) else: img = None self.frame_imgs.append(img) self.original_imgs.append(img) self.nframes = len(self.original_imgs) self.factor = factor self.relpos = [0, 0] self.imgs_z_t = None self.cell = None self.name = name self.ncopies = 0 self.min_relpos = [-0.4, -0.4] self.max_relpos = [0.4, 0.4] self.quantity = 1 #not necessarily 1 for units self.build = build if build and thing: print("BUILDING", self.name, self.fns) self.build_imgs() self.new_type = new_type if new_type: self.object_type = MapObject.current_id MapObject.current_id += 1 else: self.object_type = None
def get_smokegen(n=15, color=(99, 99, 99), grow=0.4, i=2, prob=0.3, alpha0=255, size0=None, images=None): if images is None: images = [thorpy.load_image(thorpy.style.SMOKE_IMG, (255, 255, 255))] return SmokeGenerator(images, n=n, prob=prob, grow=grow, i=i, color=color, alpha0=alpha0, size0=size0)
def __init__(self, game, n, img=None): ## self.img = get_rain_img(20) self.img = None self.n = n self.dropsx = np.random.randint(0, parameters.S, n) self.dropsy = np.random.randint(0, parameters.S, n) self.impactsx = [] self.impactsy = [] for i in range(parameters.RAIN_DISTRIBUTIONS): self.impactsx.append( np.random.randint(0, parameters.S, parameters.RAIN_IMPACTS)) self.impactsy.append( np.random.randint(0, parameters.S, parameters.RAIN_IMPACTS)) self.impact = thorpy.load_image("smoke.png") self.game = game if img is None: self.imgs = get_rain_imgs(20) else: self.imgs = get_imgs(img)
def get_fire_smokegen(n=50, color=(255, 200, 0), grow=0.4, i=2, prob=0.3, alpha0=255, size0=None, images=None, black_increase=None): if images is None: images = [thorpy.load_image(thorpy.style.SMOKE_IMG, (255, 255, 255))] return FireSmokeGenerator(images, n=n, prob=prob, grow=grow, i=i, color=color, alpha0=alpha0, size0=size0, black_increase=black_increase)
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 processImage(path): ''' Iterate the GIF, extracting each frame. ''' if not path.endswith(".gif") or path.endswith(".GIF"): return [thorpy.load_image(path)] mode = analyseImage(path)['mode'] im = Image.open(path) i = 0 p = im.getpalette() last_frame = im.convert('RGBA') images = [] try: while True: ## print("saving %s (%s) frame %d, %s %s" % (path, mode, i, im.size, im.tile)) ''' If the GIF uses local colour tables, each frame will have its own palette. If not, we need to apply the global palette to the new frame. ''' if not im.getpalette(): im.putpalette(p) new_frame = Image.new('RGBA', im.size) ''' Is this file a "partial"-mode GIF where frames update a region of a different size to the entire image? If so, we need to construct the new frame by pasting it on top of the preceding frames. ''' if mode == 'partial': new_frame.paste(last_frame) new_frame.paste(im, (0, 0), im.convert('RGBA')) ## new_frame.save('%s-%d.png' % (''.join(os.path.basename(path).split('.')[:-1]), i), 'PNG') images.append(pil_img_to_pygame_surf(new_frame)) i += 1 last_frame = new_frame im.seek(im.tell() + 1) except EOFError: pass return images
def __init__(self, fn, factor, rotate=True, colorkey=(255, 255, 255)): self.fn = fn self.id = self.fn if "skorpio2" in self.fn or "skorpio3" in self.fn: self.id = "skorpio1.png" self.img = thorpy.load_image(fn) if rotate: self.img = pygame.transform.rotate(self.img, 180) w, h = self.img.get_size() size = int(factor * w), int(factor * h) self.img = pygame.transform.scale(self.img, size) if colorkey: self.img.set_colorkey(colorkey) self.img.convert() self.size = self.img.get_size() self.collisions = [[False for y in range(h)] for x in range(w)] self.color = None self.debris = None self.build_collision_matrix() if thorpy.constants.CAN_SHADOWS: self.shadow = thorpy.graphics.get_shadow(self.img, alpha_factor=0.5) self.shadow = pygame.transform.rotate(self.shadow, 180)
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 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)
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()
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) e_title = thorpy.make_text("The Phantom Racer", 25, (255, 0, 0)) e_play = thorpy.make_button("Start new game", play) e_disp, vs = gamelogic.get_display_options() e_font = thorpy.make_font_options_setter("./metadata", "Font options") e_about = thorpy.make_button("About", launch_about) e_quit = thorpy.make_button("Quit", thorpy.functions.quit_menu_func) elements = [e_title, e_play, e_disp, e_font, e_about, e_quit] background = thorpy.load_image("PaulinaRiva.png") background = thorpy.get_resized_image(background, (parameters.W, parameters.H // 2), type_=max) e_bckgr = thorpy.Background.make(image=background, elements=elements) thorpy.store(e_bckgr) e_title.move((0, -50)) m = thorpy.Menu(e_bckgr) m.play() app.quit() #si autres bugs d'affichages : if len(p) == len(thing.points): dans draw... #be careful: # cam need to know all!!!! (for moving objects)
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
def load_images(): # global left, right, up, down, compass, girouette, thermo, houses, flag, tent, imgs_ship, star, perigeo, treasure perigeo_img = thorpy.load_image("boat_perigeo.png", (255, 255, 255)) perigeo = Tile(perigeo_img, Vector2(parameters.WRECK_COORD) * parameters.S) # lc = thorpy.load_image("boat_left_2.png", (255, 255, 255)) rc = thorpy.load_image("boat_right_2.png", (255, 255, 255)) uc = thorpy.load_image("boat_rear_2.png", (255, 255, 255)) dc = thorpy.load_image("boat_front_2.png", (255, 255, 255)) # lj = thorpy.load_image("boat_left_1.png", (255, 255, 255)) rj = thorpy.load_image("boat_right_1.png", (255, 255, 255)) uj = thorpy.load_image("boat_rear_1.png", (255, 255, 255)) dj = thorpy.load_image("boat_front_1.png", (255, 255, 255)) # left, right, up, down = (lj, rj, uj, dj) imgs_ship[CARAVEL] = (lc, rc, uc, dc) imgs_ship[JUNK] = (lj, rj, uj, dj) ## left = thorpy.load_image("boat_left_"+SHIP_STR+".png",(255,255,255)) ## right = thorpy.load_image("boat_right_"+SHIP_STR+".png",(255,255,255)) ## up = thorpy.load_image("boat_rear_"+SHIP_STR+".png",(255,255,255)) ## down = thorpy.load_image("boat_front_"+SHIP_STR+".png",(255,255,255)) # star = thorpy.load_image("star.png", (255, 255, 255)) compass = thorpy.load_image("r6.png", (255, 255, 255)) compass.set_alpha(160) thermo = thorpy.load_image("thermometer.png", (255, 255, 255)) for i in range(2): houses.append( thorpy.load_image("house" + str(i) + ".png", (255, 255, 255))) oasises.append( thorpy.load_image("oasis" + str(i) + ".png", (255, 255, 255))) firs.append(thorpy.load_image("fir" + str(i) + ".png", (255, 255, 255))) tent = thorpy.load_image("tent2.png", (255, 255, 255)) flag = thorpy.load_image("flag.png", (255, 255, 255)) i = 0 for i in range(6): imgs_arrows.append( thorpy.load_image("arrow" + str(i) + ".png", (255, 255, 255))) treasure = thorpy.load_image("treasure.png", (255, 255, 255))
def load_image(self, fn): img = thorpy.load_image(fn) return pygame.transform.smoothscale(img, (self.zoom_cell_sizes[0],)*2)
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
g.new() g.show_go_screen() if __name__ == "__main__": app = thorpy.Application((WIDTH, HEIGHT)) thorpy.set_theme("human") screen = thorpy.get_screen() def play(): print("playing") def calibrate(): print("calibrating") logo = thorpy.Image.make(thorpy.load_image("Logo.png")) sticky_jump_image = "StickyJump.png" sticky_jump_image_hover = "StickyJumpHover.png" sticky_jam_image = "StickyJam.png" reset_image = "StickyReset.png" quit_image = "Credits.png" quit_image_hover = "CreditsHover.png" e_play = thorpy.make_image_button(sticky_jump_image, sticky_jump_image_hover, sticky_jump_image_hover) e_play.user_func = init_game e_play_2 = thorpy.make_image_button(sticky_jam_image, sticky_jam_image, sticky_jam_image) e_quit = thorpy.make_image_button(quit_image, quit_image_hover, quit_image_hover) e_quit.user_func = thorpy.functions.quit_menu_func
parameters.OASIS_PROB = diff[4] cam.reset(seed) game.next_season = parameters.SEASON_MOD_DAYS core.perigeo.img_pos = Vector2(parameters.WRECK_COORD)*parameters.S intro = scenario.get_intro_text() core.instructions = scenario.get_instructions() game.instructions = core.instructions if not savefile: #actual game m = thorpy.Menu(intro) m.play() gui.show_loading() ##image = thorpy.load_image("bottle.png") image = thorpy.load_image("message_in_a_bottle_by_solid_pawn.png") image = pygame.transform.scale(image, (parameters.S,parameters.S)) screen.blit(image,(0,0)) pygame.display.flip() m = thorpy.Menu(core.instructions) m.play() #xxx game.choose_ship() game.choose_astronomer() game.choose_hunter() game.choose_captain() game.set_ship(game.ship) game.refresh_controllables() app.fill((0,0,0)) pygame.display.flip() game.e_x.set_text("0")
elif j1_main: #j1 win ==> up sgn = -1 else: sgn = 1 for i in range(30): c1.move((0, sgn * 10)) c2.move((0, sgn * 10)) b.unblit_and_reblit() pygame.display.flip() pygame.time.wait(20) app = thorpy.Application((800, 600), "Pomme d'API") simg = 30 img = thorpy.load_image("./coeur.png", colorkey=(255, 255, 255)) img_coeur = thorpy.get_resized_image(img, (simg, simg)) img = thorpy.load_image("./trefle.png", colorkey=(255, 255, 255)) img_trefle = thorpy.get_resized_image(img, (simg, simg)) img = thorpy.load_image("./pique.png", colorkey=(255, 255, 255)) img_pique = thorpy.get_resized_image(img, (simg, simg)) img = thorpy.load_image("./carreau.png", colorkey=(255, 255, 255)) img_carreau = thorpy.get_resized_image(img, (simg, simg)) img_nothing = img_carreau.copy() img_nothing.fill((50, 50, 50)) couleur2img = couleur2texte = { "c": img_coeur, "p": img_pique, "l": img_carreau, "t": img_trefle,