Exemple #1
0
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()
Exemple #3
0
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)
Exemple #4
0
 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 refresh():
    global me, mi
    me, img, mi = generate_map()
    me.screen.fill((255, 255, 255))
    img = thorpy.get_resized_image(img, (300, 300))
    button_img_map.get_elements()[0].set_image(img)
    for button_genmap in buttons:
        button_genmap.blit()
    pygame.display.flip()
Exemple #6
0
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()
Exemple #7
0
 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 __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
Exemple #9
0
            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,
    "u": img_nothing
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)
    me, img, mi = generate_map()
    me.screen.fill((255, 255, 255))
    img = thorpy.get_resized_image(img, (300, 300))
    button_img_map.get_elements()[0].set_image(img)
    for button_genmap in buttons:
        button_genmap.blit()
    pygame.display.flip()


W, H = 1000, 700  #screen size
app = thorpy.Application((W, H))
FPS = 80

button_genmap = thorpy.make_button("Generate another map", refresh)
me, img, mi = generate_map()
img = thorpy.get_resized_image(img, (300, 300))
button_img_map = thorpy.Clickable(elements=[thorpy.Image(img)])
button_img_map.fit_children()
button_img_map.user_func = thorpy.functions.quit_menu_func
buttons = [button_genmap, button_img_map]
thorpy.store("screen", buttons)
me.screen.fill((255, 255, 255))
pygame.display.flip()
m = thorpy.Menu(buttons)
m.play()
game = Game(me)

#<fast> : quality a bit lower if true, loading time a bit faster.
#<use_beach_tiler>: quality much better if true, loading much slower.
#<load_tilers> : Very slow but needed if you don't have Numpy but still want HQ.
game.build_map(mi, fast=False, use_beach_tiler=True, load_tilers=False)
    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()
                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)

##OverflowError: signed short integer is greater than maximum
#       ==> si continue, faire comme pour Object3D avec control des val abs