Ejemplo n.º 1
0
def launch(e, after=None):
    thorpy.launch_blocking(e)
    if parameters.game:
        parameters.game.draw()
    if after:
        after()
    pygame.display.flip()
Ejemplo n.º 2
0
def choose_name():
    name = thorpy.Inserter.make("Choose your name", value="Hero")
    box = thorpy.make_ok_box([name])
    thorpy.auto_ok(box)
    box.center()
    thorpy.launch_blocking(box)
    parameters.PNAME = name.get_value()
Ejemplo n.º 3
0
 def rename_current_unit(self):
     varset = thorpy.VarSet()
     varset.add("newname", "", "New name")
     ##        ps = thorpy.ParamSetterLauncher.make(varset)
     ps = thorpy.ParamSetter.make([varset])
     for h in ps.get_handlers():
         ins = ps.handlers[h]
     ins.set_main_color((200, 200, 200, 150))
     ps.center()
     ins.enter()  #put focus on inserter
     thorpy.launch_blocking(ps)
     newname = ins.get_value()
     if newname:
         self.unit.name = newname
     self.update_em(self.unit.cell)
     self.redraw()
     self.em.blit()
     pygame.display.flip()
Ejemplo n.º 4
0
 def show_options(self):
     e_life_size = thorpy.SliderX(100, (6, 20),
                                  "Life font size",
                                  type_=int,
                                  initial_value=self.life_font_size)
     ##        e_life_color = thorpy.ColorSetter(text="Life font color",
     ##                                            value=self.life_font_color)
     e_title = thorpy.make_text("Units life")
     e_box = thorpy.make_ok_cancel_box([e_title, e_life_size])
     e_box.center()
     result = thorpy.launch_blocking(e_box)
     if result.how_exited == "done":
         self.life_font_size = e_life_size.get_value()
         ##            self.life_font_color = e_life_color.get_value()
         self.refresh_graphics_options()
     self.me.draw()
     self.menu.blit()
     pygame.display.flip()
Ejemplo n.º 5
0
 def launch(self):
     self.b.blit()
     pygame.display.flip()
     thorpy.launch_blocking(self.e)
     thorpy.functions.quit_menu_func()
Ejemplo n.º 6
0
def buy_part(parent):
    background = thorpy.load_image("background_garage.jpg")
    background = thorpy.get_resized_image(background,
                                                    (parameters.W,parameters.H),
                                                    type_=max)
    thorpy.get_screen().blit(background,(0,0))
    pygame.display.flip()
    title = thorpy.make_text("Vessel merchant", thorpy.style.TITLE_FONT_SIZE+4, (255,0,0))
    hbar = thorpy.Line.make(200, "h")
    intro = "Hello, "+str(parameters.player.name)+"."+\
                                    "\nHere is what I have to sell today:"
    intro = thorpy.make_text(intro, thorpy.style.TITLE_FONT_SIZE, thorpy.style.TITLE_FONT_COLOR)
    #
    money = thorpy.Element(thorpy.pack_text(200,"Your money: "+str(parameters.player.money)+" $."))
    money.set_painter(thorpy.functions.obtain_valid_painter(thorpy.painterstyle.DEF_PAINTER,
                                                 pressed=True))
    money.finish()
    money.scale_to_title()
    #
    info = thorpy.Element(thorpy.pack_text(200,"Remember that any part you buy will replace your current one."))
    info.set_painter(thorpy.functions.obtain_valid_painter(thorpy.painterstyle.DEF_PAINTER,
                                                 pressed=True))
    info.finish()
    info.scale_to_title()
    money_info = thorpy.Ghost.make([info, money])
    thorpy.store(money_info, mode="h")
    money_info.fit_children()
    #
    part1, skills1, price1 = get_random_element()
    part2, skills2, price2 = get_random_element()
    choices = thorpy.Ghost.make(elements=[part1,part2])
    thorpy.store(choices, mode="h")
    choices.fit_children()
    cancel = thorpy.make_button("No, thanks", thorpy.functions.quit_menu_func)
    #
    def buy(part, cost):
        if cost > parameters.player.money:
            thorpy.launch_blocking_alert("Not enough money",
            "You don't have enough money to buy this part.",transp=False)
            box.unblit_and_reblit()
        else:
            parameters.player.money -= cost
            name = part.pop(0)
            if name == "wings":
                parts = [getattr(parameters.player.vessel, "lwing"),
                         getattr(parameters.player.vessel, "rwing")]
            else:
                parts = [getattr(parameters.player.vessel, name)]
            for part_obj in parts:
                for skillname, factor in part:
                    if skillname == "agility": skillname = "turn"
                    elif skillname == "power":
                        parameters.player.vessel.engine_force *= (1.+factor)
                    elif skillname == "max_fuel":
                        parameters.player.vessel.engine.max_fuel *= (1.+factor)
                    elif skillname == "mass":
                        parameters.player.vessel.engine_force *= parameters.player.vessel.mass
                        parameters.player.vessel.mass *= (1.+factor)
                        parameters.player.vessel.engine_force /= parameters.player.vessel.mass
                        parameters.player.vessel.max_life = int(parameters.player.vessel.mass * parameters.LIFE_FACTOR)
                    else:
                        current_value = getattr(parameters.player.vessel, skillname)
                        new_value = current_value + factor*current_value/6.
                        setattr(parameters.player.vessel, skillname, new_value)
            thorpy.functions.quit_menu_func()
    part1.e_ok.user_func = buy
    part1.e_ok.user_params = {"part":skills1, "cost":price1}
    part2.e_ok.user_func = buy
    part2.e_ok.user_params = {"part":skills2, "cost":price2}
    #
    box = thorpy.Box.make([title,hbar,intro,money_info,choices,cancel])
    box.center()
    thorpy.launch_blocking(box)
Ejemplo n.º 7
0
 def launch_map_menu(self):
     thorpy.launch_blocking(self.menu)
Ejemplo n.º 8
0
    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)