Esempio n. 1
0
    def __init__(self, rootParent=None):

        self.volume = DirectSlider(
            pos=LPoint3f(0.2, 0, 0.325),
            text='Volume',
            text_pos=(-1.05, -0.02),
            text_fg=(1, 1, 1, 1),
            text_scale=0.1,
            text_align=TextNode.ARight,
            parent=rootParent,
            command=base.messenger.send,
            extraArgs=["volumeChange"],
        )
        self.volume.setTransparency(0)

        self.audioMute = DirectCheckButton(
            frameSize=(-2.925000047683716, 3.024999713897705, -0.225,
                       0.8250000238418579),
            pos=LPoint3f(0, 0, 0),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Mute',
            parent=rootParent,
            command=self.toggleMute,
        )
        self.audioMute.setTransparency(0)

        self.btnBack = DirectButton(
            frameSize=(-1.5249999523162843, 1.6499999523162843,
                       -0.21250001192092896, 0.8250000238418579),
            pos=LPoint3f(0, 0, -0.575),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Back',
            parent=rootParent,
            command=base.messenger.send,
            extraArgs=["optionBack"],
            pressEffect=1,
        )
        self.btnBack.setTransparency(0)

        self.fullscreen = DirectCheckButton(
            frameSize=(-3.35, 2.6, -0.213, 0.825),
            pos=LPoint3f(0.045, 0, -0.175),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Fullscreen',
            parent=rootParent,
            command=self.toggleFullscreen,
        )
        self.fullscreen.setTransparency(0)
Esempio n. 2
0
    def __init__(self,
                 x,
                 y,
                 parent,
                 size=100,
                 minValue=0,
                 maxValue=100,
                 value=50,
                 pageSize=1,
                 callback=None,
                 extraArgs=None):
        if extraArgs is None:
            extraArgs = []

        # Scale has to be 2.0, otherwise there will be an error.
        self.node = DirectSlider(pos=(size * 0.5 + x, 1, -y),
                                 parent=parent,
                                 range=(minValue, maxValue),
                                 value=value,
                                 pageSize=pageSize,
                                 scale=2.0,
                                 command=callback,
                                 extraArgs=extraArgs,
                                 frameColor=(0.09, 0.09, 0.09, 0.8),
                                 frameSize=(-size * 0.25, size * 0.25, -5, 5),
                                 thumb_frameColor=(0.35, 0.53, 0.2, 1.0),
                                 thumb_frameSize=(-2.5, 2.5, -5.0, 5.0),
                                 thumb_relief=DGG.FLAT,
                                 relief=DGG.FLAT)
    def __init__(self,
                 x=0,
                 y=0,
                 parent=None,
                 size=100,
                 min_value=0,
                 max_value=100,
                 value=50,
                 page_size=1,
                 callback=None,
                 extra_args=None):
        """ Inits the slider """
        RPObject.__init__(self)
        if extra_args is None:
            extra_args = []

        # Scale has to be 2.0, otherwise there will be an error.
        self._node = DirectSlider(
            pos=(size * 0.5 + x, 1, -y),
            parent=parent,
            range=(min_value, max_value),
            value=value,
            pageSize=page_size,
            scale=2.0,
            command=callback,
            extraArgs=extra_args,
            frameColor=(0.0, 0.0, 0.0, 1),
            frameSize=(-size * 0.25, size * 0.25, -5, 5),
            relief=DGG.FLAT,
            thumb_frameColor=(0.35, 0.53, 0.2, 1.0),
            thumb_relief=DGG.FLAT,
            thumb_frameSize=(-2.5, 2.5, -5.0, 5.0),
        )
Esempio n. 4
0
    def setting_menu(self):
        if self.__destroySetting==False:
            # 设置界面背景图
            self.__background = OnscreenImage(image='../../resources/images/settings/setting_frame.png', pos=(0, 0, 0),
                                              scale=(1.0, 0, 0.7))
            self.__background.setTransparency(TransparencyAttrib.MAlpha)

            ##滑动条
            self.__slider = DirectSlider(pos=(0.16, 0, 0.26), scale=0.5, value=0.5, command=self.__setMusicSliderVolume,
                                         frameSize=(-1.0, 0.9, -0.06, 0.06),
                                         image='../../resources/images/settings/slide_bar.png',
                                         image_pos=(-0.05, 0, 0.0), image_scale=(1.0, 0, 0.05),
                                         thumb_image='../../resources/images/settings/slide_btn.png',
                                         thumb_image_pos=(-0.0, 0, 0.0), thumb_image_scale=0.1,
                                         thumb_frameSize=(0.0, 0.0, 0.0, 0.0))
            self.__slider.setTransparency(TransparencyAttrib.MAlpha)

            # self.__musicButton = DirectButton(pos=(0.9, 0, 0.75), text="Close", scale=0.1, pad=(0.2, 0.2), rolloverSound=None,
            #                                   clickSound=None, command=self.toggleMusicBox,extraArgs=[base])

            # 继续按钮
            self.__continueButton = DirectButton(pos=(-0.25, 0, 0.0), text="", scale=(0.2, 0, 0.1),
                                                 command=self.__continue_game,
                                                 image=("../../resources/images/settings/btn_continue_0.png",
                                                        "../../resources/images/settings/btn_continue_0.png"
                                                        , "../../resources/images/settings/btn_continue_1.png"),
                                                 frameColor=(0, 0, 0, 0))
            self.__continueButton.setTransparency(TransparencyAttrib.MAlpha)

            # 存档按钮
            self.__saveButton = DirectButton(pos=(0.33, 0, 0.0), text="", scale=(0.2, 0, 0.1), command=self.__save_game,
                                             image=("../../resources/images/settings/btn_save_0.png",
                                                    "../../resources/images/settings/btn_save_0.png"
                                                    , "../../resources/images/settings/btn_save_1.png"),
                                             frameColor=(0, 0, 0, 0))
            self.__saveButton.setTransparency(TransparencyAttrib.MAlpha)

            # 帮助按钮
            self.__helpButton = DirectButton(pos=(-0.25, 0, -0.25), text="", scale=(0.2, 0, 0.1), command=self.__help,
                                             image=("../../resources/images/settings/btn_help_0.png",
                                                    "../../resources/images/settings/btn_help_0.png"
                                                    , "../../resources/images/settings/btn_help_1.png"),
                                             frameColor=(0, 0, 0, 0))
            self.__helpButton.setTransparency(TransparencyAttrib.MAlpha)

            # 回到主界面按钮
            self.__homeButton = DirectButton(pos=(0.33, 0, -0.25), text="", scale=(0.2, 0, 0.1), command=self.__return_home,
                                             image=("../../resources/images/settings/btn_home_0.png",
                                                    "../../resources/images/settings/btn_home_0.png"
                                                    , "../../resources/images/settings/btn_home_1.png"),
                                             frameColor=(0, 0, 0, 0))
            self.__homeButton.setTransparency(TransparencyAttrib.MAlpha)

            # 设置滑动条value
            self.__slider['value'] = self.__rm.get_volume()

            self.__destroySetting = True
Esempio n. 5
0
 def loadExposureGUI(self):
     self.numExposure = DirectSlider(
         parent=self,
         value=self.exposure,
         pos=(self.buttonbase_xcoord + 0.1, 0.0,
              (self.buttonbase_ycoord - self.textRowHeight * 2.2)),
         thumb_relief=None,
         range=(0, 5),  # self.SAMPLES_MAX
         thumb_geom=self.circleModel.find(
             '**/tt_t_gui_mat_namePanelCircle'),
         frameTexture=self.barTexture,
         frameSize=(-0.5, 0.5, -0.08, 0.08),
         command=self.__changeExposure)
     self.numExposure.setScale(0.5)
     self.numExposure.setTransparency(True)
     self.numExposureText = OnscreenText(
         pos=(self.buttonbase_xcoord + 0.1,
              self.buttonbase_ycoord - self.textRowHeight * 1.9),
         scale=0.05,
         text="Exposure Amount = {}".format(self.blur),
         style=5,
         mayChange=True)
Esempio n. 6
0
 def loadBlurGUI(self):
     self.numBlur = DirectSlider(
         parent=self,
         value=self.blur,
         # pos=(0.0, 0.0, 0.0), # for new window
         pos=(self.buttonbase_xcoord + 0.1, 0.0,
              (self.buttonbase_ycoord - self.textRowHeight * 0.5)),
         thumb_relief=None,
         range=(-10, 10),  # self.SAMPLES_MAX
         thumb_geom=self.circleModel.find(
             '**/tt_t_gui_mat_namePanelCircle'),
         frameTexture=self.barTexture,
         frameSize=(-0.5, 0.5, -0.08, 0.08),
         command=self.__changeBlur)
     self.numBlur.setScale(0.5)
     self.numBlur.setTransparency(True)
     self.numBlurText = OnscreenText(
         pos=(self.buttonbase_xcoord + 0.1,
              self.buttonbase_ycoord - self.textRowHeight * 0.2),
         scale=0.05,
         text="Blur Amount = {}".format(self.blur),
         style=5,
         mayChange=True)
