Exemple #1
0
 def __init__(self, game, node):
     BaseNodeScript.__init__(self, game, 'SoundsExample', node)
     self.log = logging.getLogger('SoundsExample')
     
     # reference to sounds fx player
     self.sounds = None
     
     # the following set of fields are UI labels
     self.instructions = None
     self.soundsStatusText = None
     self.volumeText = None
     self.rateText = None
     self.balanceText = None
     self.loopText = None
     self.eventText = None
     
     # reference to the 'blah' sound 
     self.blahSound = None
     
     # holds the status of sounds, if True then sounds are globally enabled
     self.lastStatus = True
     
     # flags that indicate if the respective property has been update by the user
     self.updateVolume = False
     self.updateRate = False
     self.updateBalance = False
     self.updateLooping = False
     
     # 
     self.looping = 0
Exemple #2
0
 def update(self, millis):
     '''
     Gets called on every logic update and we use it to update the UI texts based on user input actions.
     The millis parameter is the milliseconds that elapsed since the last logic update.
     '''
     
     # call the super class implementation first, this is optional
     BaseNodeScript.update(self, millis)
     
     # detects if sounds status has been toggled in order to update the UI label
     if self.lastStatus != self.sounds.isEnabled():
         self.lastStatus = self.sounds.isEnabled()
         self.soundsStatusText.setText('Sounds status: %s' % self.lastStatus)
         
     # updates the volume label if needed
     if self.updateVolume:
         self.volumeText.setText('Volume: %.1f' % self.sounds.getVolume())
         self.updateVolume = False
     
     # updates the rate label if needed
     if self.updateRate:
         self.rateText.setText('Rate: %.1f' % self.sounds.getPlayRate())
         self.updateRate = False
         
     # updates the balance label if needed
     if self.updateBalance:
         self.balanceText.setText('Balance: %.1f' % self.sounds.getBalance())
         self.updateBalance = False
         
     # updates the looping label if needed
     if self.updateLooping:
         self.loopText.setText('Looping: %d' % self.looping)
         self.updateLooping = False
Exemple #3
0
 def update(self, millis):
     BaseNodeScript.update(self, millis)
     track = self.music.getActiveTrack() # returns a tuple of the form (index, track_name, track_file)
     if self.lastActiveTrack != track:
         self.lastActiveTrack = track
         self._updateTrackLabel('[%d] %s (file: %s)' % track)
         pl = self.music.getPlaylist()
         self._updatePlaylistLabel('Current playlist: %s' % pl.name)
Exemple #4
0
 def exit(self):
     '''
     Performs some cleanup.
     '''
     
     # call the super class implementation first, this is optional
     BaseNodeScript.exit(self)
     if self.instructions is not None:
         self.instructions.destroy()                
         
     # this will stop all active sounds
     if self.sounds is not None:
         self.sounds.stopAll()
Exemple #5
0
    def __init__(self, game, node):
        BaseNodeScript.__init__(self, game, 'Example_i18n', node)
        self.log = logging.getLogger('Example_i18n')

        self.currentLanguage = "en"

        self.languageToStr = {
            'en': 'English',
            'gr': 'Greek',
            'ar': 'Arabic',
            'cn': 'Traditional Chinese'
        }
        self.languages = ['en', 'gr', 'ar', 'cn']

        self.languageLabel = None
Exemple #6
0
    def __init__(self, game, node):

        # we must call the parent class
        BaseNodeScript.__init__(self, game, 'sudoku', node)

        self.log = logging.getLogger('sudoku')

        # stores the current state of the board
        self.board = []

        # stores the initial state of the board, as defined in start_pos.txt
        self.initBoard = []

        # stores the solved state of the board, as defined in solution_pos.txt
        self.solutionBoard = []
Exemple #7
0
 def registerMessages(self):
     li = [
         PanoConstants.EVENT_HOTSPOT_ACTION,
         PanoConstants.EVENT_HOTSPOT_LOOKAT
     ]
     li.extend(BaseNodeScript.registerMessages(self))
     return li
Exemple #8
0
 def enter(self):
     BaseNodeScript.enter(self)
     
     # hold the camera fixed
     self.game.getView().getCameraController().disable()
             
     self.music = self.game.getMusic()
             
     res = self.game.getResources()
     self.list1 = res.loadPlaylist('list1')
     self.list2 = res.loadPlaylist('list2')
             
     self.music.setPlaylist(self.list1)                                
     self.music.play()            
     
     self.game.getInput().addMappings('playlist-control')    
