def touch_ended(self, touch): # this method is called, when user releases a finger from the screen #pass # back button if self.back_arrow_button.frame.contains_point(touch.location): self.dismiss_modal_scene() # sound slider if self.sound_slider.frame.contains_point(touch.location): #print("sound slider clicked") if config.sound_setting == True: config.sound_setting = False sound.stop_effect(config.background_music) elif config.sound_setting == False: config.sound_setting = True config.background_music = sound.play_effect( './assets/sounds/backgroundMusic.mp3', volume=0.2) # changing characters options and animating them but only for 1 cycle if self.classic_ninja.frame.contains_point(touch.location): config.character_setting = 'classic' self.animate_classic_enabled = True if self.ginger_ninja.frame.contains_point(touch.location): config.character_setting = 'ginger' self.animate_ginger_enabled = True #print(config.character_setting) if self.bat_ninja.frame.contains_point(touch.location): config.character_setting = 'bat' self.animate_bat_enabled = True
def test_audio(sender): global effectID global playing if (playing == True): sound.stop_effect(effectID) playing = False else: effectID = sound.play_effect(trackname) playing = True
def stop_sequence(sender): global effectID global sequence_running val = console.alert("Stop Running Sequence", "Are you sure you want to stop this sequence?", button1="YES") if val == 1: sequence_running = False sound.stop_effect(effectID) v['status_label'].text = ("System Status: ARMED Ready to Fire") v['start_sequence_button'].enabled = True v['stop_sequence_button'].enabled = False v['manual_fire_button'].enabled = True v['disarm_system_button'].enabled= True
def update(self): # this method is called, hopefully, 60 times a second #pass # check if sound was turned off if config.sound_setting == False: sound.stop_effect(config.background_music) # check if audio has stopped playing and play again if config.sound_setting == True and ( time.time() - self.music_start_time >= 65): config.background_music = sound.play_effect( './assets/sounds/backgroundMusic.mp3') self.music_start_time = time.time()
def touch_ended(self, touch): # this method is called, when user releases a finger from the screen # if start button is pressed, goto game scene if self.fire_button.frame.contains_point(touch.location): sound.play_effect('laser1.wav') #Play music sound.stop_effect('laser1.wav') #Stop music #Need to stop music after playing self.create_new_missile('missile.png') #Play music else: # if I removed my finger, then no matter what spaceship # should not be moving any more self.left_button_down = False self.right_button_down = False
def stop_all_effects(self): for id in self._l: soundOrig.stop_effect(id) self._l = list()
def stop_effect(self, effect_id): soundOrig.stop_effect(effect_id) self._l.remove(effect_id)
def draw(self): w = self.size.w h = self.size.h sw = w * 0.25 if self.state == 'Menu': background(0.75, 1, 0) tint(0, 0, 0) text('Tap Defense', 'BanglaSangamMN', self.titleS, w * 0.5, h * 0.8) text('YOLO', self.scoreF, self.largeS, w * 0.5, h * 0.5) text('Have Fun...', self.scoreF, self.largeS, w * 0.5, h * 0.35) text('Highscores', self.scoreF, self.largeS, w * 0.5, h * 0.2) elif self.state in ['YOLO', 'Have Fun']: background(0, 0, 0) if self.music_frame in self.music: if self.prevEffect: stop_effect(self.prevEffect) self.prevEffect = play_effect('Piano_' + self.music[self.music_frame]) self.music_frame = (self.music_frame + 1) % 384 for i in self.buttons: i.update(self.dt) i.draw() fill(1, 1, 1) rect(0, sw, w, 1) for i in range(1, 4): rect(sw * i, 0, 1, sw) for image in self.imagesOnScreen: image.frame = image.frame.translate(0, -self.speed) if image.frame.y <= sw: self.imagesOnScreen.remove(image) self.endGame() image.update(self.dt) image.draw() if randint(0, self.maxSpeed * 2) < self.speed: x = randint(0, 3) * sw image = self.buttons[randint(0, 3)].image if not any( Rect(x, h - sw, sw, sw).intersects(i.frame) for i in self.imagesOnScreen): layer = Layer(Rect(x, h - sw, sw, sw)) layer.image = image self.imagesOnScreen.append(layer) self.speed = min(self.speed + 0.001, self.maxSpeed) elif self.state.startswith('Starting'): background(0, 0, 0) tint(1, 1, 1) text( 'YOLO Mode' if self.state == 'Starting YOLO' else 'Have Fun...', self.f, self.titleS, w * 0.5, h * 0.9) text('How to play:', self.instrF, self.s, w * 0.5, h * 0.75) text('When a picture falls down', self.instrF, self.smallS, w * 0.5, h * 0.67) text('from the top of the screen,', self.instrF, self.smallS, w * 0.5, h * 0.63) text('tap on its corresponding', self.instrF, self.smallS, w * 0.5, h * 0.59) text('image on the bottom to', self.instrF, self.smallS, w * 0.5, h * 0.55) text('make it dissappear. If an', self.instrF, self.smallS, w * 0.5, h * 0.51) text('image makes it to the', self.instrF, self.smallS, w * 0.5, h * 0.47) text('bottom, you lose the game.', self.instrF, self.smallS, w * 0.5, h * 0.43) text('Tap to start!', self.f, self.titleS, w * 0.5, h * 0.12) elif self.state.endswith('Win'): background(0, 0, 0) text('New Highscore!' if self.highscoreText else 'You lost!', self.f, self.largeS, w * 0.5, h * 0.9) text('Time:', self.scoreF, self.titleS, w * 0.5, h * 0.5) text( str(int(self.time)) + ' seconds', self.scoreF, self.largeS, w * 0.5, h * 0.45) text('Menu', self.f, self.smallS, w - 5, 5, alignment=7) elif self.state == 'Highscores': background(0, 0, 0) tint(1, 1, 1) text('Highscores', self.f, self.largeS, w * 0.5, h * 0.9) text('YOLO Mode:', self.f, self.largeS, w * 0.5, h * 0.55) text( str(int(self.highscores['YOLO'])) + ' seconds', self.f, self.s, w * 0.5, h * 0.5) text('Have Fun Mode:', self.f, self.largeS, w * 0.5, h * 0.35) text( str(int(self.highscores['Have Fun'])) + ' seconds', self.f, self.s, w * 0.5, h * 0.3) text('Menu', self.f, self.smallS, w - 5, 5, alignment=7)
def stop_all_effects(self): for sound_id in self._playing: sound.stop_effect(sound_id) self._playing.clear()
def stop_effect(self, sound_id): sound.stop_effect(sound_id) del self._playing[sound_id]
# https://forum.omz-software.com/topic/3641/sound-effect-not-stopping import sound, time y = "room_One.mp3" x = sound.play_effect(y) #sound.play_effect(y) # <- This call can be removed time.sleep(5) sound.stop_effect(x)
def touch_ended(self, touch): global keyid sound.stop_effect(keyid)