def _downloadComplete(self): # Little bit dirty, but unless I do this, the sound object is gc-ed. if self.updateDownloader.hasSucceeded(): self.downloadcomp = bgtsound.sound() self.downloadcomp.stream("data/sounds/stream/download.ogg") self.downloadcomp.play() else: self.downloadcomp = bgtsound.sound() self.downloadcomp.stream("data/sounds/stream/error.ogg") self.downloadcomp.play()
def obtain(self): self.field.log(_("Obtained a \"%(item)s\" item!") % {"item": NAMES[self.type][self.identifier]}) s = bgtsound.sound() s.load(globalVars.appMain.sounds["hit.ogg"]) s.pan = self.field.getPan(self.x) s.pitch = random.randint(70, 130) s.play() s = bgtsound.sound() s.load(globalVars.appMain.sounds["itemget.ogg"]) s.pan = self.field.getPan(self.x) s.volume = self.field.getVolume(self.y) s.play() self.field.itemVoicePlayer.play("get %s.ogg" % NAMES[self.type][self.identifier], self.field.getPan(self.x)) self.fallingBeep.stop() self.switchState(STATE_SHOULDBEDELETED)
def test(self): if not self.active: return self.testSound = bgtsound.sound() self.testSound.load(random.choice(list(self.sounds.values()))) self.testSound.volume = -10 self.testSound.play()
def count(self): s = bgtsound.sound() if self.number > 0: self.current += 1 s.load(globalVars.appMain.sounds["bonus.ogg"]) p = 75 + (self.current * 5) if p > 300: p = 300 else: self.current -= 1 s.load(globalVars.appMain.sounds["unbonus.ogg"]) p = 150 + (self.current * 3) if p < 50: p = 50 # end if s.pitch = p s.play() if self.current == self.number: self.active = False return w = 200 - (abs(self.current) * 10) if w < 50: w = 50 self.nextCountTime = w self.countTimer.restart()
def play(self, file, pan): if not self.active: return if file in self.sounds: s = bgtsound.sound() s.load(self.sounds[file]) s.pan = pan s.play()
def deactivate(self, mode): self.off = bgtsound.sound() self.off.load(self.offSound) self.off.play() self.active = False self.player.field.log( _("One of your \"%(item)s\" effects is ending!") % {"item": self.name})
def activate(self, mode): self.on = bgtsound.sound() self.on.load(self.onSound) self.on.play() self.active = True self.timer.restart() self.player.field.log( _("A new \"%(item)s\" effect is starting!") % {"item": self.name})
def playScream(self): """Makes this enemy scream. Internally called.""" self.scream = bgtsound.sound() self.scream.load(globalVars.appMain.sounds["scream%d.ogg" % self.screamNum]) self.scream.pitch = random.randint(SCREAM_PITCH_LOW, SCREAM_PITCH_HIGH) self.scream.pan = self.field.getPan(self.x) self.scream.volume = self.field.getVolume(self.y) self.scream.play()
def playBodyfall(self): """Makes a bodyfall sound for this enemy. Internally called.""" self.bodyfall = bgtsound.sound() self.bodyfall.load(globalVars.appMain.sounds["dead.ogg"]) self.bodyfall.pitch = random.randint(70, 130) self.bodyfall.pan = self.field.getPan(self.x) self.bodyfall.volume = self.field.getVolume(self.y) self.bodyfall.play()
def punch(self): """Called when this item was punched and destroyed.""" s = bgtsound.sound() s.load(globalVars.appMain.sounds["hit.ogg"]) s.pan = self.field.getPan(self.x) s.pitch = random.randint(70, 130) s.play() self.destroy()
def __init__(self): s=bgtsound.sound() s.stream("fx/background2.ogg") self.volume=0 s.volume=self.volume self.sound=s self.thread=threading.Thread(target=self._thread) self.thread.setDaemon(True) self.thread_exit=False
def playShatter(self): self.field.itemVoicePlayer.play("lose %s.ogg" % NAMES[self.type][self.identifier], self.field.getPan(self.x)) self.shatter = bgtsound.sound() self.shatter.load(globalVars.appMain.sounds["item_destroy%d.ogg" % random.randint(1, 2)]) self.shatter.pitch = random.randint(70, 130) self.shatter.pan = self.field.getPan(self.x) self.shatter.volume = self.field.getVolume(self.y) self.shatter.play() self.fallingBeep.stop()
def initialize(self, x, y, mode, voice, easter=False): self.gameTimer = window.Timer() self.paused = False self.easter = easter self.logs = [] self.log( _("Game started at %(startedtime)s!") % { "startedtime": datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S") }) self.x = x self.y = y self.setModeHandler(mode) self.leftPanningLimit = -100 self.rightPanningLimit = 100 self.lowVolumeLimit = -30 self.highVolumeLimit = 0 self.level = 1 if self.easter: self.level = 10 self.enemies = [] self.items = [] for i in range(self.level): self.enemies.append(None) self.player = player.Player() self.player.initialize(self) self.collectionCounter = collection.CollectionCounter() self.collectionCounter.initialize(globalVars.appMain.collectionStorage) self.defeats = 0 self.nextLevelup = self.modeHandler.calculateNextLevelup() self.levelupBonus = bonusCounter.BonusCounter() self.levelupBonus.initialize() self.destructing = False self.destructTimer = window.Timer() self.itemVoicePlayer = itemVoicePlayer.ItemVoicePlayer() self.itemVoicePlayer.initialize(voice) self.destructPowerup = bgtsound.sound() self.destructPowerup.load( globalVars.appMain.sounds["destructPowerup.ogg"]) self.destruct = bgtsound.sound() self.destruct.load(globalVars.appMain.sounds["destruct.ogg"])
def play(self, index): """Plays a scream. :param pos: Scream number. """ if self.sound: self.sound.stop() self.sound = bgtsound.sound() self.sound.load(self.appMain.sounds["scream%d.ogg" % index]) self.sound.pitch = self.pitch self.sound.play() bgtsound.playOneShot(self.appMain.sounds["confirm.ogg"])
def moveTo(self, p): """ Moves this player to the specified position. :param p: New position. :type p: int """ self.x = p s = bgtsound.sound() s.load(globalVars.appMain.sounds["change.ogg"]) s.pan = self.field.getPan(self.x) s.play()
def punchLaunch(self): """Launches a punch. If this player is already punching, this method does nothing. """ if self.punching: return self.punches += 1 self.punching = True s = bgtsound.sound() s.load(globalVars.appMain.sounds["fists.ogg"]) s.pan = self.field.getPan(self.x) s.pitch = int(DEFAULT_PUNCH_SPEED / self.punchSpeed * 100) + random.randint(-10, 10) s.play() self.punchTimer.restart()
def extend(self, ms): self.ex = bgtsound.sound() self.ex.load(self.onSound) self.ex.pitch = 130 self.ex.play() self.lasts += ms self.player.field.log( _("Your \"%(item)s\" effect has been extended for %(extended)d milliseconds! (now %(newtime)d)" ) % { "item": self.name, "extended": ms, "newtime": self.lasts - self.timer.elapsed })
def processGoodItemHit(self, it): """ Processes a good item hit. Called from processItemHit. :param it: Item instance which got hit. :type it: item.Item """ if it.identifier == itemConstants.GOOD_MEGATONPUNCH: existing = self.findEffect("Megaton punch") if existing is None: e = itemEffects.MegatonPunchEffect() e.initialize(self) e.activate(self.field.modeHandler) self.itemEffects.append(e) else: existing.extend(itemConstants.BASE_EFFECT_TIME) return if it.identifier == itemConstants.GOOD_BOOST: e = itemEffects.BoostEffect() e.initialize(self) e.activate(self.field.modeHandler) self.itemEffects.append(e) return if it.identifier == itemConstants.GOOD_PENETRATION: existing = self.findEffect("Penetration") if existing is None: e = itemEffects.PenetrationEffect() e.initialize(self) e.activate(self.field.modeHandler) self.itemEffects.append(e) else: existing.extend(itemConstants.BASE_EFFECT_TIME) return if it.identifier == itemConstants.GOOD_DESTRUCTION: ok = self.field.startDestruction() if not ok: # Already destructing self.autoDestructionRemaining += 1 self.field.log( _("This effect will be used when it's necessary! (Remaining %(r)d)" ) % {"r": self.autoDestructionRemaining}) return if it.identifier == itemConstants.GOOD_EXTRALIFE: self.lives += 1 self.field.log( _("Extra life! (now %(lives)d lives)") % {"lives": self.lives}) s = bgtsound.sound() s.load(globalVars.appMain.sounds["extraLife.ogg"]) s.pitch = 60 + (self.lives * 10) s.play() return
def run(self): s=self.getScreenSize() self.setMousePos(s[0]/2,s[1]/2) self.homeSound=bgtsound.sound() self.homeSound.stream("fx/home.ogg") while(True): self.homeSound.play_looped() self.frameUpdate() if self.keyPressed(window.K_KP0) or self.keyPressed(window.K_0): self.oscController.recalibrate() self.say("センサー準備完了") #end recalibration if self.keyPressed(window.K_RETURN) or self.keyPressed(window.K_KP_ENTER): self.play() if self.keyPressed(window.K_ESCAPE): break
def initialize(self, field, x, speed, type, identifier): self.field = field self.x = x self.y = field.getY() self.speed = speed self.state = STATE_ALIVE self.stepTimer = window.Timer() self.fallingBeep = bgtsound.sound() self.fallingBeep.load(globalVars.appMain.sounds["itemfalling.ogg"]) self.fallingBeep.pan = self.field.getPan(self.x) self.fallingBeep.volume = self.field.getVolume(self.y) self.fallingBeep.pitch = self.field.getPitch(self.y) self.fallingBeep.play_looped() self.type = type self.identifier = identifier
def intro(self): """Plays the intro sound. It blocks when the sound is playing, then starts the game music. """ introsound = bgtsound.sound() introsound.stream("data/sounds/stream/ssIntro.ogg") introsound.play() while (introsound.playing): self.frameUpdate() if self.keyPressed(window.K_RETURN): introsound.fadeout(900) self.wait(1000) break # end skipping with enter # end while intro is playing self.thread_loadSounds.join() self.updateChecker.wait() self.music.play_looped()
def hit(self): """Kills this enemy as it got hit.""" s = bgtsound.sound() s.load(globalVars.appMain.sounds["hit.ogg"]) s.pan = self.field.getPan(self.x) s.pitch = random.randint(70, 130) s.play() self.playScream() self.field.collectionCounter.increment(self.screamNum) self.switchState(STATE_SCREAMING) score = self.field.modeHandler.calculateEnemyDefeatScore(self.speed, self.y) s = self.field.modeHandler.getDefeatMessage(self.speed, self.y) if self.field.easter: s = s.replace("Hit!", "I punched a monkey!") self.field.log(s) self.field.player.addScore(score)
def initialize(self): """ Initializes the app. returns True on success or False on failure. :rtype: bool """ super().initialize( 640, 480, buildSettings.GAME_NAME + " (" + str(buildSettings.GAME_VERSION) + ")") globalVars.appMain = self # data path patch files = glob.glob("data/*.dat") if len(files) > 0: import shutil for elem in files: shutil.copyfile(elem, appDataPath + "/" + os.path.basename(elem)) os.remove(elem) # end files # end patch required # Load sounds self.updateChecker = updateClient.Checker() self.updateChecker.initialize(buildSettings.GAME_VERSION, buildSettings.UPDATE_SERVER_ADDRESS) self.updateChecker.run() self.updateDownloader = None # Not downloading self.thread_loadSounds = threading.Thread(target=self.loadSounds) self.thread_loadSounds.setDaemon(True) self.thread_loadSounds.start() self.options = gameOptions.GameOptions() self.options.initialize(OPTIONS_FILENAME) self.itemVoices = self.getItemVoicesList() self.locales = self.getLocalesList() self.initTranslation() self.music = bgtsound.sound() self.musicData = sound_lib.sample.Sample("data/sounds/stream//bg.ogg") self.music.load(self.musicData) self.music.volume = self.options.bgmVolume self.numScreams = len(glob.glob("data/sounds/scream*.ogg")) self.collectionStorage = collection.CollectionStorage() self.collectionStorage.initialize(self.numScreams, COLLECTION_DATA_FILENAME) self.statsStorage = stats.StatsStorage() self.statsStorage.initialize(STATS_DATA_FILENAME) self.exiting = False # True only within the onExit trap return True
def gamePlay(self, mode): """ Starts the gameplay. It returns when the gameplay is finished or exited. If it is finished with a result, returns the result. Otherwise, returns None. :rtype: gameResult.GameResult """ self.say( _("%(playmode)s, high score %(highscore)s, start!") % { "playmode": mode, "highscore": self.statsStorage.get("hs_" + mode) }) field = gameField.GameField() if random.randint(0, 4999) == 1: self.resetMusicPitch(200) field.initialize(3, 20, mode, self.options.itemVoice, True) else: field.initialize(3, 20, mode, self.options.itemVoice) field.setLimits(self.options.leftPanningLimit, self.options.rightPanningLimit) while (True): self.frameUpdate() if self.keyPressed(window.K_ESCAPE): field.abort() result = gameResult.GameResult() result.initialize(field) result.aborted = True return result # end abort if self.keyPressed(window.K_TAB): self.pauseGame(field) if field.frameUpdate() is False: break # end while field.clear() self.wait(2000) s = bgtsound.sound() s.load(self.sounds["dead.ogg"]) s.pitch = random.randint(70, 130) s.play() self.wait(800) with open("result.txt", mode='a', encoding='utf-8') as f: f.write(field.exportLog()) r = gameResult.GameResult() r.initialize(field) return r
def step(self): """Makes this enemy walk one step. If it reaches to the player, it automatically attacks.""" if self.attackCheck() is True: return self.y -= 1 s = bgtsound.sound() num = 0 while True: num = random.randint(1, 18) if num != self.lastStepNum: break # end while s.load(globalVars.appMain.sounds["s_lf%d.ogg" % num]) s.pan = self.field.getPan(self.x) s.volume = self.field.getVolume(self.y) s.pitch = random.randint(90, 110) if self.y < 4: s.pitch -= (4 - self.y) * 8 s.play() self.stepTimer.restart()
def hit(self): """Called when this player gets hit by one of the enemies. Returns true when the attack succeeds, or False if player attacks back with auto destruction.""" if self.autoDestructionRemaining > 0: self.autoDestructionRemaining -= 1 self.field.log( _("You're about to be attacked, but you have a counter!")) self.field.startDestruction() return False # end auto destruction self.lives -= 1 self.field.log( _("You've been slapped! (%(lives)d HP remaining)") % {"lives": self.lives}) s = bgtsound.sound() if self.lives > 0: s.load(globalVars.appMain.sounds["attacked.ogg"]) s.play() else: self.field.log(_("Game over!")) s.load(globalVars.appMain.sounds["gameover.ogg"]) s.volume = -10 s.play() return False
def optionChange(self, cursor, direction): """Changes a specific game option. Used in the optionsMenu method. :param cursor: the cursor position in the settings menu :type cursor: int :param direction: Which arrow key was pressed (0=left / 1=right) :type direction: int """ if cursor == 0: # BGM volume if direction == 1 and self.options.bgmVolume == self.options.BGMVOLUME_POSITIVE_BOUNDARY: return if direction == -1 and self.options.bgmVolume == self.options.BGMVOLUME_NEGATIVE_BOUNDARY: return if direction == 1: self.options.bgmVolume += 2 if direction == -1: self.options.bgmVolume -= 2 self.music.volume = self.options.bgmVolume self.say("%d" % (abs(-30 - self.options.bgmVolume) * 0.5)) return # end bgm volume if cursor == 1: # left panning limit if direction == 1 and self.options.leftPanningLimit == self.options.LEFTPANNINGLIMIT_POSITIVE_BOUNDARY: return if direction == -1 and self.options.leftPanningLimit == self.options.LEFTPANNINGLIMIT_NEGATIVE_BOUNDARY: return if direction == 1: self.options.leftPanningLimit += 5 if direction == -1: self.options.leftPanningLimit -= 5 s = bgtsound.sound() s.load(self.sounds["change.ogg"]) s.pan = self.options.leftPanningLimit s.play() return # end left panning limit if cursor == 2: # right panning limit if direction == 1 and self.options.rightPanningLimit == self.options.RIGHTPANNINGLIMIT_POSITIVE_BOUNDARY: return if direction == -1 and self.options.rightPanningLimit == self.options.RIGHTPANNINGLIMIT_NEGATIVE_BOUNDARY: return if direction == 1: self.options.rightPanningLimit += 5 if direction == -1: self.options.rightPanningLimit -= 5 s = bgtsound.sound() s.load(self.sounds["change.ogg"]) s.pan = self.options.rightPanningLimit s.play() return # end left panning limit if cursor == 3: # item voice c = 0 for n in self.itemVoices: # which are we selecting? if self.options.itemVoice == n: break c += 1 # detected the current option if direction == 1 and c == len(self.itemVoices) - 1: return # clipping if direction == -1 and c == 0: return # clipping c += direction self.pl = itemVoicePlayer.ItemVoicePlayer() if not self.pl.initialize(self.itemVoices[c]): self.say( _("%(voice)s cannot be loaded.") % {"voice": self.itemVoices[c]}) return self.say(self.itemVoices[c]) self.pl.test() self.options.itemVoice = self.itemVoices[c] return # end item voices if cursor == 4: # language c = 0 for n in self.locales: # which are we selecting? if n == self.options.language: break c += 1 # detected the current option if direction == 1 and c == len(self.locales) - 1: return # clipping if direction == -1 and c == 0: return # clipping c += direction self.say(self.locales[c]) self.options.language = self.locales[c] return