Exemple #9
0
 def registerMessages(self):        
     '''
     The purpose of this method is to declare the list of messages IDs for which we are interested to receive. 
     Here we are interested in a single message besides the standard list of message IDs returned by the
     base class.
     It is not necessary to include the list of messages from the base class but it contains some very useful
     message IDs like game_paused, game_resumed, etc., so most probably you will want to do this.
     '''
     return ['sound_finished'].extend(BaseNodeScript.registerMessages(self))
Exemple #10
0
    def enter(self):
        BaseNodeScript.enter(self)

        #setup the initial board
        ord0 = ord('0')
        startTxt = self.game.getResources().loadText('start_pos.txt')
        for c in startTxt:
            if c <= '9' and c >= '0':
                self.initBoard.append(ord(c) - ord0)

        self.board.extend(self.initBoard)

        #setup the solution matrix
        solTxt = self.game.getResources().loadText('solution_pos.txt')
        for c in solTxt:
            if c <= '9' and c >= '0':
                self.solutionBoard.append(ord(c) - ord0)

        self._createHotspots()
Exemple #11
0
    def __init__(self, game, node):                
        BaseNodeScript.__init__(self, game, 'MusicExample', node)        
        self.log = logging.getLogger('MusicExample')

        # displays the current track
        self.instructions = None
        
        # used to detect a change in the active track
        self.lastActiveTrack = None
        
        # two different music playlists
        self.list1 = None
        self.list2 = None
        
        # displays active track
        self.trackLabel = None

        # displays active playlist
        self.playlistLabel = None
Exemple #12
0
 def exit(self):
     BaseNodeScript.exit(self)
     self.game.getInput().removeMappings('playlist-control')
