예제 #1
0
class CharGen():
    def __init__(self):
        self.text = "CharGen"
        self.textObject = OnscreenText(text=self.text,
                                       pos=(0.95, -0.95),
                                       scale=0.07,
                                       fg=(1, 0.5, 0.5, 1),
                                       align=TextNode.ACenter,
                                       mayChange=1)

        self.f = DirectFrame(frameColor=(1, 1, 1, 0.5),
                             frameSize=(-1, 1, -0.4, 0.4))
        self.f.setPos(-0.5, 0, -0.5)

        self.flavorText = OnscreenText("Primary Colour",
                                       pos=(0, 0, 0.4),
                                       scale=0.07,
                                       align=TextNode.ACenter,
                                       mayChange=1,
                                       fg=(1, 1, 1, 1))
        self.flavorText.reparent_to(self.f)
        self.flavorText.setPos(0, 0.2)
        #slider R
        self.sR = DirectSlider(self.f,
                               range=(0, 1),
                               value=0,
                               pageSize=3,
                               command=self.setCol)
        self.sR.setScale(0.5, 0.5, 0.5)
        self.sR.setPos(0, 0, 0)
        self.sR.setColor(1, 0, 0)

        #slider G
        self.sG = DirectSlider(self.f,
                               range=(0, 1),
                               value=0,
                               pageSize=3,
                               command=self.setCol)
        self.sG.setScale(0.5, 0.5, 0.5)
        self.sG.setPos(0, 0, -0.1)
        self.sG.setColor(0, 1, 0)

        #slider B
        self.sB = DirectSlider(self.f,
                               range=(0, 1),
                               value=0,
                               pageSize=3,
                               command=self.setCol)
        self.sB.setScale(0.5, 0.5, 0.5)
        self.sB.setPos(0, 0, -0.2)
        self.sB.setColor(0, 0, 1)

        self.pandaActor = Actor("models/panda-model",
                                {"walk": "models/panda-walk4"})
        self.pandaActor.setScale(0.005, 0.005, 0.005)
        self.pandaActor.setPos(0.8, 12, -0.5)
        self.pandaActor.reparentTo(base.render)

    def setCol(self):
        #print(self.s['value'])
        self.pandaActor.setColor(self.sR['value'], self.sG['value'],
                                 self.sB['value'])