Esempio n. 7
0
class MainMenu(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.accept("Exit",self.__exit)
        self.__rm = ResourcesManager()
        self.__destroySetting = False

    # 菜单界面
    def start(self):
        #全屏
        self.setFullScreen(0)

        #load background image
        self.__image = OnscreenImage(image='../../resources/images/menu/home1.png',scale=1)
        self.__image.setSx(self.getAspectRatio())
        self.__image.setTransparency(TransparencyAttrib.MAlpha)

        # 监听输入
        self.__keyInput = MenuPlayerInputHandler()
        self.accept("NewGame",self.__new_game)
        self.accept("LoadGame",self.__load_game)
        self.accept("Description",self.__description)
        self.accept("ChangeMenu",self.__change_menu)

        self.accept("a",self.setting_menu)
        self.accept("b",self.setting_destroy)

    # 设置全屏
    def setFullScreen(self,full):
        if full == 1 :
            self.__setFullscreen(2560,1600,0,0,1)
        else:
            self.__setFullscreen(800,600,150,50,0)

    # 清除界面,清除监听
    def destroy(self):
        self.__image.destroy()
        self.__keyInput.destroy()

    # 私有函数,选择全屏
    def __setFullscreen(self, width, height, posX, posY, full):
        winProps = WindowProperties()
        winProps.setOrigin(posX, posY)
        winProps.setSize(width, height)
        winProps.setFullscreen(full)
        self.win.requestProperties(winProps)

    # 私有函数,进入新建游戏界面
    def __new_game(self):
        print '进入new game'
        messenger.send("serious_new_game")
        print '发送了serious_new_game'

    # 私有函数,进入读取游戏界面
    def __load_game(self):
        print '进入load game'
        messenger.send("serious_load_game")
        print '发送了serious_load_game'

    # 私有函数,进入about界面
    def __description(self):
        print '进入description'
        messenger.send("serious_description")
        print '发送了serious_description'

    # 私有函数,用来自建的选择进入的游戏界面
    def __change_mode(self,image_path):
        self.__image.setImage(image_path)

    def __exit(self):
        print '进入exit'
        # self.__del__()
        exit()

    # 私有函数,更改游戏目录
    def __change_menu(self):
        switch_count = {0:'../../resources/images/menu/home1.png',
                        1:'../../resources/images/menu/home2.png',
                        2:'../../resources/images/menu/home3.png',
                        3:'../../resources/images/menu/home4.png',}
        self.__change_mode(switch_count[self.__keyInput.get_count()])

    #设置界面
    def setting_menu(self):
        if self.__destroySetting==False:
            # 设置界面背景图
            self.__background = OnscreenImage(image='../../resources/images/settings/setting_frame.png', pos=(0, 0, 0),
                                              scale=(1.0, 0, 0.7))
            self.__background.setTransparency(TransparencyAttrib.MAlpha)

            ##滑动条
            self.__slider = DirectSlider(pos=(0.16, 0, 0.26), scale=0.5, value=0.5, command=self.__setMusicSliderVolume,
                                         frameSize=(-1.0, 0.9, -0.06, 0.06),
                                         image='../../resources/images/settings/slide_bar.png',
                                         image_pos=(-0.05, 0, 0.0), image_scale=(1.0, 0, 0.05),
                                         thumb_image='../../resources/images/settings/slide_btn.png',
                                         thumb_image_pos=(-0.0, 0, 0.0), thumb_image_scale=0.1,
                                         thumb_frameSize=(0.0, 0.0, 0.0, 0.0))
            self.__slider.setTransparency(TransparencyAttrib.MAlpha)

            # self.__musicButton = DirectButton(pos=(0.9, 0, 0.75), text="Close", scale=0.1, pad=(0.2, 0.2), rolloverSound=None,
            #                                   clickSound=None, command=self.toggleMusicBox,extraArgs=[base])

            # 继续按钮
            self.__continueButton = DirectButton(pos=(-0.25, 0, 0.0), text="", scale=(0.2, 0, 0.1),
                                                 command=self.__continue_game,
                                                 image=("../../resources/images/settings/btn_continue_0.png",
                                                        "../../resources/images/settings/btn_continue_0.png"
                                                        , "../../resources/images/settings/btn_continue_1.png"),
                                                 frameColor=(0, 0, 0, 0))
            self.__continueButton.setTransparency(TransparencyAttrib.MAlpha)

            # 存档按钮
            self.__saveButton = DirectButton(pos=(0.33, 0, 0.0), text="", scale=(0.2, 0, 0.1), command=self.__save_game,
                                             image=("../../resources/images/settings/btn_save_0.png",
                                                    "../../resources/images/settings/btn_save_0.png"
                                                    , "../../resources/images/settings/btn_save_1.png"),
                                             frameColor=(0, 0, 0, 0))
            self.__saveButton.setTransparency(TransparencyAttrib.MAlpha)

            # 帮助按钮
            self.__helpButton = DirectButton(pos=(-0.25, 0, -0.25), text="", scale=(0.2, 0, 0.1), command=self.__help,
                                             image=("../../resources/images/settings/btn_help_0.png",
                                                    "../../resources/images/settings/btn_help_0.png"
                                                    , "../../resources/images/settings/btn_help_1.png"),
                                             frameColor=(0, 0, 0, 0))
            self.__helpButton.setTransparency(TransparencyAttrib.MAlpha)

            # 回到主界面按钮
            self.__homeButton = DirectButton(pos=(0.33, 0, -0.25), text="", scale=(0.2, 0, 0.1), command=self.__return_home,
                                             image=("../../resources/images/settings/btn_home_0.png",
                                                    "../../resources/images/settings/btn_home_0.png"
                                                    , "../../resources/images/settings/btn_home_1.png"),
                                             frameColor=(0, 0, 0, 0))
            self.__homeButton.setTransparency(TransparencyAttrib.MAlpha)

            # 设置滑动条value
            self.__slider['value'] = self.__rm.get_volume()

            self.__destroySetting = True

    #移除设置界面所有控件
    def setting_destroy(self):
        if self.__destroySetting==True:
            self.__background.destroy()
            self.__rm.set_volume(self.__slider['value'])
            self.__slider.destroy()
            # self.__musicButton.destroy()
            self.__continueButton.destroy()
            self.__saveButton.destroy()
            self.__helpButton.destroy()
            self.__homeButton.destroy()
            self.__destroySetting = False

    # 设置音乐声音大小
    def __setMusicSliderVolume(self):
        newVolume = self.__slider.guiItem.getValue()
        self.__rm.set_volume(newVolume)

    # 设置界面,私有函数,继续游戏
    def __continue_game(self):
        self.setting_destroy()

    # 设置界面,私有函数,存档
    def __save_game(self):
        self.setting_destroy()

    # 设置界面,私有函数,游戏帮助
    def __help(self):
        self.setting_destroy()

    # 设置界面,私有函数,回到主界面
    def __return_home(self):
        self.setting_destroy()
Esempio n. 8
0
 def loadStartScreen(self):
     self.startBG = OnscreenImage(image='world.jpg', pos=(0, 0, 0), scale=3)
     self.title = OnscreenText(text="Onwards,Term Project",
                               align=TextNode.ACenter,
                               fg=(1, 1, 1, 1),
                               pos=(0, 0.5),
                               scale=.08,
                               shadow=(0, 0, 0, 0.5))
     self.chooseGround = OnscreenText(text="Choose Land:",
                                      align=TextNode.ACenter,
                                      fg=(1, 1, 1, 1),
                                      pos=(-0.8, 0.25),
                                      scale=.08,
                                      shadow=(0, 0, 0, 0.5))
     self.buttonForest = DirectButton(pos=(-0.2, 0, 0.24),
                                      text="Forest",
                                      scale=.1,
                                      pad=(.2, .2),
                                      rolloverSound=None,
                                      clickSound=None,
                                      command=self.selected,
                                      extraArgs=["forest"],
                                      relief=SUNKEN)
     self.buttonDesert = DirectButton(pos=(0.4, 0, 0.24),
                                      text="Desert",
                                      scale=.1,
                                      pad=(.2, .2),
                                      rolloverSound=None,
                                      clickSound=None,
                                      command=self.selected,
                                      extraArgs=["desert"])
     self.chooseMusic = OnscreenText(text="Choose Music:",
                                     align=TextNode.ACenter,
                                     fg=(1, 1, 1, 1),
                                     pos=(-0.8, 0),
                                     scale=.08,
                                     shadow=(0, 0, 0, 0.5))
     self.buttonMusic1 = DirectButton(pos=(-0.2, 0, -0.01),
                                      text="Piano 1",
                                      scale=.1,
                                      pad=(.2, .2),
                                      rolloverSound=None,
                                      clickSound=None,
                                      command=self.selected,
                                      extraArgs=["piano1"],
                                      relief=SUNKEN)
     self.buttonMusic2 = DirectButton(pos=(0.35, 0, -0.01),
                                      text="Piano 2",
                                      scale=.1,
                                      pad=(.2, .2),
                                      rolloverSound=None,
                                      clickSound=None,
                                      command=self.selected,
                                      extraArgs=["piano2"])
     self.buttonMusic3 = DirectButton(pos=(0.8, 0, -0.01),
                                      text="None",
                                      scale=.1,
                                      pad=(.2, .2),
                                      rolloverSound=None,
                                      clickSound=None,
                                      command=self.selected,
                                      extraArgs=["stop"])
     self.volume = OnscreenText(text="Volume:",
                                align=TextNode.ACenter,
                                fg=(1, 1, 1, 1),
                                pos=(-0.8, -0.3),
                                scale=.08,
                                shadow=(0, 0, 0, 0.5))
     self.volumeSlider = DirectSlider(pos=(0.3, 0, -0.3),
                                      scale=0.7,
                                      value=.5,
                                      command=self.setMusicVolume)
     self.enterInstruction = OnscreenText(text="Press 'Enter' to Begin",
                                          align=TextNode.ACenter,
                                          fg=(1, 1, 1, 1),
                                          pos=(0, -0.5),
                                          scale=.08,
                                          shadow=(0, 0, 0, 0.5))
     self.accept("enter", self.loadModels)
Esempio n. 9
0
class Ground(ShowBase):
    def __init__(self):
        # Initialize the ShowBase class from which we inherit,which will
        # create a window and set up everything we need for rendering into it.
        ShowBase.__init__(self)

        self.setBackgroundColor(240, 35, 35, 1)

        # Make a variable to store the unique collision string count
        self.collCount = 0

        #set scale of ground
        self.scaleBy = 120

        #disable mouse control of camera and manually place it
        base.disableMouse()
        camera.setPos(self.scaleBy // 2, self.scaleBy // 2, 2)

        #quit program when Escapse key pressed
        self.accept("escape", sys.exit)
        self.accept("a", self.runMiniGame)
        #set default settings of game
        self.setting = "forest"
        self.music = base.loader.loadSfx("music1.ogg")
        self.music.setVolume(.5)

        self.miniGameRun = False

        #initialization starting screen
        self.loadStartScreen()

    #display start screen w/ text and buttons
    def loadStartScreen(self):
        self.startBG = OnscreenImage(image='world.jpg', pos=(0, 0, 0), scale=3)
        self.title = OnscreenText(text="Onwards,Term Project",
                                  align=TextNode.ACenter,
                                  fg=(1, 1, 1, 1),
                                  pos=(0, 0.5),
                                  scale=.08,
                                  shadow=(0, 0, 0, 0.5))
        self.chooseGround = OnscreenText(text="Choose Land:",
                                         align=TextNode.ACenter,
                                         fg=(1, 1, 1, 1),
                                         pos=(-0.8, 0.25),
                                         scale=.08,
                                         shadow=(0, 0, 0, 0.5))
        self.buttonForest = DirectButton(pos=(-0.2, 0, 0.24),
                                         text="Forest",
                                         scale=.1,
                                         pad=(.2, .2),
                                         rolloverSound=None,
                                         clickSound=None,
                                         command=self.selected,
                                         extraArgs=["forest"],
                                         relief=SUNKEN)
        self.buttonDesert = DirectButton(pos=(0.4, 0, 0.24),
                                         text="Desert",
                                         scale=.1,
                                         pad=(.2, .2),
                                         rolloverSound=None,
                                         clickSound=None,
                                         command=self.selected,
                                         extraArgs=["desert"])
        self.chooseMusic = OnscreenText(text="Choose Music:",
                                        align=TextNode.ACenter,
                                        fg=(1, 1, 1, 1),
                                        pos=(-0.8, 0),
                                        scale=.08,
                                        shadow=(0, 0, 0, 0.5))
        self.buttonMusic1 = DirectButton(pos=(-0.2, 0, -0.01),
                                         text="Piano 1",
                                         scale=.1,
                                         pad=(.2, .2),
                                         rolloverSound=None,
                                         clickSound=None,
                                         command=self.selected,
                                         extraArgs=["piano1"],
                                         relief=SUNKEN)
        self.buttonMusic2 = DirectButton(pos=(0.35, 0, -0.01),
                                         text="Piano 2",
                                         scale=.1,
                                         pad=(.2, .2),
                                         rolloverSound=None,
                                         clickSound=None,
                                         command=self.selected,
                                         extraArgs=["piano2"])
        self.buttonMusic3 = DirectButton(pos=(0.8, 0, -0.01),
                                         text="None",
                                         scale=.1,
                                         pad=(.2, .2),
                                         rolloverSound=None,
                                         clickSound=None,
                                         command=self.selected,
                                         extraArgs=["stop"])
        self.volume = OnscreenText(text="Volume:",
                                   align=TextNode.ACenter,
                                   fg=(1, 1, 1, 1),
                                   pos=(-0.8, -0.3),
                                   scale=.08,
                                   shadow=(0, 0, 0, 0.5))
        self.volumeSlider = DirectSlider(pos=(0.3, 0, -0.3),
                                         scale=0.7,
                                         value=.5,
                                         command=self.setMusicVolume)
        self.enterInstruction = OnscreenText(text="Press 'Enter' to Begin",
                                             align=TextNode.ACenter,
                                             fg=(1, 1, 1, 1),
                                             pos=(0, -0.5),
                                             scale=.08,
                                             shadow=(0, 0, 0, 0.5))
        self.accept("enter", self.loadModels)

    #change button reliefs if clicked or not & game settings based on button
    def selected(self, pressed):
        if pressed == "desert":
            self.setting = "desert"
            self.buttonForest['relief'] = RAISED
            self.buttonDesert['relief'] = SUNKEN
        elif pressed == "forest":
            self.setting = "forest"
            self.buttonForest['relief'] = SUNKEN
            self.buttonDesert['relief'] = RAISED
        if pressed == "piano1":
            self.music.stop()
            self.music = base.loader.loadSfx("music1.ogg")
            self.music.setLoop(True)
            self.music.play()
            self.buttonMusic1['relief'] = SUNKEN
            self.buttonMusic2['relief'] = RAISED
            self.buttonMusic3['relief'] = RAISED
        elif pressed == "piano2":
            self.music.stop()
            self.music = base.loader.loadSfx("music2.ogg")
            self.music.setLoop(True)
            self.music.play()
            self.buttonMusic1['relief'] = RAISED
            self.buttonMusic2['relief'] = SUNKEN
            self.buttonMusic3['relief'] = RAISED
        elif pressed == "stop":
            self.music.stop()
            self.buttonMusic1['relief'] = RAISED
            self.buttonMusic2['relief'] = RAISED
            self.buttonMusic3['relief'] = SUNKEN

    #change volume based on slider position
    def setMusicVolume(self):
        vol = self.volumeSlider.guiItem.getValue()
        self.music.setVolume(vol)

    #load models when 'enter' pressed
    def loadModels(self):
        self.startBG.destroy()
        self.title.destroy()
        self.chooseGround.destroy()
        self.buttonForest.destroy()
        self.buttonDesert.destroy()
        self.chooseMusic.destroy()
        self.buttonMusic1.destroy()
        self.buttonMusic2.destroy()
        self.buttonMusic3.destroy()
        self.enterInstruction.destroy()
        self.volumeSlider.destroy()
        self.volume.destroy()

        self.cTrav = CollisionTraverser()

        self.lastHitEntry = "is an entry"
        self.plants = []
        self.plantColls = []
        self.animals = []
        self.animalColls = []

        self.miniGameBoxes = []

        self.axes = []
        self.planters = []
        self.haveAxe = False
        self.havePlanter = False
        self.selectedPlanterOpt = 0

        self.planterOptionsForest = [("plants/foliage01.egg.pz", 11, 12),
                                     ("plants/foliage02.egg.pz", -12, 14),
                                     ("plants/foliage03.egg.pz", 14, 23),
                                     ("plants/foliage04.egg.pz", 0, 0),
                                     ("plants/foliage05.egg.pz", 6, 22),
                                     ("plants/foliage09.egg.pz", -3, 10),
                                     ("chicken.egg", 0, 0)]

        self.planterOptionsDesert = [("plants/shrubbery.egg.pz", 1, 14),
                                     ("plants/cactus1.egg", 0, 12),
                                     ("plants/cactus2.egg", 2.5, 11),
                                     ("chicken.egg", 0, 0)]

        #display instructions
        self.loadText()

        #respond when arrow keys are pressed
        self.accept("arrow_up", self.eventArrowPressed, ["up"])
        self.accept("arrow_up-repeat", self.eventArrowPressed, ["up"])
        self.accept("arrow_right", self.eventArrowPressed, ["right"])
        self.accept("arrow_right-repeat", self.eventArrowPressed, ["right"])
        self.accept("arrow_left", self.eventArrowPressed, ["left"])
        self.accept("arrow_left-repeat", self.eventArrowPressed, ["left"])
        self.accept("arrow_down", self.eventArrowPressed, ["down"])
        self.accept("arrow_down-repeat", self.eventArrowPressed, ["down"])
        self.accept("f", self.eventAerielView)
        self.accept("0", self.restartGame)
        self.accept("enter", self.doNothing)

        groundTexture = loader.loadTexture(self.setting + ".jpg")

        #load starting square of land
        land = loader.loadModel("box")
        land.setPos(0, 0, 0)
        land.setSy(self.scaleBy)
        land.setSx(self.scaleBy)
        land.setSz(0.5)
        land.setTexture(groundTexture, 1)

        self.spanGround = [(0, 0)]
        self.ground = land
        self.ground.reparentTo(render)

        #load main char
        self.mainChar = loader.loadModel("box")
        self.mainChar.reparentTo(camera)
        self.mainChar.setPos(0, 10, -2)
        self.mainChar.setColorScale(0.6, 0.6, 1.0, 1.0)
        self.moveMainCharX = 0.5
        self.moveMainCharY = 0.75

        #load main char's collision ray onto screen & make char a collider
        self.mainCharGroundRay = CollisionRay()
        self.mainCharGroundRay.setOrigin(0.5, 0, 30)
        self.mainCharGroundRay.setDirection(0, 0, -1)
        self.mainCharGroundCol = CollisionNode('mainCharRay')
        self.mainCharGroundCol.addSolid(self.mainCharGroundRay)
        self.mainCharGroundCol.setFromCollideMask(CollideMask.bit(0))
        self.mainCharGroundCol.setIntoCollideMask(CollideMask.allOff())
        self.mainCharGroundColNp = self.mainChar.attachNewNode(\
                                                        self.mainCharGroundCol)
        self.mainCharGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.mainCharGroundColNp,\
                                                    self.mainCharGroundHandler)
        #load camera's collision ray & make it a collider
        self.camGroundRay = CollisionRay()
        self.camGroundRay.setOrigin(0, 0, 30)
        self.camGroundRay.setDirection(0, 0, -1)
        self.camGroundCol = CollisionNode('camRay')
        self.camGroundCol.addSolid(self.camGroundRay)
        self.camGroundCol.setFromCollideMask(CollideMask.bit(0))
        self.camGroundCol.setIntoCollideMask(CollideMask.allOff())
        self.camGroundColNp = self.camera.attachNewNode(self.camGroundCol)
        self.camGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.camGroundColNp, self.camGroundHandler)

        #shows collision nodes (for debugging)
        # self.mainCharGroundColNp.show()
        # self.camGroundColNp.show()

        self.curPos = self.mainChar.getPos()
        self.cameraCurPos = camera.getPos()

        # shows collisions occuring (for debugging)
        # self.cTrav.showCollisions(render)

        #continuously check for collisions
        taskMgr.add(self.checkCollisions, "checkCollisionsTask")

        #initialize fog so that scene in distance is blocked from view
        color = (240, 35, 35)
        expfog = Fog("Scene-wide exponential Fog object")
        expfog.setColor(*color)
        expfog.setExpDensity(0.006)
        render.setFog(expfog)
        base.setBackgroundColor(color)

    #display instructions on screen top & title on botton
    def loadText(self):
        self.bottomTitle = \
            OnscreenText(text="Onwards,Term Project",
                         parent=base.a2dBottomRight,align=TextNode.ARight,
                         fg=(1,1,1,1),pos=(-0.1,0.1),scale=.08,
                         shadow=(0,0,0,0.5))
        self.startInstructions = \
           OnscreenText(text="Press Arrow Keys to explore. Press and hold 'f' "+
                              "to activate Aeriel View. Press Esc to exit."+
                              "\nPress '0' to go to Start Screen",
                         parent=base.a2dTopLeft,align=TextNode.ALeft,
                         pos=(0.05,-0.08),fg=(1,1,1,1),scale=.06,
                         shadow=(0,0,0,0.5))

    #set what happens when arrow keys pressed
    def eventArrowPressed(self, dir):
        self.curPos = self.mainChar.getPos()
        self.cameraCurPos = camera.getPos()
        x, y, z = base.camera.getPos()
        if dir == "up":
            camera.setPos(x, y + self.moveMainCharY, z)
        elif dir == "down":
            camera.setPos(x, y - self.moveMainCharY, z)
        elif dir == "right":
            camera.setPos(x + self.moveMainCharX, y, z)
        elif dir == "left":
            camera.setPos(x - self.moveMainCharX, y, z)
        self.checkExtend(dir)

    #set what happens when x pressed & axe activated
    def eventAxe(self):
        deleted = False
        if len(self.plantColls) > 0:
            for i in range(len(self.plantColls)):
                if (self.lastHitEntry in self.plantColls[i][0].getName()):
                    self.plantColls[i][0].remove_node()
                    self.plants[i].remove_node()
                    self.plantColls = self.plantColls[:i] + self.plantColls[i +
                                                                            1:]
                    self.plants = self.plants[:i] + self.plants[i + 1:]
                    deleted = True
                    break
        if len(self.animalColls) > 0 and deleted == False:
            for i in range(len(self.animalColls)):
                if (self.lastHitEntry in self.animalColls[i][0].getName()):
                    self.animalColls[i][0].remove_node()
                    self.animals[i][0].remove_node()
                    self.animalColls = self.animalColls[:i]+\
                                       self.animalColls[i+1:]
                    self.animals = self.animals[:i] + self.animals[i + 1:]
                    deleted = True
                    break
        if len(self.miniGameBoxes) > 0 and deleted == False:
            for i in range(len(self.miniGameBoxes)):
                if (self.lastHitEntry
                        in self.miniGameBoxes[i][1][0].getName()):
                    self.miniGameBoxes[i][1][0].remove_node()
                    self.miniGameBoxes[i][0].remove_node()
                    self.miniGameBoxes = self.miniGameBoxes[:i]+\
                                         self.miniGameBoxes[i+1:]
                    deleted = True
                    self.acceptMiniGame()
                    break

    #set what happens when w pressed & planter activated
    def eventPlanter(self):
        #create new object and position it in front of main character
        x, y, z = camera.getPos()
        if self.setting == "forest":
            plantType,shiftX,shiftY = \
                            self.planterOptionsForest[self.selectedPlanterOpt]
        else:
            plantType,shiftX,shiftY = \
                            self.planterOptionsDesert[self.selectedPlanterOpt]
        if plantType == "chicken.egg":
            self.newAnimal()
        else:
            plant = loader.loadModel(plantType)
            plant.setScale(0.2)
            plant.setPos(x + shiftX, y + shiftY, 0)
            plant.reparentTo(render)
            if plantType == "plants/cactus1.egg":
                plant.setTexture(loader.loadTexture("cactusskin.png"), 1)
                plant.setScale(1)
                plantColl = self.initCollisionSphere(plant, 0.1, False)
            elif plantType == "plants/cactus2.egg":
                plant.setScale(1)
                plant.setZ(0.5)
                plantColl = self.initCollisionSphere(plant, 0.8, False)
            elif plantType == "plants/shrubbery.egg.pz":
                plant.setScale(0.15)
                plantColl = self.initCollisionSphere(plant, 0.2, False)
            else:
                plantColl = self.initCollisionSphere(plant, 0.08, False)
            self.plants += [plant]
            self.plantColls += [plantColl]

    #shift camera upwards to show aeriel view
    def eventAerielView(self):
        self.x, self.y, self.z = camera.getPos()
        shiftPos = camera.posInterval(0.1,\
                                     Point3(self.x,self.y + 30,self.z + 150))
        shiftAngle = camera.hprInterval(0.2, Vec3(0, -90, 0))
        aerielView = Sequence(shiftPos, shiftAngle)
        aerielView.start()
        self.moveMainCharX = 2
        self.moveMainCharY = 3
        self.accept("f-up", self.eventNormalView)

    #shift camera back to normal view
    def eventNormalView(self):
        shiftPos = camera.posInterval(0.1, Point3(self.x, self.y, self.z))
        shiftAngle = camera.hprInterval(0.2, Vec3(0, 0, 0))
        aerielView = Sequence(shiftPos, shiftAngle)
        aerielView.start()
        self.moveMainCharX = 0.5
        self.moveMainCharY = 0.75

    #check whether or not to extend ground
    def checkExtend(self, dir):
        x, y, z = base.camera.getPos()
        checkV = (0, 0)
        whole = self.scaleBy
        #Up
        checkX = x // self.scaleBy
        checkY = (y + whole) // self.scaleBy
        cUp = (checkX, checkY)
        if cUp not in self.spanGround:
            self.spanGround += [cUp]
            self.extendScene()
        #Down
        checkX = x // self.scaleBy
        checkY = (y - whole) // self.scaleBy
        cDown = (checkX, checkY)
        if cDown not in self.spanGround:
            self.spanGround += [cDown]
            self.extendScene()
        #Right
        checkX = (x + whole) // self.scaleBy
        checkY = y // self.scaleBy
        cRight = (checkX, checkY)
        if cRight not in self.spanGround:
            self.spanGround += [cRight]
            self.extendScene()
        #Left
        checkX = (x - whole) // self.scaleBy
        checkY = y // self.scaleBy
        cLeft = (checkX, checkY)
        if cLeft not in self.spanGround:
            self.spanGround += [cLeft]
            self.extendScene()
        #Upper Right Diagonal
        checkX = (x + whole) // self.scaleBy
        checkY = (y + whole) // self.scaleBy
        cUpRight = (checkX, checkY)
        if cUpRight not in self.spanGround:
            self.spanGround += [cUpRight]
            self.extendScene()
        #Upper Left Diagonal
        checkX = (x - whole) // self.scaleBy
        checkY = (y + whole) // self.scaleBy
        cUpLeft = (checkX, checkY)
        if cUpLeft not in self.spanGround:
            self.spanGround += [cUpLeft]
            self.extendScene()
        #Lower Right Diagonal
        checkX = (x + whole) // self.scaleBy
        checkY = (y - whole) // self.scaleBy
        cUpRight = (checkX, checkY)
        if cUpRight not in self.spanGround:
            self.spanGround += [cUpRight]
            self.extendScene()
        #Lower Left Diagonal
        checkX = (x - whole) // self.scaleBy
        checkY = (y - whole) // self.scaleBy
        cUpLeft = (checkX, checkY)
        if cUpLeft not in self.spanGround:
            self.spanGround += [cUpLeft]
            self.extendScene()

    #extend ground
    def extendScene(self):
        #add square of ground
        groundTexture = loader.loadTexture(self.setting + ".jpg")
        new = loader.loadModel("box")
        new.setSy(self.scaleBy)
        new.setSx(self.scaleBy)
        new.setSz(0.5)
        new.setTexture(groundTexture, 1)
        newPos = self.spanGround[-1]
        newPosX = newPos[0] * self.scaleBy
        newPosY = newPos[1] * self.scaleBy
        new.setPos(newPosX, newPosY, 0)
        self.newground = new
        self.newground.reparentTo(render)

        #load axe if haven't collided with one yet
        if not self.haveAxe:
            axe = loader.loadModel("axe")
            axe.setColor(0, 0, 0, 1.0)
            axe.setScale(0.5, 1, 0.5)
            axe.setPos(randint(newPosX, newPosX + self.scaleBy),
                       randint(newPosY, newPosY + self.scaleBy), 0.3)
            axe.reparentTo(render)
            axeObject = loader.loadModel("axe01")
            axeObject.setScale(3)
            axeObject.setPos(0.5, 0, 2)
            axeObject.setHpr(0, 65, 35)
            axeObject.reparentTo(axe)
            axeColl = self.initCollisionSphere(axe, 1, False)
            self.axes += [axe]

        #load planter if haven't collided with one yet
        if not self.havePlanter:
            planter = loader.loadModel("planter")
            planter.setColor(0, 0, 1, 1)
            planter.setScale(1, 1, 1)
            planter.setPos(randint(newPosX, newPosX + self.scaleBy),
                           randint(newPosY, newPosY + self.scaleBy), 0.3)
            planter.reparentTo(render)
            planterBag = loader.loadModel("planter01")
            planterBag.setScale(1.5)
            planterBag.setHpr(0, 30, 0)
            planterBag.setPos(0.75, 0, 1.25)
            planterBag.reparentTo(planter)
            planterColl = self.initCollisionSphere(planter, 1, False)
            self.planters += [planter]

        #load random number of mini game boxes
        for i in range(randint(1, 4)):
            miniGameBox = loader.loadModel("box")
            miniGameBox.setPos(randint(newPosX, newPosX + self.scaleBy),
                               randint(newPosY, newPosY + self.scaleBy), 0.5)
            miniGameBox.reparentTo(render)
            miniGameBoxColl = self.initCollisionSphere(miniGameBox, 1.3, False)
            self.miniGameBoxes += [[miniGameBox, miniGameBoxColl]]

        #load certain plants in forest setting
        if self.setting == "forest":
            for i in range(randint(3, 15)):
                #place plant 1
                plant1 = loader.loadModel("plants/foliage01.egg.pz")
                plant1.setScale(0.2)
                plant1.setPos(randint(newPosX, newPosX + self.scaleBy),
                              randint(newPosY, newPosY + self.scaleBy), 0)
                plant1.reparentTo(render)
                plantColl = self.initCollisionSphere(plant1, 0.08, False)
                self.plants += [plant1]
                self.plantColls += [plantColl]
            for i in range(randint(3, 15)):
                #place plant2
                plant2 = loader.loadModel("plants/foliage02.egg.pz")
                plant2.setScale(0.2)
                plant2.setPos(randint(newPosX, newPosX + self.scaleBy),
                              randint(newPosY, newPosY + self.scaleBy), 0)
                plant2.reparentTo(render)
                plantColl = self.initCollisionSphere(plant2, 0.06, False)
                self.plants += [plant2]
                self.plantColls += [plantColl]
            for i in range(randint(3, 15)):
                #place plant3
                plant3 = loader.loadModel("plants/foliage03.egg.pz")
                plant3.setScale(0.8)
                plant3.setPos(randint(newPosX, newPosX + self.scaleBy),
                              randint(newPosY, newPosY + self.scaleBy), 0)
                plant3.reparentTo(render)
                plantColl = self.initCollisionSphere(plant3, 0.06, False)
                self.plants += [plant3]
                self.plantColls += [plantColl]
            for i in range(randint(3, 15)):
                #place plant4
                plant4 = loader.loadModel("plants/foliage04.egg.pz")
                plant4.setScale(0.6)
                plant4.setPos(randint(newPosX, newPosX + self.scaleBy),
                              randint(newPosY, newPosY + self.scaleBy), 0)
                plant4.reparentTo(render)
                plantColl = self.initCollisionSphere(plant4, 0.07, False)
                self.plants += [plant4]
                self.plantColls += [plantColl]
            for i in range(randint(3, 15)):
                #place plant5
                plant5 = loader.loadModel("plants/foliage05.egg.pz")
                plant5.setScale(0.6)
                plant5.setPos(randint(newPosX, newPosX + self.scaleBy),
                              randint(newPosY, newPosY + self.scaleBy), 0)
                plant5.reparentTo(render)
                plantColl = self.initCollisionSphere(plant5, 0.05, False)
                self.plants += [plant5]
                self.plantColls += [plantColl]
            for i in range(randint(3, 15)):
                #place plant6
                plant6 = loader.loadModel("plants/foliage09.egg.pz")
                plant6.setScale(0.6)
                plant6.setPos(randint(newPosX, newPosX + self.scaleBy),
                              randint(newPosY, newPosY + self.scaleBy), 0)
                plant6.reparentTo(render)
                plantColl = self.initCollisionSphere(plant6, 0.08, False)
                self.plants += [plant6]
                self.plantColls += [plantColl]
            #load walking animals
            if newPos[0] % 4 == 0 and newPos[1] % 3 == 0:
                animal = loader.loadModel("box")
                animal.setScale(1)
                animal.setPos(randint(newPosX, newPosX + self.scaleBy),
                              randint(newPosY, newPosY + self.scaleBy), -0.75)
                animal.reparentTo(render)
                animalColl = self.initCollisionSphere(animal, 0.75, False)
                chicken = loader.loadModel("chicken")
                chicken.setScale(0.15)
                chicken.setPos(0.5, 0.5, 1.25)
                chicken.setHpr(0, 0, 0)
                chicken.reparentTo(animal)
                self.animalColls += [animalColl]
                animalGroundHandler = CollisionHandlerQueue()
                self.animals += [[animal, randint(0, 4), animalGroundHandler]]
                self.cTrav.addCollider(animalColl[0], animalGroundHandler)
        #load certain plants in desert setting
        elif self.setting == "desert":
            for i in range(randint(0, 6)):
                #place shrubbery
                plant0 = loader.loadModel("plants/shrubbery.egg.pz")
                plant0.setScale(0.1)
                plant0.setPos(randint(newPosX, newPosX + self.scaleBy),
                              randint(newPosY, newPosY + self.scaleBy), 0)
                plant0.reparentTo(render)
                plantColl = self.initCollisionSphere(plant0, 0.3, False)
                self.plants += [plant0]
                self.plantColls += [plantColl]
            for i in range(randint(0, 6)):
                #place cactus1
                plant1 = loader.loadModel("plants/cactus1.egg")
                plant1.setScale(1)
                plant1.setPos(randint(newPosX, newPosX + self.scaleBy),
                              randint(newPosY, newPosY + self.scaleBy), 0)
                plant1.setTexture(loader.loadTexture("cactusskin.png"), 1)
                plant1.reparentTo(render)
                plantColl = self.initCollisionSphere(plant1, 0.1, False)
                self.plants += [plant1]
                self.plantColls += [plantColl]
            for i in range(randint(0, 6)):
                #place cactus2
                plant2 = loader.loadModel("plants/cactus2.egg")
                plant2.setScale(1)
                plant2.setPos(randint(newPosX, newPosX + self.scaleBy),
                              randint(newPosY, newPosY + self.scaleBy), 0.5)
                plant2.reparentTo(render)
                plantColl = self.initCollisionSphere(plant2, 0.8, False)
                self.plants += [plant2]
                self.plantColls += [plantColl]
            #load walking animals
            if newPos[0] % 4 == 0 and newPos[1] % 3 == 0:
                animal = loader.loadModel("box")
                animal.setScale(1)
                animal.setPos(randint(newPosX, newPosX + self.scaleBy),
                              randint(newPosY, newPosY + self.scaleBy), -0.75)
                animal.reparentTo(render)
                animalColl = self.initCollisionSphere(animal, 0.75, False)
                chicken = loader.loadModel("chicken")
                chicken.setScale(0.15)
                chicken.setPos(0.5, 0.5, 1.25)
                chicken.setHpr(0, 0, 0)
                chicken.reparentTo(animal)
                self.animalColls += [animalColl]
                animalGroundHandler = CollisionHandlerQueue()
                self.animals += [[animal, randint(0, 4), animalGroundHandler]]
                self.cTrav.addCollider(animalColl[0], animalGroundHandler)

    #load animal in front of main char
    def newAnimal(self):
        #load and initialize box for chicken to be rendered to
        x, y, z = self.cameraCurPos
        animal = loader.loadModel("box")
        animal.setScale(1)
        animal.setPos(x + 1, y + 15, -0.75)
        animal.reparentTo(render)
        animalColl = self.initCollisionSphere(animal, 0.75, False)
        #load chicken
        chicken = loader.loadModel("chicken")
        chicken.setScale(0.15)
        chicken.setPos(0.5, 0.5, 1.25)
        chicken.setHpr(0, 0, 0)
        chicken.reparentTo(animal)
        #store animal into
        self.animalColls += [animalColl]
        animalGroundHandler = CollisionHandlerQueue()
        self.animals += [[animal, 0, animalGroundHandler]]
        self.cTrav.addCollider(animalColl[0], animalGroundHandler)
        taskMgr.add(self.moveAnimal, "moveAnimalsTask")
        taskMgr.add(self.checkAnimalCollisions, "checkAnimalCollisionsTask")

    #move every animal in self.animals forward
    def moveAnimal(self, task):
        for animal in self.animals:
            x, y, z = animal[0].getPos()
            if animal[1] == 0:
                animal[0].setPos(x, y + 0.025, z)
                animal[0].setHpr(180, 0, 0)
            elif animal[1] == 2:
                animal[0].setPos(x + 0.025, y, z)
                animal[0].setHpr(90, 0, 0)
            elif animal[1] == 1:
                animal[0].setPos(x, y - 0.025, z)
                animal[0].setHpr(0, 0, 0)
            elif animal[1] == 3:
                animal[0].setPos(x - 0.025, y, z)
                animal[0].setHpr(270, 0, 0)
        return Task.cont

    #check if animal collided with surroundings
    def checkAnimalCollisions(self, task):
        #check collisions of each automatically moving animals
        for animal in self.animals:
            entries = list(animal[2].getEntries())
            entries.sort(key=lambda x: x.getSurfacePoint(render).getZ())
            if len(entries) > 0:
                x, y, z = animal[0].getPos()
                if animal[1] == 0:
                    animal[0].setPos(x, y - 0.03, z)
                elif animal[1] == 2:
                    animal[0].setPos(x - 0.03, y, z)
                elif animal[1] == 1:
                    animal[0].setPos(x, y + 0.03, z)
                elif animal[1] == 3:
                    animal[0].setPos(x + 0.03, y, z)
                animal[1] = (animal[1] + 1) % 4
        return Task.cont

    #check if main character collided with surroundings
    def checkCollisions(self, task):
        #check collisions for mainChar
        entries = list(self.mainCharGroundHandler.getEntries())
        entries.sort(key=lambda x: x.getSurfacePoint(render).getZ())
        #if bump into tree,go back to last position so char doesn't go in tree
        if (len(entries) > 0
                and ("axe" not in entries[0].getIntoNode().getName())
                and ("planter" not in entries[0].getIntoNode().getName())):
            camera.setPos(self.cameraCurPos)
            #show what was last hit item
            if self.haveAxe:
                #unhighlight last entry
                unhighlighted = True
                if unhighlighted:
                    for i in range(len(self.plantColls)):
                        if (self.lastHitEntry in \
                            self.plantColls[i][0].getName()):
                            self.plants[i].setColorScale(1, 1, 1, 1.0)
                            unhighlighted = False
                            break
                if unhighlighted:
                    for i in range(len(self.animalColls)):
                        if (self.lastHitEntry in \
                            self.animalColls[i][0].getName()):
                            self.animals[i][0].setColorScale(1, 1, 1, 1.0)
                            unhighlighted = False
                            break
                if unhighlighted:
                    for i in range(len(self.miniGameBoxes)):
                        if(self.lastHitEntry in \
                            self.miniGameBoxes[i][1][0].getName()):
                            self.miniGameBoxes[i][0].setColorScale(
                                1, 1, 1, 1.0)
                            unhighlighted = False
                            break
                #find last entry & highlight it
                if len(entries) > 0:
                    self.lastHitEntry = entries[0].getIntoNode().getName()
                    highlighted = True
                    if highlighted:
                        for i in range(len(self.plantColls)):
                            if (self.lastHitEntry in \
                                self.plantColls[i][0].getName()):
                                self.plants[i].setColorScale(
                                    0.6, 0.6, 1.0, 1.0)
                                highlighted = False
                                break
                    if highlighted:
                        for i in range(len(self.animalColls)):
                            if (self.lastHitEntry in \
                                self.animalColls[i][0].getName()):
                                self.animals[i][0].setColorScale(0.6,\
                                                                 0.6,1.0,1.0)
                                highlighted = False
                                break
                    if highlighted:
                        for i in range(len(self.miniGameBoxes)):
                            if(self.lastHitEntry in \
                                self.miniGameBoxes[i][1][0].getName()):
                                self.miniGameBoxes[i][0].setColorScale(0.6,\
                                                                    0.6,1.0,1.0)
                                highlighted = False
                                break
        #if bump into axe,activate axe & delete it
        elif len(entries) > 0 and ("axe"
                                   in entries[0].getIntoNode().getName()):
            self.haveAxe = True
            for obj in self.axes:
                obj.remove_node()

        #if bump into planter,activate planter & delete it
        elif (len(entries) > 0
              and ("planter" in entries[0].getIntoNode().getName())):
            self.havePlanter = True
            for obj in self.planters:
                obj.remove_node()
        #change onscreen text & add keyboard events if hit axe and/or planter
        if self.havePlanter:
            self.accept('w', self.eventPlanter)
            self.planterInstructions = OnscreenText(
                text="Press 'w' to plant." +
                "Press 'q' or 'e' to change plant",
                parent=base.a2dTopLeft,
                align=TextNode.ALeft,
                pos=(0.05, -0.28),
                fg=(1, 1, 1, 1),
                scale=.06,
                shadow=(0, 0, 0, 0.5))
            self.accept('e', self.changeSelectedPlanterOpt, ["e"])
            self.accept('q', self.changeSelectedPlanterOpt, ["q"])
        if self.haveAxe:
            self.accept('x', self.eventAxe)
            self.axeInstructions = OnscreenText(text="Press 'x' to cut plant.",
                                                parent=base.a2dTopLeft,
                                                align=TextNode.ALeft,
                                                pos=(0.05, -0.20),
                                                fg=(1, 1, 1, 1),
                                                scale=.06,
                                                shadow=(0, 0, 0, 0.5))
        return Task.cont

    #change selecter planter opt so that it stays w/in list
    def changeSelectedPlanterOpt(self, direction):
        #in forest,modify selectedPlantOpt if it goes out of range
        if self.setting == "forest":
            if direction == "e":
                self.selectedPlanterOpt += 1
                if self.selectedPlanterOpt >= len(self.planterOptionsForest):
                    self.selectedPlanterOpt -= len(self.planterOptionsForest)
            else:
                self.selectedPlanterOpt -= 1
                if self.selectedPlanterOpt <= -1 * len(
                        self.planterOptionsForest):
                    self.selectedPlanterOpt += len(self.planterOptionsForest)
        #in desert,modify selectedPlantOpt if it goes out of range
        else:
            if direction == "e":
                self.selectedPlanterOpt += 1
                if self.selectedPlanterOpt >= len(self.planterOptionsDesert):
                    self.selectedPlanterOpt -= len(self.planterOptionsDesert)
            else:
                self.selectedPlanterOpt -= 1
                if self.selectedPlanterOpt <= -1 * len(
                        self.planterOptionsDesert):
                    self.selectedPlanterOpt += len(self.planterOptionsDesert)

    #source: https://www.panda3d.org/manual/index.php/Event_Example
    #initialize collision sphere around object
    def initCollisionSphere(self, obj, circR, show=False):
        # Get the size of the object for the collision sphere.
        bounds = obj.getChild(0).getBounds()
        radius = bounds.getRadius() * circR

        center = bounds.getCenter()
        #make center of collision circle be on ground around tree trunks
        center[2] = 0
        if obj.getName() == "foliage01.egg.pz":
            pass
        elif obj.getName() == "foliage02.egg.pz":
            center[0] -= 4
        elif obj.getName() == "foliage03.egg.pz":
            center[0] -= 3.5
        elif obj.getName() == "foliage04.egg.pz":
            center[0] += 11
            center[1] -= 1
        elif obj.getName() == "foliage05.egg.pz":
            center[0] += 1.5
            center[1] -= 4
        elif obj.getName() == "foliage09.egg.pz":
            center[0] -= 2.5
            center[1] -= 2

        # Create a collision sphere and name it something understandable.
        collSphereStr = 'CollisionHull' + str(
            self.collCount) + "_" + obj.getName()
        self.collCount += 1
        cNode = CollisionNode(collSphereStr)
        cNode.addSolid(CollisionSphere(center, radius))

        cNodepath = obj.attachNewNode(cNode)
        if show:
            cNodepath.show()

        # Return a tuple with the collision node and its corrsponding string so
        # that the bitmask can be set.
        return (cNodepath, collSphereStr)

    #remove functionality from keyboard key
    def doNothing(self):
        pass

    #ask player if they want to continue to minigame screen
    def acceptMiniGame(self):
        self.question = OnscreenText(text="Do you want to play a minigame?",
                                     align=TextNode.ACenter,
                                     fg=(1, 1, 1, 1),
                                     pos=(0, 0.5),
                                     scale=.08,
                                     shadow=(0, 0, 0, 0.5))

        self.buttonNo = DirectButton(pos=(-0.2, 0, 0.24),
                                     text="No",
                                     scale=.1,
                                     pad=(.2, .2),
                                     rolloverSound=None,
                                     clickSound=None,
                                     command=self.miniSelected,
                                     extraArgs=["no"],
                                     relief=SUNKEN)

        self.buttonYes = DirectButton(pos=(0.2, 0, 0.24),
                                      text="Yes",
                                      scale=.1,
                                      pad=(.2, .2),
                                      rolloverSound=None,
                                      clickSound=None,
                                      command=self.miniSelected,
                                      extraArgs=["yes"],
                                      relief=RAISED)

        self.enterInstruction = OnscreenText(text="Press 'enter' to continue",
                                             align=TextNode.ACenter,
                                             fg=(1, 1, 1, 1),
                                             pos=(0, -0.5),
                                             scale=.08,
                                             shadow=(0, 0, 0, 0.5))

        self.accept("enter", self.executeMiniButtons)

    #change values of button when pressed
    def miniSelected(self, pressed):
        if pressed == "yes":
            self.miniGameRun = True
            self.buttonNo['relief'] = RAISED
            self.buttonYes['relief'] = SUNKEN
        elif pressed == "no":
            self.miniGameRun = False
            self.buttonNo['relief'] = SUNKEN
            self.buttonYes['relief'] = RAISED

    #control whether to run mini game or continue normal game
    def executeMiniButtons(self):
        self.question.destroy()
        self.buttonNo.destroy()
        self.buttonYes.destroy()
        self.enterInstruction.destroy()
        if self.miniGameRun:
            self.runMiniGame()

    #run minigame if magic box is collected
    def runMiniGame(self):
        #remove game functionality from keys while minigame is being played
        self.accept("a", self.doNothing)
        self.accept("f", self.doNothing)
        self.accept("w", self.doNothing)
        self.accept("e", self.doNothing)
        self.accept("q", self.doNothing)
        self.accept("enter", self.doNothing)

        #temporarily stop checking collisions on main game level
        taskMgr.remove('checkCollisionsTask')

        #temporarily add task
        taskMgr.add(self.miniGameCheckCollisions,
                    'miniGameCheckCollisionsTask')

        #temporary mini game controls
        self.accept("arrow_up", self.eventUpMini)
        self.accept("arrow_up-repeat", self.eventUpMini)
        self.accept("arrow_right", self.eventRightMini)
        self.accept("arrow_right-repeat", self.eventRightMini)
        self.accept("arrow_left", self.eventLeftMini)
        self.accept("arrow_left-repeat", self.eventLeftMini)
        self.accept("arrow_down", self.eventDownMini)
        self.accept("arrow_down-repeat", self.eventDownMini)
        self.accept("x", self.eventAxe)

        self.miniGameRun = False

        #shift camera down to minigame level
        self.x, self.y, self.z = camera.getPos()
        shiftPos = camera.posInterval(
            0.1, Point3(self.scaleBy // 2, self.scaleBy // 2, -148))
        miniGameView = Sequence(shiftPos)
        miniGameView.start()

        #game objects (object,x,y,scale)
        self.miniGameModles = [("plants/foliage01.egg.pz", 11, 12, 1),
                               ("plants/foliage02.egg.pz", -12, 14, 1),
                               ("plants/shrubbery.egg.pz", 1, 14, 1),
                               ("plants/cactus1.egg", 0, 0, 1),
                               ("plants/cactus2.egg", 2.5, 11, 1),
                               ("chicken.egg", 0, 0, 0.15)]

        #create minigame ground
        land = loader.loadModel("box")
        land.setPos(0, 0, -150)
        land.setSy(self.scaleBy)
        land.setSx(self.scaleBy)
        land.setSz(0.5)
        land.reparentTo(render)

        self.instructionsChicken = OnscreenText(text="Find chicken to return!",
                                                align=TextNode.ACenter,
                                                fg=(1, 1, 1, 1),
                                                pos=(0, 0.5),
                                                scale=.08,
                                                shadow=(0, 0, 0, 0.5))

        #load and initialize box for chicken to be rendered to
        x, y, z = self.cameraCurPos
        animal = loader.loadModel("box")
        animal.setScale(1)
        animal.setPos(randint(1, 118), randint(10, 106), -150.75)
        animal.reparentTo(render)
        animalColl = self.initCollisionSphere(animal, 0.75, False)
        #load chicken
        chicken = loader.loadModel("chicken")
        chicken.setScale(0.15)
        chicken.setPos(0.5, 0.5, 1.25)
        chicken.setHpr(0, 0, 0)
        chicken.reparentTo(animal)
        #store animal into
        self.animalColls += [animalColl]
        animalGroundHandler = CollisionHandlerQueue()
        self.animals += [[animal, 0, animalGroundHandler]]
        self.cTrav.addCollider(animalColl[0], animalGroundHandler)

    #when game is done,change setting back to original
    def miniGameDone(self):
        self.instructionsChicken.destroy()

        #delete new chicken
        self.animalColls[-1][0].remove_node()
        self.animals[-1][0].remove_node()
        self.animalColls = self.animalColls[:-1]
        self.animals = self.animals[:-1]

        #back to original game controls
        self.accept("arrow_up", self.eventArrowPressed, ["up"])
        self.accept("arrow_up-repeat", self.eventArrowPressed, ["up"])
        self.accept("arrow_right", self.eventArrowPressed, ["right"])
        self.accept("arrow_right-repeat", self.eventArrowPressed, ["right"])
        self.accept("arrow_left", self.eventArrowPressed, ["left"])
        self.accept("arrow_left-repeat", self.eventArrowPressed, ["left"])
        self.accept("arrow_down", self.eventArrowPressed, ["down"])
        self.accept("arrow_down-repeat", self.eventArrowPressed, ["down"])
        self.accept("f", self.eventAerielView)
        self.accept("w", self.eventPlanter)
        self.accept("e", self.changeSelectedPlanterOpt, ["e"])
        self.accept("q", self.changeSelectedPlanterOpt, ["e"])
        if not self.haveAxe:
            self.accept('x', self.doNothing)

        #redo taskMgr
        taskMgr.add(self.checkCollisions, 'checkCollisionsTask')
        taskMgr.remove('miniGameCheckCollisionsTask')

        #go back to normal view
        shiftPos = camera.posInterval(0.1, Point3(self.x, self.y, self.z))
        normalGameView = Sequence(shiftPos)
        normalGameView.start()

    #check if main character collided with chicken
    def miniGameCheckCollisions(self, task):
        #check collisions for mainChar
        entries = list(self.mainCharGroundHandler.getEntries())
        entries.sort(key=lambda x: x.getSurfacePoint(render).getZ())
        #if bump into chicken,go back to normal gam
        if (len(entries) > 0):
            self.miniGameDone()
        return Task.cont

    #set what happens when up arrow pressed
    def eventUpMini(self):
        self.curPosMini = self.mainChar.getPos()
        self.cameraCurPosMini = camera.getPos()
        x, y, z = base.camera.getPos()
        if y + self.moveMainCharX < 107:
            camera.setPos(x, y + self.moveMainCharY, z)

    #set what happens when down arrow pressed
    def eventDownMini(self):
        self.curPosMini = self.mainChar.getPos()
        self.cameraCurPosMini = camera.getPos()
        x, y, z = base.camera.getPos()
        if y - self.moveMainCharX > -9:
            camera.setPos(x, y - self.moveMainCharY, z)

    #set what happens when right arrow pressed
    def eventRightMini(self):
        self.curPosMini = self.mainChar.getPos()
        self.cameraCurPosMini = camera.getPos()
        x, y, z = base.camera.getPos()
        if x + self.moveMainCharX < 119:
            camera.setPos(x + self.moveMainCharX, y, z)

    #set what happens when left arrow pressed
    def eventLeftMini(self):
        self.curPosMini = self.mainChar.getPos()
        self.cameraCurPosMini = camera.getPos()
        x, y, z = base.camera.getPos()
        if x - self.moveMainCharX > 0:
            camera.setPos(x - self.moveMainCharY, y, z)

    #reload game
    def restartGame(self):
        self.loadStartScreen()
 def slider(self, pos, scale, value, command):
     return DirectSlider(pos=pos, scale=scale, value=value,
                                 command=command)
Esempio n. 11
0
    def __init__(self, tooltip, grid):
        self.tt = tooltip
        self.grid = grid
        screenWidthPx = base.getSize()[0]
        left = screenWidthPx * 0.25
        barWidth = screenWidthPx * 0.75

        color = (
            (0.25, 0.25, 0.25, 1),  # Normal
            (0.35, 0.35, 1, 1),  # Click
            (0.25, 0.25, 1, 1),  # Hover
            (0.1, 0.1, 0.1, 1))  # Disabled

        #
        # Toolbar
        #
        self.toolBar = DirectBoxSizer(frameColor=(0.25, 0.25, 0.25, 1),
                                      frameSize=(0, barWidth, -24, 24),
                                      autoUpdateFrameSize=False,
                                      pos=(0, 0, 0),
                                      parent=base.pixel2d)

        buttonColor = (
            (0.8, 0.8, 0.8, 1),  # Normal
            (0.9, 0.9, 1, 1),  # Click
            (0.8, 0.8, 1, 1),  # Hover
            (0.5, 0.5, 0.5, 1))  # Disabled
        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           command=base.messenger.send,
                           extraArgs=["newProject"],
                           image="icons/New.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Create New GUI (Ctrl-N)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           command=base.messenger.send,
                           extraArgs=["saveProject"],
                           image="icons/Save.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Save GUI as gui Project (Ctrl-S)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           text_scale=0.33,
                           relief=DGG.FLAT,
                           command=base.messenger.send,
                           extraArgs=["exportProject"],
                           image="icons/Export.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show,
                 ["Export GUI as python script (Ctrl-E)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["loadProject"],
                           image="icons/Load.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Load GUI project (Ctrl-O)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        placeholder = DirectFrame(text="|",
                                  frameSize=(-1, 1, -24, 24),
                                  pad=(4, 0),
                                  frameColor=(0, 0, 0, 1))
        self.toolBar.addItem(placeholder)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["undo"],
                           image="icons/Undo.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Undo last action (Ctrl-Z)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["redo"],
                           image="icons/Redo.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Redo last action (Ctrl-Y)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["cycleRedo"],
                           image="icons/CycleRedo.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show,
                 ["Cycle through redo branches (Ctrl-Shift-Y)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        placeholder = DirectFrame(text="|",
                                  frameSize=(-1, 1, -24, 24),
                                  pad=(4, 0),
                                  frameColor=(0, 0, 0, 1))
        self.toolBar.addItem(placeholder)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["removeElement"],
                           image="icons/Delete.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Delete selected element (Del)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        placeholder = DirectFrame(text="|",
                                  frameSize=(-1, 1, -24, 24),
                                  pad=(4, 0),
                                  frameColor=(0, 0, 0, 1))
        self.toolBar.addItem(placeholder)

        self.cb_grid = DirectCheckBox(
            frameSize=(-24, 24, -24, 24),
            frameColor=buttonColor,
            relief=DGG.FLAT,
            text_scale=12,
            image="icons/GridOff.png"
            if self.grid.isHidden() else "icons/GridOn.png",
            uncheckedImage="icons/GridOff.png",
            checkedImage="icons/GridOn.png",
            image_scale=24,
            isChecked=not self.grid.isHidden(),
            command=self.toggleGrid)
        self.cb_grid.setTransparency(TransparencyAttrib.M_multisample)
        self.cb_grid.bind(DGG.ENTER, self.tt.show, ["Toggle Grid (Ctrl-G)"])
        self.cb_grid.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(self.cb_grid)

        self.cb_scale = DirectCheckBox(frameSize=(-24, 24, -24, 24),
                                       frameColor=buttonColor,
                                       relief=DGG.FLAT,
                                       text_scale=12,
                                       image="icons/Scale1.png",
                                       uncheckedImage="icons/Scale2.png",
                                       checkedImage="icons/Scale1.png",
                                       image_scale=24,
                                       isChecked=True,
                                       command=self.toggleVisualEditorParent)
        self.cb_scale.setTransparency(TransparencyAttrib.M_alpha)
        self.cb_scale.bind(DGG.ENTER, self.tt.show,
                           ["Toggle editor scale (Aspect/Pixel)"])
        self.cb_scale.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(self.cb_scale)

        placeholder = DirectFrame(text="|",
                                  frameSize=(-1, 1, -24, 24),
                                  pad=(4, 0),
                                  frameColor=(0, 0, 0, 1))
        self.toolBar.addItem(placeholder)

        zoomHolder = DirectFrame(
            frameSize=(-48, 48, -24, 24),
            #pad=(4, 0),
            frameColor=(0, 0, 0, 0))
        self.toolBar.addItem(zoomHolder)
        self.zoomSlider = DirectSlider(zoomHolder,
                                       scale=(48, 1, 96),
                                       pos=(0, 0, 0),
                                       range=(0.1, 1.5),
                                       command=self.zoomSliderChanged)
        self.zoomSlider.bind(DGG.ENTER, self.tt.show, ["Zoom"])
        self.zoomSlider.bind(DGG.EXIT, self.tt.hide)
        #self.toolBar.addItem(self.zoomSlider)

        placeholder = DirectFrame(text="|",
                                  frameSize=(-1, 1, -24, 24),
                                  pad=(4, 0),
                                  frameColor=(0, 0, 0, 1))
        self.toolBar.addItem(placeholder)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["quitApp"],
                           image="icons/Quit.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_alpha)
        btn.bind(DGG.ENTER, self.tt.show,
                 ["Quit Direct GUI Designer (Ctrl-Q)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        placeholder = DirectFrame(text="|",
                                  frameSize=(-1, 1, -24, 24),
                                  pad=(4, 0),
                                  frameColor=(0, 0, 0, 1))
        self.toolBar.addItem(placeholder)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["showHelp"],
                           image="icons/Help.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Show a help Dialog (F1)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["showSettings"],
                           image="icons/Settings.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Show Designer Settings"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        if not ConfigVariableBool("show-toolbar", True).getValue():
            self.toolBar.hide()

        self.accept("setVisualEditorParent", self.setVisualEditorParent)
        self.accept("toggleGrid", self.setGrid)
Esempio n. 12
0
    def loadAmbientOcclusionGUI(self):
        self.numSamples = DirectSlider(
            parent=self,
            value=self.samples,
            pos=(self.buttonbase_xcoord + 0.1, 0.0,
                 self.buttonbase_ycoord - self.textRowHeight * 3.5),
            thumb_relief=None,
            range=(0, 32),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeAOValue)
        # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength))
        self.numSamples.setScale(0.5)
        self.numSamples.setTransparency(True)
        self.numSamplesText = OnscreenText(
            pos=(self.buttonbase_xcoord + 0.1,
                 self.buttonbase_ycoord - self.textRowHeight * 3.2),
            scale=0.05,
            text="AO Sample Count = {}".format(self.samples),
            style=5,
            mayChange=True)

        self.numRadius = DirectSlider(
            parent=self,
            value=self.radius,
            pos=(self.buttonbase_xcoord + 0.1, 0.0,
                 (self.buttonbase_ycoord - self.textRowHeight * 4.5)),
            thumb_relief=None,
            range=(0, 1),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeAOValue)

        self.numRadius.setScale(0.5)
        self.numRadius.setTransparency(True)
        self.numRadiusText = OnscreenText(
            pos=(self.buttonbase_xcoord + 0.1,
                 self.buttonbase_ycoord - self.textRowHeight * 4.2),
            scale=0.05,
            text="AO Radius = {}".format(str(self.radius)),
            style=5,
            mayChange=True)

        self.numAmount = DirectSlider(
            parent=self,
            value=self.amount,
            pos=(self.buttonbase_xcoord + 0.1, 0.0,
                 (self.buttonbase_ycoord - self.textRowHeight * 5.5)),
            thumb_relief=None,
            range=(0, 64),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeAOValue)

        self.numAmount.setScale(0.5)
        self.numAmount.setTransparency(True)
        self.numAmountText = OnscreenText(
            pos=(self.buttonbase_xcoord + 0.1,
                 self.buttonbase_ycoord - self.textRowHeight * 5.2),
            scale=0.05,
            text="AO Amount = {}".format(self.amount),
            style=5,
            mayChange=True)

        self.numStrength = DirectSlider(
            parent=self,
            value=self.strength,
            pos=(self.buttonbase_xcoord + 0.1, 0.0,
                 (self.buttonbase_ycoord - self.textRowHeight * 6.5)),
            thumb_relief=None,
            range=(0, 0.1),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeAOValue)

        self.numStrength.setScale(0.5)
        self.numStrength.setTransparency(True)
        self.numStrengthText = OnscreenText(
            pos=(self.buttonbase_xcoord + 0.1,
                 self.buttonbase_ycoord - self.textRowHeight * 6.2),
            scale=0.05,
            text="AO Strength = {}".format(self.strength),
            style=5,
            mayChange=True)
Esempio n. 13
0
class ToontownShaderManager(DirectFrame):
    def __init__(self, parent):
        self._parent = parent
        DirectFrame.__init__(self,
                             parent=self._parent,
                             relief=None,
                             pos=(0.0, 0.0, 0.0),
                             scale=(1.0, 1.0, 1.0))
        self.filter = CommonFilters(base.win,
                                    base.cam)  # Only affects primary window

        # Ambient Occlusion
        self.samples = 0
        self.radius = 0.0
        self.amount = 0.0
        self.strength = 0.0

        # Blur/Sharpen
        self.blur = 1.0  # this is normal value, 0.0 blurs it

        # Cartoon Ink
        self.cartoonSep = 0.0
        self.cartoonR = 0.0
        self.cartoonB = 0.0
        self.cartoonG = 0.0

        # todo: Add bloom

        # Boolean Filters
        self.HDREnabled = False
        self.invertedEnabled = False
        self.sRGBEnabled = False
        self.halfPixelShiftEnabled = False
        self.viewGlowEnabled = False

        # Other Filters
        self.exposure = 0.0

        self.SAMPLES_MAX = 128
        self.RAD_MAX = 1.0
        self.AMT_MAX = 64.0
        self.STR_MAX = 0.01
        self.INCREMENT = 1
        self.numSamples = None
        self.numRadius = None

        self.circleModel = loader.loadModel(
            'phase_3/models/gui/tt_m_gui_mat_nameShop')
        self.barTexture = loader.loadTexture('phase_3/maps/slider.png')
        self.loadGUI()
        # self.newWindow() # Disabled for now

    def loadGUI(self):
        self.textRowHeight = 0.2
        self.buttonbase_xcoord = 1.4
        self.buttonbase_ycoord = 0.45
        self.loadAmbientOcclusionGUI()
        self.loadBlurGUI()
        self.loadExposureGUI()
        self.loadCartoonInkGUI()
        self.loadHotkeys()

    def loadHotkeys(self):
        # for now instead of gui buttons i'ma just put the bool filters as hotkeys
        self.accept('4', self.__toggleHDR)
        self.accept('5', self.__toggleInverted)
        self.accept('6', self.__toggleSRGB)
        self.accept('7', self.__toggleHalfPixelShift)
        self.accept('8', self.__toggleViewGlow)

    def loadAmbientOcclusionGUI(self):
        self.numSamples = DirectSlider(
            parent=self,
            value=self.samples,
            pos=(self.buttonbase_xcoord + 0.1, 0.0,
                 self.buttonbase_ycoord - self.textRowHeight * 3.5),
            thumb_relief=None,
            range=(0, 32),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeAOValue)
        # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength))
        self.numSamples.setScale(0.5)
        self.numSamples.setTransparency(True)
        self.numSamplesText = OnscreenText(
            pos=(self.buttonbase_xcoord + 0.1,
                 self.buttonbase_ycoord - self.textRowHeight * 3.2),
            scale=0.05,
            text="AO Sample Count = {}".format(self.samples),
            style=5,
            mayChange=True)

        self.numRadius = DirectSlider(
            parent=self,
            value=self.radius,
            pos=(self.buttonbase_xcoord + 0.1, 0.0,
                 (self.buttonbase_ycoord - self.textRowHeight * 4.5)),
            thumb_relief=None,
            range=(0, 1),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeAOValue)

        self.numRadius.setScale(0.5)
        self.numRadius.setTransparency(True)
        self.numRadiusText = OnscreenText(
            pos=(self.buttonbase_xcoord + 0.1,
                 self.buttonbase_ycoord - self.textRowHeight * 4.2),
            scale=0.05,
            text="AO Radius = {}".format(str(self.radius)),
            style=5,
            mayChange=True)

        self.numAmount = DirectSlider(
            parent=self,
            value=self.amount,
            pos=(self.buttonbase_xcoord + 0.1, 0.0,
                 (self.buttonbase_ycoord - self.textRowHeight * 5.5)),
            thumb_relief=None,
            range=(0, 64),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeAOValue)

        self.numAmount.setScale(0.5)
        self.numAmount.setTransparency(True)
        self.numAmountText = OnscreenText(
            pos=(self.buttonbase_xcoord + 0.1,
                 self.buttonbase_ycoord - self.textRowHeight * 5.2),
            scale=0.05,
            text="AO Amount = {}".format(self.amount),
            style=5,
            mayChange=True)

        self.numStrength = DirectSlider(
            parent=self,
            value=self.strength,
            pos=(self.buttonbase_xcoord + 0.1, 0.0,
                 (self.buttonbase_ycoord - self.textRowHeight * 6.5)),
            thumb_relief=None,
            range=(0, 0.1),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeAOValue)

        self.numStrength.setScale(0.5)
        self.numStrength.setTransparency(True)
        self.numStrengthText = OnscreenText(
            pos=(self.buttonbase_xcoord + 0.1,
                 self.buttonbase_ycoord - self.textRowHeight * 6.2),
            scale=0.05,
            text="AO Strength = {}".format(self.strength),
            style=5,
            mayChange=True)

    def loadCartoonInkGUI(self):
        self.cSep = DirectSlider(
            parent=self,
            value=self.cartoonSep,
            pos=(-self.buttonbase_xcoord + 0.1, 0.0,
                 self.buttonbase_ycoord - self.textRowHeight * 2.5),
            thumb_relief=None,
            range=(0, 32),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeCartoon)
        # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength))
        self.cSep.setScale(0.5)
        self.cSep.setTransparency(True)

        self.cRed = DirectSlider(
            parent=self,
            value=self.cartoonR,
            pos=(-self.buttonbase_xcoord + 0.1, 0.0,
                 self.buttonbase_ycoord - self.textRowHeight * 3.5),
            thumb_relief=None,
            range=(0, 1),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeCartoon)
        # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength))
        self.cRed.setScale(0.5)
        self.cRed.setTransparency(True)

        self.cBlue = DirectSlider(
            parent=self,
            value=self.cartoonB,
            pos=(-self.buttonbase_xcoord + 0.1, 0.0,
                 self.buttonbase_ycoord - self.textRowHeight * 4.5),
            thumb_relief=None,
            range=(0, 1),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeCartoon)
        # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength))
        self.cBlue.setScale(0.5)
        self.cBlue.setTransparency(True)

        self.cGreen = DirectSlider(
            parent=self,
            value=self.cartoonG,
            pos=(-self.buttonbase_xcoord + 0.1, 0.0,
                 self.buttonbase_ycoord - self.textRowHeight * 5.5),
            thumb_relief=None,
            range=(0, 1),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeCartoon)
        # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength))
        self.cGreen.setScale(0.5)
        self.cGreen.setTransparency(True)

    def loadBlurGUI(self):
        self.numBlur = DirectSlider(
            parent=self,
            value=self.blur,
            # pos=(0.0, 0.0, 0.0), # for new window
            pos=(self.buttonbase_xcoord + 0.1, 0.0,
                 (self.buttonbase_ycoord - self.textRowHeight * 0.5)),
            thumb_relief=None,
            range=(-10, 10),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeBlur)
        self.numBlur.setScale(0.5)
        self.numBlur.setTransparency(True)
        self.numBlurText = OnscreenText(
            pos=(self.buttonbase_xcoord + 0.1,
                 self.buttonbase_ycoord - self.textRowHeight * 0.2),
            scale=0.05,
            text="Blur Amount = {}".format(self.blur),
            style=5,
            mayChange=True)

    def loadExposureGUI(self):
        self.numExposure = DirectSlider(
            parent=self,
            value=self.exposure,
            pos=(self.buttonbase_xcoord + 0.1, 0.0,
                 (self.buttonbase_ycoord - self.textRowHeight * 2.2)),
            thumb_relief=None,
            range=(0, 5),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeExposure)
        self.numExposure.setScale(0.5)
        self.numExposure.setTransparency(True)
        self.numExposureText = OnscreenText(
            pos=(self.buttonbase_xcoord + 0.1,
                 self.buttonbase_ycoord - self.textRowHeight * 1.9),
            scale=0.05,
            text="Exposure Amount = {}".format(self.blur),
            style=5,
            mayChange=True)

    def printValue(self):
        print(self.numSamples['value'])

    def __changeCartoon(self):
        self.filter.delCartoonInk()
        s = self.cSep['value']
        self.cartoonSep = s
        r = self.cRed['value']
        self.cartoonR = r
        b = self.cBlue['value']
        self.cartoonB = b
        g = self.cGreen['value']
        self.cartoonG = g
        self.filter.setCartoonInk(s, (r, g, b, 1))  # a doesn't change

    def __changeBlur(self):
        self.filter.delBlurSharpen()
        b = self.numBlur['value']
        self.blur = b
        self.numBlurText.setText("Blur amount = {}".format(b))
        self.filter.setBlurSharpen(b)

    def __changeAOValue(self):
        if self.numSamples is None:
            print("NONE")
            return
        self.filter.delAmbientOcclusion()

        s = self.numSamples['value']
        self.samples = s
        self.numSamplesText.setText("AO Sample Count = {}".format(s))
        if (s == 0):
            return

        r = self.numRadius['value']
        self.radius = r
        self.numRadiusText.setText("AO Radius = {}".format(r))
        if (r == 0):
            return

        a = self.numAmount['value']
        self.amount = a
        self.numAmountText.setText("AO Amount = {}".format(a))
        if (a == 0):
            return

        st = self.numStrength['value']
        self.strength = st
        self.numStrengthText.setText("AO Strength = {}".format(st))
        if (st == 0):
            return

        self.filter.setAmbientOcclusion(numsamples=s,
                                        radius=r,
                                        amount=a,
                                        strength=st)
        print(
            "sample count: {} | radius count: {} | amount count: {} | strength count: {}"
            .format(self.samples, self.radius, self.amount, self.strength))

    # WARNING: Won't work with relatively older Panda versions because this is new
    def __changeExposure(self):
        self.filter.delExposureAdjust()
        e = self.numExposure['value']
        self.exposure = e
        self.numExposureText.setText("Exposure amount = {}".format(e))
        self.filter.setExposureAdjust(e)

    def __toggleInverted(self):
        if not self.invertedEnabled:
            self.filter.setInverted()
            self.invertedEnabled = True
        else:
            self.filter.delInverted()
            self.invertedEnabled = False

    def __toggleHDR(self):
        if not self.HDREnabled:
            self.filter.setHighDynamicRange()
            self.HDREnabled = True
        else:
            self.filter.delHighDynamicRange()
            self.HDREnabled = False

    def __toggleSRGB(self):
        if not self.sRGBEnabled:
            self.filter.setSrgbEncode(True)
            self.sRGBEnabled = True
        else:
            self.filter.delSrgbEncode()
            self.sRGBEnabled = False

    def __toggleHalfPixelShift(self):
        if not self.halfPixelShiftEnabled:
            self.filter.setHalfPixelShift()
            self.halfPixelShiftEnabled = True
        else:
            self.filter.delHalfPixelShift()
            self.halfPixelShiftEnabled = False

    def __toggleViewGlow(self):
        if not self.viewGlowEnabled:
            self.filter.setViewGlow()
            self.viewGlowEnabled = True
        else:
            self.filter.delViewGlow()
            self.viewGlowEnabled = False

    def getValue(self, item, item_MAX):
        return item / item_MAX

    # Not gonna use this feature since it makes it very laggy. I will have to figure out
    # a better way to layout UI some other time.
    # https://discourse.panda3d.org/t/how-to-open-a-new-window/23929/4
    def newWindow(self):
        self.wp = WindowProperties()
        self.wp.setSize(700, 500)
        self.wp.setRawMice(True)
        print(self.wp.getMouseMode())
        win2mouseWatcher = MouseWatcher()
        ar = 1
        self.win2 = base.openWindow(props=self.wp, aspectRatio=ar)
        self.window2render2d = NodePath('window2render2d')
        self.window2render2d.setDepthTest(0)
        self.window2render2d.setDepthWrite(0)

        self.window2camera2d = base.makeCamera2d(self.win2)
        self.window2camera2d.reparentTo(self.window2render2d)

        # Parent gui to this
        self.window2aspect2d = self.window2render2d.attachNewNode(
            PGTop('window2aspect2d'))
        self.window2aspect2d.setScale(1.0 / ar, 1.0, 1.0)

        name = self.win2.getInputDeviceName(0)
        mk = base.dataRoot.attachNewNode(MouseAndKeyboard(self.win2, 0, name))
        mw = mk.attachNewNode(MouseWatcher(name))
        self.window2aspect2d.node().setMouseWatcher(mw.node())
Esempio n. 14
0
    def loadCartoonInkGUI(self):
        self.cSep = DirectSlider(
            parent=self,
            value=self.cartoonSep,
            pos=(-self.buttonbase_xcoord + 0.1, 0.0,
                 self.buttonbase_ycoord - self.textRowHeight * 2.5),
            thumb_relief=None,
            range=(0, 32),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeCartoon)
        # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength))
        self.cSep.setScale(0.5)
        self.cSep.setTransparency(True)

        self.cRed = DirectSlider(
            parent=self,
            value=self.cartoonR,
            pos=(-self.buttonbase_xcoord + 0.1, 0.0,
                 self.buttonbase_ycoord - self.textRowHeight * 3.5),
            thumb_relief=None,
            range=(0, 1),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeCartoon)
        # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength))
        self.cRed.setScale(0.5)
        self.cRed.setTransparency(True)

        self.cBlue = DirectSlider(
            parent=self,
            value=self.cartoonB,
            pos=(-self.buttonbase_xcoord + 0.1, 0.0,
                 self.buttonbase_ycoord - self.textRowHeight * 4.5),
            thumb_relief=None,
            range=(0, 1),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeCartoon)
        # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength))
        self.cBlue.setScale(0.5)
        self.cBlue.setTransparency(True)

        self.cGreen = DirectSlider(
            parent=self,
            value=self.cartoonG,
            pos=(-self.buttonbase_xcoord + 0.1, 0.0,
                 self.buttonbase_ycoord - self.textRowHeight * 5.5),
            thumb_relief=None,
            range=(0, 1),  # self.SAMPLES_MAX
            thumb_geom=self.circleModel.find(
                '**/tt_t_gui_mat_namePanelCircle'),
            frameTexture=self.barTexture,
            frameSize=(-0.5, 0.5, -0.08, 0.08),
            command=self.__changeCartoon)
        # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength))
        self.cGreen.setScale(0.5)
        self.cGreen.setTransparency(True)
Esempio n. 15
0

print("starting")
t = BobViz()

def changeColor(colorSlot, group):
    color = list(t.spheroColor)
    color[colorSlot] = slider[group][colorSlot]['value']
    t.spheroColor = tuple(color)
    nodes = render.findAllMatches(group)
    for node in nodes:
        node.getMaterial().setDiffuse(t.spheroColor)

slider = dict()
slider["Spheros"] = []
slider["Spheros"].append(DirectSlider(range=(0,1), value=t.spheroColor[0], scale=0.25, pos=(-1.0, 0.0, -0.85),
                         command=changeColor, extraArgs=(0,"Spheros")))
slider["Spheros"].append(DirectSlider(range=(0,1), value=t.spheroColor[1], scale=0.25, pos=(-1.0, 0.0, -0.90),
                         command=changeColor, extraArgs=(1,"Spheros")))
slider["Spheros"].append(DirectSlider(range=(0,1), value=t.spheroColor[2], scale=0.25, pos=(-1.0, 0.0, -0.95),
                         command=changeColor, extraArgs=(2,"Spheros")))



# Create a unix domain socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

# Connect the socket to the port where the server is listening
server_address = './uds_socket'
print('connecting to {}'.format(server_address))
try:
    sock.connect(server_address)
Esempio n. 16
0
    def __init__(self):

        #Our standard title and instructions text
        self.title = OnscreenText(text="Panda3D: Tutorial - Musicbox(sounds)",
                                  style=1,
                                  fg=(1, 1, 1, 1),
                                  pos=(0.7, -0.95),
                                  scale=.07)
        self.escapeEventText = OnscreenText(text="ESC: Quit",
                                            style=1,
                                            fg=(1, 1, 1, 1),
                                            pos=(-1.3, 0.95),
                                            align=TextNode.ALeft,
                                            scale=.05)

        #Set up the key input
        self.accept('escape', sys.exit)

        #Fix the camera position
        base.disableMouse()

        #Loading sounds is done in a similar way to loading other things
        #Loading the main music box song
        self.musicBoxSound = base.loadMusic('music/musicbox.ogg')
        self.musicBoxSound.setVolume(.5)  #Volume is a percentage from 0 to 1
        self.musicBoxSound.setLoopCount(
            0)  #0 means loop forever, 1 (default) means
        #play once. 2 or higher means play that
        #many times

        #Sound objects do not have a pause function, just play and stop. So we will
        #Use this variable to keep track of where the sound is at when it was stoped
        #to impliment pausing
        self.musicTime = 0

        #Loading the open/close effect
        #loadSFX and loadMusic are identical. They are often used for organization
        #(loadMusic is used for background music, loadSfx is used for other effects)
        self.lidSfx = base.loadSfx('music/openclose.ogg')
        #The open/close file has both effects in it. Fortunatly we can use intervals
        #to easily define parts of a sound file to play
        self.lidOpenSfx = SoundInterval(self.lidSfx, duration=2, startTime=0)
        self.lidCloseSfx = SoundInterval(self.lidSfx, startTime=5)

        #For this tutorial, it seemed appropriate to have on screen controls. The
        #following code creates them
        #This is a label for a slider
        self.sliderText = OnscreenText("Volume",
                                       style=1,
                                       fg=(1, 1, 1, 1),
                                       pos=(0, 0.8),
                                       scale=.07)
        #The slider itself. It calls self.setMusicBoxVolume when changed
        self.slider = DirectSlider(pos=Vec3(0, 0, .7),
                                   value=.50,
                                   command=self.setMusicBoxVolume)
        #A button that calls self.toggleMusicBox when pressed
        self.button = DirectButton(pos=Vec3(.7, 0, .7),
                                   text="Open Box",
                                   scale=.1,
                                   pad=(.5, .5),
                                   rolloverSound=None,
                                   clickSound=None,
                                   command=self.toggleMusicBox)

        #A variable to represent the state of the simulation. It starts closed
        self.boxOpen = False

        #Here we load and set up the music box. It was modeled in a complex way, so
        #setting it up will be complicated
        self.musicBox = loader.loadModel('models/MusicBox')
        self.musicBox.setPos(0, 60, -10)
        self.musicBox.reparentTo(render)
        #Just like the scene graph contains hierarchies of nodes, so can
        #models. You can get the NodePath for the node using the find
        #function, and then you can animate the model by moving its parts
        #To see the hierarchy of a model, use, the ls function
        #self.musicBox.ls() prints out the entire hierarchy of the model

        #Finding pieces of the model
        self.Lid = self.musicBox.find('**/lid')
        self.Panda = self.musicBox.find('**/turningthing')

        #This model was made with the hinge in the wrong place
        #this is here so we have something to turn
        self.HingeNode = self.musicBox.find('**/box').attachNewNode(
            'nHingeNode')
        self.HingeNode.setPos(.8659, 6.5, 5.4)
        #WRT - ie with respect to. Reparents the object without changing
        #its position, size, or orientation
        self.Lid.wrtReparentTo(self.HingeNode)
        self.HingeNode.setHpr(0, 90, 0)

        #This sets up an interval to play the close sound and actually close the box
        #at the same time.
        self.lidClose = Parallel(
            self.lidCloseSfx,
            LerpFunc(self.HingeNode.setP,
                     duration=2,
                     fromData=0,
                     toData=90,
                     blendType='easeInOut'))

        #Same thing for opening the box
        self.lidOpen = Parallel(
            self.lidOpenSfx,
            LerpFunc(self.HingeNode.setP,
                     duration=2,
                     fromData=90,
                     toData=0,
                     blendType='easeInOut'))

        #The interval for turning the panda
        self.PandaTurn = self.Panda.hprInterval(7, Vec3(360, 0, 0))
        #Do a quick loop and pause to set it as a looping interval so it can be
        #started with resume and loop properly
        self.PandaTurn.loop()
        self.PandaTurn.pause()
Esempio n. 17
0
    def bld_page(self):
        menu_args = self.menu_args
        self.pagewidgets = []

        def add_lab(txt, txt_tr, pos_z):
            lab = DirectLabel(text='',
                              pos=(-.1, 1, pos_z),
                              text_align=TextNode.ARight,
                              **menu_args.label_args)
            PageGui.transl_text(lab, txt, txt_tr)
            self.pagewidgets += [lab]
            return lab

        add_lab('Language', _('Language'), .7)
        self._lang_opt = DirectOptionMenu(text='',
                                          items=eng.languages,
                                          pos=(.49, 1, .7),
                                          initialitem=self.props.lang,
                                          command=self.__change_lang,
                                          **menu_args.option_args)
        add_lab('Volume', _('Volume'), .5)
        self._vol_slider = DirectSlider(pos=(.52, 0, .53),
                                        scale=.49,
                                        value=self.props.volume,
                                        frameColor=menu_args.btn_color,
                                        thumb_frameColor=menu_args.text_fg,
                                        command=self.__on_volume)
        add_lab('Fullscreen', _('Fullscreen'), .3)
        self._fullscreen_cb = DirectCheckButton(
            pos=(.12, 1, .32),
            text='',
            indicatorValue=self.props.fullscreen,
            indicator_frameColor=menu_args.text_fg,
            command=lambda val: eng.toggle_fullscreen(),
            **menu_args.checkbtn_args)
        add_lab('Resolution', _('Resolution'), .1)
        res2vec = lambda res: LVector2i(*[int(val) for val in res.split('x')])
        self._res_opt = DirectOptionMenu(
            text='',
            items=[
                'x'.join([str(el_res) for el_res in res])
                for res in eng.resolutions
            ],
            pos=(.49, 1, .1),
            initialitem='x'.join(str(res) for res in eng.closest_res),
            command=lambda res: eng.set_resolution(res2vec(res)),
            **menu_args.option_args)
        add_lab('Antialiasing', _('Antialiasing'), -.1)
        aa_next_lab = DirectLabel(text='',
                                  pos=(.2, 1, -.1),
                                  text_align=TextNode.ALeft,
                                  **menu_args.label_args)
        PageGui.transl_text(aa_next_lab, '(from the next execution)',
                            _('(from the next execution)'))
        self._aa_cb = DirectCheckButton(pos=(.12, 1, -.07),
                                        text='',
                                        indicatorValue=self.props.aa,
                                        indicator_frameColor=menu_args.text_fg,
                                        **menu_args.checkbtn_args)
        add_lab('Shaders', _('Shaders'), -.3)
        self._shaders_cb = DirectCheckButton(
            pos=(.12, 1, -.27),
            text='',
            indicatorValue=self.props.shaders,
            indicator_frameColor=menu_args.text_fg,
            **menu_args.checkbtn_args)
        # bld_in = lambda: self.menu.logic.push_page(
        #     InputPage(self.menu, self.props.joystick, self.props.keys))
        # it doesn't work if we go forward and back between options and input:
        # we should update keys
        input_btn = DirectButton(text='',
                                 pos=(0, 1, -.5),
                                 command=self.on_input_btn,
                                 **menu_args.btn_args)
        PageGui.transl_text(input_btn, 'Configure input', _('Configure input'))

        self.pagewidgets += [
            self._lang_opt, self._vol_slider, self._fullscreen_cb,
            self._res_opt, self._aa_cb, aa_next_lab, input_btn,
            self._shaders_cb
        ]
        map(self.add_widget, self.pagewidgets)
        idx = LangMgr().lang_codes.index(self.props.lang)
        self.__change_lang(eng.languages[idx])
        ThanksPageGui.bld_page(self)