Exemple #13
0
 def enter(self):
     '''
     Here we initialize some fields and flags and setup our UI which constists only of labels.
     '''
     
     # call the super class implementation first, this is optional
     BaseNodeScript.enter(self)
     
     self.sounds = self.game.getSoundsFx()
             
     # hold the camera fixed
     self.game.getView().getCameraController().disable()
     
     # display instructions
     self.instructions = OnscreenText(text = 'Press 1 for blah-blah, 2 for cling and 3 for zipper',
                                      pos = (base.a2dLeft + 0.1, 0.9),
                                      align = TextNode.ALeft,
                                      scale = 0.07,
                                      fg = (1.0, 1.0, 1.0, 1.0),
                                      shadow = (0.0, 0.0, 0.0, 0.7)
                                      )
     
     # gets the status of sounds
     self.lastStatus = self.sounds.isEnabled()
     
     self.soundsStatusText = OnscreenText(text = 'Sounds status: %s' % self.lastStatus,
                                          pos = (base.a2dLeft + 0.1, 0.8),
                                          align = TextNode.ALeft,
                                          scale = 0.07,
                                          fg = (1.0, 1.0, 1.0, 1.0),
                                          shadow = (0.0, 0.0, 0.0, 0.7),
                                          mayChange = True
                                          )
     
     self.volumeText = OnscreenText(text = 'Volume: %.1f' % self.sounds.getVolume(),
                                          pos = (base.a2dLeft + 0.1, 0.7),
                                          align = TextNode.ALeft,
                                          scale = 0.07,
                                          fg = (1.0, 1.0, 1.0, 1.0),
                                          shadow = (0.0, 0.0, 0.0, 0.7),
                                          mayChange = True
                                          )
     
     self.rateText = OnscreenText(text = 'Rate: %.1f' % self.sounds.getPlayRate(),
                                          pos = (base.a2dLeft + 0.1, 0.6),
                                          align = TextNode.ALeft,
                                          scale = 0.07,
                                          fg = (1.0, 1.0, 1.0, 1.0),
                                          shadow = (0.0, 0.0, 0.0, 0.7),
                                          mayChange = True
                                          )
     
     self.balanceText = OnscreenText(text = 'Balance: %.1f' % self.sounds.getBalance(),
                                          pos = (base.a2dLeft + 0.1, 0.5),
                                          align = TextNode.ALeft,
                                          scale = 0.07,
                                          fg = (1.0, 1.0, 1.0, 1.0),
                                          shadow = (0.0, 0.0, 0.0, 0.7),
                                          mayChange = True
                                          )
     
     self.loopText = OnscreenText(text = 'Looping: %d' % self.looping,
                                          pos = (base.a2dLeft + 0.1, 0.4),
                                          align = TextNode.ALeft,
                                          scale = 0.07,
                                          fg = (1.0, 1.0, 1.0, 1.0),
                                          shadow = (0.0, 0.0, 0.0, 0.7),
                                          mayChange = True
                                          )
     
     self.eventText = OnscreenText(text = 'Finished event received',
                                          pos = (base.a2dLeft + 0.1, 0.3),
                                          align = TextNode.ALeft,
                                          scale = 0.07,
                                          fg = (1.0, 0.0, 0.0, 1.0),
                                          shadow = (0.0, 0.0, 0.0, 0.7),
                                          mayChange = True
                                          )
     self.eventText.hide()
     
     OnscreenText(text = 'Press P, R to pause/resume playing sounds',
                                          pos = (base.a2dLeft + 0.1, 0.2),
                                          align = TextNode.ALeft,
                                          scale = 0.05,
                                          fg = (1.0, 1.0, 1.0, 1.0),
                                          shadow = (0.0, 0.0, 0.0, 0.7),
                                          mayChange = True
                                          )
     OnscreenText(text = 'Press L, Shift-L to increase/decrease the loop count',
                                          pos = (base.a2dLeft + 0.1, 0.1),
                                          align = TextNode.ALeft,
                                          scale = 0.05,
                                          fg = (1.0, 1.0, 1.0, 1.0),
                                          shadow = (0.0, 0.0, 0.0, 0.7),
                                          mayChange = True
                                          )
     OnscreenText(text = 'Press +, - to increase/decrease playing rate',
                                          pos = (base.a2dLeft + 0.1, 0.0),
                                          align = TextNode.ALeft,
                                          scale = 0.05,
                                          fg = (1.0, 1.0, 1.0, 1.0),
                                          shadow = (0.0, 0.0, 0.0, 0.7),
                                          mayChange = True
                                          )
     OnscreenText(text = 'Press [, ] to decrease/increase sound volume',
                                          pos = (base.a2dLeft + 0.1, -0.1),
                                          align = TextNode.ALeft,
                                          scale = 0.05,
                                          fg = (1.0, 1.0, 1.0, 1.0),
                                          shadow = (0.0, 0.0, 0.0, 0.7),
                                          mayChange = True
                                          )
     OnscreenText(text = 'Press D, E to disable/enable sounds',
                                          pos = (base.a2dLeft + 0.1, -0.2),
                                          align = TextNode.ALeft,
                                          scale = 0.05,
                                          fg = (1.0, 1.0, 1.0, 1.0),
                                          shadow = (0.0, 0.0, 0.0, 0.7),
                                          mayChange = True
                                          )
     OnscreenText(text = 'Press B, Shift-B to increase/decrease balance',
                                          pos = (base.a2dLeft + 0.1, -0.3),
                                          align = TextNode.ALeft,
                                          scale = 0.05,
                                          fg = (1.0, 1.0, 1.0, 1.0),
                                          shadow = (0.0, 0.0, 0.0, 0.7),
                                          mayChange = True
                                          )
     
     
     
     # add our input mappings to the active mappings, the existing mappings were not deleted
     # but they can be partially overridden by this.
     self.game.getInput().addMappings('sounds')
Exemple #14
0
 def exit(self):
     BaseNodeScript.exit(self)
Exemple #15
0
 def update(self, millis):
     BaseNodeScript.update(self, millis)
     if self.isSolutionAchieved():
         self.game.getView().getTalkBox().showText('game.success')
Exemple #16
0
    def enter(self):
        BaseNodeScript.enter(self)

        self.game.getView().getCameraController().disable()
        self.game.getView().getTalkBox().setFontName('default')
        self.game.getView().getTalkBox().showText('text.mf', 1000)
Exemple #17
0
 def __init__(self, game, node):
     BaseNodeScript.__init__(self, game, 'MultifilesExample', node)
     self.log = logging.getLogger('MultifilesExample')