예제 #2
0
class CarPanel(GameObject):
    def __init__(self, car_props, player_idx, ncars, players):
        GameObject.__init__(self)
        self._players = players
        self.car_props = car_props
        self.player_idx = player_idx
        self.ncars = ncars
        sprops = self.car_props.race_props.season_props
        menu_props = sprops.gameprops.menu_props
        if ncars == 1:
            parent_tr = base.a2dTopRight
        elif ncars == 2:
            if self.player_idx == 0: parent_tr = base.a2dTopCenter
            else: parent_tr = base.a2dTopRight
        elif ncars == 3:
            if self.player_idx == 0: parent_tr = base.a2dTopRight
            elif self.player_idx == 1: parent_tr = base.aspect2d
            else: parent_tr = base.a2dRightCenter
        elif ncars == 4:
            if self.player_idx == 0: parent_tr = base.a2dTopCenter
            elif self.player_idx == 1: parent_tr = base.a2dTopRight
            elif self.player_idx == 2: parent_tr = base.aspect2d
            else: parent_tr = base.a2dRightCenter
        if ncars == 1:
            parent_tl = base.a2dTopLeft
        elif ncars == 2:
            if self.player_idx == 0: parent_tl = base.a2dTopLeft
            else: parent_tl = base.a2dTopCenter
        elif ncars == 3:
            if self.player_idx == 0: parent_tl = base.a2dTopLeft
            elif self.player_idx == 1: parent_tl = base.a2dLeftCenter
            else: parent_tl = base.aspect2d
        elif ncars == 4:
            if self.player_idx == 0: parent_tl = base.a2dTopLeft
            elif self.player_idx == 1: parent_tl = base.a2dTopCenter
            elif self.player_idx == 2: parent_tl = base.a2dLeftCenter
            else: parent_tl = base.aspect2d
        if ncars == 1:
            parent_bl = base.a2dBottomLeft
        elif ncars == 2:
            if self.player_idx == 0: parent_bl = base.a2dBottomLeft
            else: parent_bl = base.a2dBottomCenter
        elif ncars == 3:
            if self.player_idx == 0: parent_bl = base.a2dLeftCenter
            elif self.player_idx == 1: parent_bl = base.a2dBottomLeft
            else: parent_bl = base.a2dBottomCenter
        elif ncars == 4:
            if self.player_idx == 0: parent_bl = base.a2dLeftCenter
            elif self.player_idx == 1: parent_bl = base.aspect2d
            elif self.player_idx == 2: parent_bl = base.a2dBottomLeft
            else: parent_bl = base.a2dBottomCenter
        # if ncars == 1: parent_t = base.a2dTopCenter
        # elif ncars == 2:
        #     if self.player_idx == 0: parent_t = base.a2dTopQuarter
        #     else: parent_t = base.a2dTopThirdQuarter
        # elif ncars == 3:
        #     if self.player_idx == 0: parent_t = base.a2dTop
        #     elif self.player_idx == 1: parent_t = base.a2dCenterQuarter
        #     else: parent_t = base.a2dCenterThirdQuarter
        # elif ncars == 4:
        #     if self.player_idx == 0: parent_t = base.a2dTopQuarter
        #     elif self.player_idx == 1: parent_t = base.a2dTopThirdQuarter
        #     elif self.player_idx == 2: parent_t = base.a2dCenterQuarter
        #     else: parent_t = base.a2dCenterThirdQuarter
        # if ncars == 1: parent_b = base.a2dBottomCenter
        # elif ncars == 2:
        #     if self.player_idx == 0: parent_b = base.a2dBottomQuarter
        #     else: parent_b = base.a2dBottomThirdQuarter
        # elif ncars == 3:
        #     if self.player_idx == 0: parent_b = base.aspect2d
        #     elif self.player_idx == 1: parent_b = base.a2dBottomQuarter
        #     else: parent_b = base.a2dBottomThirdQuarter
        # elif ncars == 4:
        #     if self.player_idx == 0: parent_b = base.a2dCenterQuarter
        #     elif self.player_idx == 1: parent_b = base.a2dCenterThirdQuarter
        #     elif self.player_idx == 2: parent_b = base.a2dBottomQuarter
        #     else: parent_b = base.a2dBottomThirdQuarter
        yellow_scale = .065 if ncars == 1 else .042
        white_scale = .05 if ncars == 1 else .038
        damages_img_scale = (.12, 1, .12) if ncars == 1 else (.08, 1, .08)
        self.__weap_scale = .12 if ncars == 1 else .08
        txt_x = -.24 if ncars == 1 else -.18
        lab_x = -.3 if ncars == 1 else -.24
        offset_z = .1 if ncars == 1 else .08
        top_z = -.1
        damages_txt_pos = (.3, .1) if ncars == 1 else (.24, .06)
        damages_img_pos = (.46, 1, .12) if ncars == 1 else (.36, 1, .07)
        weapon_txt_pos = (.18, -.08) if ncars == 1 else (.14, -.08)
        self.__weapon_img_pos = (.18, 1, -.24) if ncars == 1 else \
            (.14, 1, -.18)
        fwd_img_pos = (0, 1, -.2) if ncars == 1 else (0, 1, -.16)
        fwd_img_scale = .15 if ncars == 1 else .12
        pars = {
            'scale': yellow_scale,
            'parent': parent_tr,
            'fg': menu_props.text_active_col,
            'align': TextNode.A_left,
            'font': self.eng.font_mgr.load_font(sprops.font)
        }
        # self.glass_tl = OnscreenImage(
        #     'assets/images/gui/topleft.txo',
        #     scale=(.23, 1, .24), parent=parent_tl, pos=(.22, 1, -.23))
        # self.glass_tl.set_transparency(True)
        # self.glass_tr = OnscreenImage(
        #     'assets/images/gui/topright.txo',
        #     scale=(.36, 1, .36), parent=parent_tr, pos=(-.35, 1, -.35))
        # self.glass_tr.set_transparency(True)
        # self.glass_t = OnscreenImage(
        #     'assets/images/gui/top.txo',
        #     scale=(.24, 1, .22), parent=parent_t, pos=(0, 1, -.21))
        # self.glass_t.set_transparency(True)
        # self.glass_bl = OnscreenImage(
        #     'assets/images/gui/bottomleft.txo',
        #     scale=(.36, 1, .16), parent=parent_bl, pos=(.35, 1, .15))
        # self.glass_bl.set_transparency(True)
        # self.glass_br = OnscreenImage(
        #     'assets/images/gui/bottomright.txo', scale=(.26, 1, .26),
        #     parent=base.a2dBottomRight, pos=(-.25, 1, .25))
        # self.glass_br.set_transparency(True)
        # self.glass_b = OnscreenImage(
        #     'assets/images/gui/bottom.txo',
        #     scale=(1.02, 1, .26), parent=parent_b, pos=(0, 1, .25))
        # self.glass_b.set_transparency(True)
        # self.glass_tl.hide()
        # self.glass_t.hide()
        # self.glass_b.hide()
        self.speed_txt = OnscreenText(pos=(txt_x + .06, top_z), **pars)
        self.speed_txt['align'] = TextNode.A_center
        self.speed_c = Circle(size=.1,
                              pos=(txt_x + .06, top_z),
                              parent=parent_tr,
                              ray=.4,
                              thickness=.05,
                              col_start=(.9, .6, .1, 1),
                              col_end=(.2, .8, .2, 1))
        lap_str = '1/' + str(self.car_props.race_props.laps)
        self.lap_txt = OnscreenText(text=lap_str,
                                    pos=(txt_x, top_z - offset_z),
                                    **pars)
        self.time_txt = OnscreenText(pos=(txt_x, top_z - offset_z * 4), **pars)
        self.best_txt = OnscreenText(pos=(txt_x, top_z - offset_z * 5), **pars)
        self.ranking_txt = OnscreenText(pos=(txt_x, top_z - offset_z * 2),
                                        **pars)
        self.damages_img = OnscreenImage('assets/images/gui/car_icon.txo',
                                         scale=damages_img_scale,
                                         parent=parent_bl,
                                         pos=damages_img_pos)
        self.damages_img.set_transparency(True)
        self.damages_img.set_color_scale(menu_props.text_normal_col)
        self.damages_img.set_r(90)
        pars = {
            'scale': white_scale,
            'parent': pars['parent'],
            'fg': menu_props.text_normal_col,
            'align': TextNode.A_right,
            'font': pars['font']
        }
        self.speed_lab = OnscreenText(_('speed:'), pos=(lab_x, top_z), **pars)
        self.lap_lab = OnscreenText(text=_('lap:'),
                                    pos=(lab_x, top_z - offset_z),
                                    **pars)
        self.time_lab = OnscreenText(_('time:'),
                                     pos=(lab_x, top_z - offset_z * 4),
                                     **pars)
        self.best_lab = OnscreenText(_('best lap:'),
                                     pos=(lab_x, top_z - offset_z * 5),
                                     **pars)
        self.ranking_lab = OnscreenText(_('ranking:'),
                                        pos=(lab_x, top_z - offset_z * 2),
                                        **pars)
        self.damages_lab = OnscreenText(_('damages:'),
                                        pos=damages_txt_pos,
                                        **pars)
        self.damages_lab.reparent_to(parent_bl)
        self.weapon_lab = OnscreenText(_('weapon'),
                                       pos=weapon_txt_pos,
                                       scale=white_scale,
                                       parent=parent_tl,
                                       fg=menu_props.text_normal_col,
                                       font=self.eng.font_mgr.load_font(
                                           sprops.font))
        self.weapon_img = None
        if ncars == 1: parent = base.a2dTopCenter
        elif ncars == 2:
            if player_idx == 0: parent = base.a2dTopQuarter
            else: parent = base.a2dTopThirdQuarter
        elif ncars == 3:
            if player_idx == 0: parent = base.a2dTopCenter
            elif player_idx == 0: parent = base.a2dCenterQuarter
            else: parent = base.a2dCenterThirdQuarter
        elif ncars == 4:
            if player_idx == 0: parent = base.a2dTopQuarter
            elif player_idx == 1: parent = base.a2dTopThirdQuarter
            elif player_idx == 2: parent = base.a2dCenterQuarter
            else: parent = base.a2dCenterThirdQuarter
        self.forward_img = OnscreenImage('assets/images/gui/direction.txo',
                                         scale=fwd_img_scale,
                                         parent=parent,
                                         pos=fwd_img_pos)
        self.forward_img.set_transparency(True)
        self.forward_img.hide()

    @staticmethod
    def __close_vec(vec1, vec2):
        return all(abs(b - a) < .01 for a, b in zip(vec1, vec2))

    def enter_waiting(self):
        pass
        # if self.ncars == 1: parent = base.aspect2d
        # elif self.ncars == 2:
        #     if self.player_idx == 0: parent = base.a2dCenterQuarter
        #     else: parent = base.a2dCenterThirdQuarter
        # elif self.ncars == 3:
        #     if self.player_idx == 0: parent = base.a2dQuarterCenter
        #     elif self.player_idx == 1: parent = base.a2dThirdQuarterQuarter
        #     else: parent = base.a2dThirdQuarterThirdQuarter
        # elif self.ncars == 4:
        #     if self.player_idx == 0: parent = base.a2dQuarterQuarter
        #     elif self.player_idx == 1: parent = base.a2dQuarterThirdQuarter
        #     elif self.player_idx == 2: parent = base.a2dThirdQuarterQuarter
        #     else: parent = base.a2dThirdQuarterThirdQuarter
        # menu_props = self.race_props.season_props.gameprops.menu_props
        # pars = {'scale': .065, 'parent': parent,
        #         'fg': menu_props.text_normal_col,
        #         'font': self.eng.font_mgr.load_font(
        #             self.race_props.season_props.font)}

    def exit_waiting(self):
        pass

    def set_weapon(self, wpn):
        # self.glass_tl.show()
        self.weapon_lab.show()
        ncars = len([
            player for player in self._players if player.kind == Player.human
        ])
        if ncars == 1:
            parent_tl = base.a2dTopLeft
        elif ncars == 2:
            if self.player_idx == 0: parent_tl = base.a2dTopLeft
            else: parent_tl = base.a2dTopCenter
        elif ncars == 3:
            if self.player_idx == 0: parent_tl = base.a2dTopLeft
            elif self.player_idx == 1: parent_tl = base.a2dLeftCenter
            else: parent_tl = base.aspect2d
        elif ncars == 4:
            if self.player_idx == 0: parent_tl = base.a2dTopLeft
            elif self.player_idx == 1: parent_tl = base.a2dTopCenter
            elif self.player_idx == 2: parent_tl = base.a2dLeftCenter
            else: parent_tl = base.aspect2d
        self.weapon_img = OnscreenImage('assets/images/weapons/%s.txo' % wpn,
                                        scale=self.__weap_scale,
                                        parent=parent_tl,
                                        pos=self.__weapon_img_pos)
        self.weapon_img.set_transparency(True)

    def unset_weapon(self):
        # self.glass_tl.hide()
        self.weapon_lab.hide()
        self.weapon_img.destroy()

    def show_forward(self):
        # self.glass_t.show()
        self.forward_img.show()

    def set_forward_angle(self, angle):
        curr_angle = self.forward_img.get_r()
        curr_incr = globalClock.getDt() * 30
        if abs(curr_angle - angle) < curr_incr:
            tgt_val = angle
        else:
            sign = 1 if angle > curr_angle else -1
            tgt_val = curr_angle + curr_incr * sign
        self.forward_img.set_r(tgt_val)

    def hide_forward(self):
        # self.glass_t.hide()
        self.forward_img.hide()

    def apply_damage(self, reset=False):
        col = self.car_props.race_props.season_props.gameprops.menu_props.text_normal_col
        if reset:
            self.damages_img.set_color_scale(col)
        else:
            yellow = (col[0], col[1] - .25, col[2] - .5, col[3])
            if self.__close_vec(self.damages_img.get_color_scale(), col):
                self.damages_img.set_color_scale(yellow)
            elif self.__close_vec(self.damages_img.get_color_scale(), yellow):
                red = (col[0], col[1] - .5, col[2] - .5, col[3])
                self.damages_img.set_color_scale(red)

    def hide(self):
        labels = [
            self.speed_txt,
            self.speed_c,
            self.time_txt,
            self.lap_txt,
            self.best_txt,
            self.speed_lab,
            self.time_lab,
            self.lap_lab,
            self.best_lab,
            self.damages_img,
            self.damages_lab,
            self.ranking_txt,
            self.ranking_lab,
            self.weapon_lab,
            # self.glass_tl, self.glass_tr, self.glass_t,
            # self.glass_bl, self.glass_br, self.glass_b
        ]
        list(map(lambda wdg: wdg.hide(), labels))
        if self.weapon_img and not self.weapon_img.is_empty():
            self.weapon_img.hide()
        self.forward_img.hide()

    def destroy(self):
        labels = [
            self.speed_txt,
            self.speed_c,
            self.time_txt,
            self.lap_txt,
            self.best_txt,
            self.speed_lab,
            self.time_lab,
            self.lap_lab,
            self.best_lab,
            self.damages_img,
            self.damages_lab,
            self.ranking_txt,
            self.ranking_lab,
            self.weapon_lab,
            # self.glass_tl, self.glass_tr, self.glass_t,
            # self.glass_bl, self.glass_br, self.glass_b
        ]
        list(map(lambda wdg: wdg.destroy(), labels))
        if self.weapon_img and not self.weapon_img.is_empty():
            self.weapon_img.destroy()
        self.forward_img.destroy()