def ChangeScene(index):
     gVariables.g_scene = index
     if index == 0:
         director.replace(FadeTransition(Scene(MenuScene(gVariables.g_RESOURCES))))
     elif index == 1:
         director.replace(FadeTransition(Scene(GameScene(gVariables.g_RESOURCES))))
     else:
         exit(0)
Exemple #2
0
    def increment_sprites(self, packet):  # changes the position of the sprites
        global transition
        global spaghetti_names
        global IDENTIFIER
        global timeLeft
        global p1_score, p2_score

        #print("ID", IDENTIFIER)

        self.packet_dict = json.loads(
            packet)  # receieve the json from the server
        timeLeft = self.packet_dict[
            'time']  #unpack it and edit the global gamestate
        p1_score = self.packet_dict['p1_score']
        p2_score = self.packet_dict['p2_score']
        if int(timeLeft) == 0 and not transition:  #  if the game is over
            #print ("Negative")
            transition = True
            timeLeft = -1
            #self.updateLoop.stop()
            director.replace(FadeTransition(Scene(
                endLayer())))  # transition to the game over screen
            #reactor.stop()
        if int(timeLeft) < 0:  # stop looping if the time is negative
            return
#self.updateLoop.end()
#print(self.packet_dict)
        for el in self.packet_dict:  # use the information from the server to update the position of the spagetti
            if el != IDENTIFIER and el in ["client0", "client1"]:
                #print(el)
                self.sprite_vector[el].position = tuple(
                    self.packet_dict[el]['position'])
            if el in spaghetti_names:
                self.spaghetti[el].position = tuple(
                    self.packet_dict[el]['position'])
Exemple #3
0
    def on_mouse_press(self, x, y, buttons, modifiers):
        global volume_avg_list, pitch_avg_list, volume_talk_avg, pitch_talk_avg, volume_sing_avg, pitch_sing_avg
        self.position_x, self.position_y = director.get_virtual_coordinates(
            x, y)
        print(self.position_x)
        print(self.position_y)
        if ((840 < self.position_x < 860) and (270 < self.position_y < 290)):
            self.remove(self.talk_1)
            self.remove(self.talk_2)
            self.remove(self.button)
            self.button.position = (850, 90)
            self.add(self.button)
            self.add(self.sing_1)
            self.add(self.sing_2)
            volume_talk_avg = sum(volume_avg_list) / len(volume_avg_list)
            print("Average talk volume is %s" % (volume_talk_avg))
            pitch_talk_avg = sum(pitch_avg_list) / len(pitch_avg_list)
            print("Average talk pitch is %s" % (pitch_talk_avg))
            volume_avg_list = []
            pitch_avg_list = []

        if ((840 < self.position_x < 860) and (70 < self.position_y < 90)):
            #clicksound.play(self.talk)
            main_scene = cocos.scene.Scene()
            main_scene.add(scroller)
            main_scene.add(InputVoice())
            volume_sing_avg = sum(volume_avg_list) / len(volume_avg_list)
            print("Average volume is %s" % (volume_sing_avg))
            pitch_sing_avg = sum(volume_avg_list) / len(volume_avg_list)
            print("Average pitch is %s" % (pitch_sing_avg))
            director.replace(FadeTransition(main_scene, duration=1))
Exemple #4
0
 def on_restart(self):
     clicksound.play()
     #go back to main scene
     time.sleep(0.5)
     director.replace(FadeTransition(main_scene, duration=1))
     audiomixer.pause()
     self.game.reset()
Exemple #5
0
    def on_mouse_press(self, x, y, buttons, modifiers):
        global volume_avg_list, pitch_avg_list, volume_talk_avg, pitch_talk_avg, volume_sing_avg, pitch_sing_avg, volume_std
        self.position_x, self.position_y = director.get_virtual_coordinates(
            x, y)
        print(self.position_x)
        print(self.position_y)
        if ((840 < self.position_x < 860) and (270 < self.position_y < 290)):
            self.remove(self.talk_1)
            self.remove(self.talk_2)
            self.remove(self.button)
            self.button.position = (850, 90)
            self.add(self.button)
            self.add(self.sing_1)
            self.add(self.sing_2)
            self.add(self.sing_3)
            volume_talk_avg = np.array(volume_avg_list).mean()
            print("Average talk volume is %s" % (volume_talk_avg))
            pitch_talk_avg = np.array(pitch_avg_list).mean()
            print("Average talk pitch is %s" % (pitch_talk_avg))
            volume_avg_list = []
            pitch_avg_list = []

        if ((840 < self.position_x < 860) and (70 < self.position_y < 90)):
            clicksound.play()
            main_scene = cocos.scene.Scene()
            main_scene.add(scroller)
            main_scene.add(InputVoice())
            volume_sing_avg = np.array(volume_avg_list).mean()
            volume_std = np.array(volume_avg_list).std()
            print("Average volume is %s" % (volume_sing_avg))
            pitch_sing_avg = np.array(pitch_avg_list).mean()
            print("Average pitch is %s" % (pitch_sing_avg))
            #           menuLayer_back = MultiplexLayer(MainMenus())
            #           main_menu_scene = cocos.scene.Scene(scroller_menu,menuLayer_back)
            director.replace(FadeTransition(main_scene, duration=1))
 def getHit(self):
     if self.is_dead_scene_Playing == False and self.is_shield == False:
         self.total_lives -= 1
         self.revive_Pattern = Place(self.startLocation) + CallFunc(
             self.revive) + Blink(4, 2) + CallFunc(self.shieldoff)
         self.deadtemplate = Delay(0.5) + CallFunc(self.destroy)
         self.die()
         if self.total_lives <= 0:
             director.replace(FadeTransition(FinishScene(self.gScene)))
Exemple #7
0
	def wait_server(self):
		mes = {'type': 'ask', 'question': 'game_ready'}
		mes_bit = MyProtocol.getByteStrFromData(mes)
		self.sock.send(mes_bit)
		data_bit = self.sock.recv(10000)
		data = MyProtocol.getDataFromByteStr(data_bit)

		if data['type'] == 'ask' and data['question'] == 'game_ready' and data['answer'] == 'yes':
			director.replace(FadeTransition(Level1Scene(self)))
Exemple #8
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     self.position_x, self.position_y = director.get_virtual_coordinates(
         x, y)
     print(self.position_x)
     print(self.position_y)
     if ((840 < self.position_x < 860) and (70 < self.position_y < 90)):
         clicksound.play()
         menuLayer_back = MultiplexLayer(MainMenus())
         main_menu_scene = cocos.scene.Scene(scroller_menu, menuLayer_back)
         director.replace(FadeTransition(main_menu_scene, duration=1))
Exemple #9
0
    def on_key_press(self, key, modifiers):
        char_key = symbol_string(key)
        if char_key == "ENTER":
            # Segue to next layer with username
            global playerName
            playerName = self.player_name
            director.replace(FadeTransition(Scene(DifficultyLayer())))

        # Add to the username if valid characters.
        elif 'A' <= char_key <= 'z':
            self.player_name += char_key
            self.update_player_name()
Exemple #10
0
    def handle_answer(self):
        if not self.answer:
            self.answer = 10
        if self.game.submit_answer(int(self.answer)):
            print("Correct Answer")
        else:
            print("Incorrect Answer")

        # Update Score board.
        self.score_board_label.element.text = " Score: {}".format(
            self.game.get_current_state())

        # If not game over, continue with next question.
        if not self.game.is_game_over():
            self.display_question()
        else:
            # Move to next screen with score.
            director.replace(FadeTransition(Scene(ScoreBoardScreen())))
Exemple #11
0
 def pop_scene(self):
     last_scene = cocos.director.director.scene_stack[
         len(cocos.director.director.scene_stack) - 1]
     cocos.director.director.pop()
     cocos.director.director.replace(FadeTransition(last_scene))
Exemple #12
0
 def on_key_press(self, key, modifiers):
     # Adding transitions into your Scenes is pretty easy
     # All you need to do is put a transition in the replace method
     director.replace(FadeTransition(Scene(Layer2())))
Exemple #13
0
 def transition_next_scene(self):
     director.replace(FadeTransition(Scene(GameScreen())))
 def goMainMenu(self):
     from app.scene.menuScene import MenuScene
     director.replace(FadeTransition(Scene(MenuScene(self.R))))
Exemple #15
0
    def update(self, dt):
        global num_pitches, x_coors, num_bloomed, num_flowers, audiomixer, volumes, pitches, time_data, volume_sing_avg, volume_std
        if (num_bloomed < num_flowers):
            data = self.stream.read(self.CHUNK, exception_on_overflow=False)
            sample = np.fromstring(data, dtype=aubio.float_type)
            pitch = self.pDetection(sample)[0]
            self.time_update += dt
            volume = np.sum(sample**2) / len(sample)
            pitches.append(pitch)
            time_data.append(self.time_update)
            volumes.append(volume)
            # print(volume,volume_sing_avg,volume_std)

            if (0 < pitch < 200):
                self.add_flower(0, 'purple')
            elif (200 <= pitch < 250):
                self.add_flower(1, 'blue')
            elif (250 <= pitch < 300):
                self.add_flower(2, 'cyan')
            elif (300 <= pitch < 400):
                self.add_flower(3, 'orange')
            elif (400 <= pitch < 500):
                self.add_flower(4, 'pink')
            elif (500 <= pitch < 600):
                self.add_flower(5, 'yellow')
            elif (600 <= pitch < 1100):
                self.add_flower(6, 'white')

            if (volume > 0.0001):
                n = len(self.flowers.get_children())
                num_bloomed = 0
                for flower in self.flowers.get_children():
                    flower.points += max(
                        (1 - abs(volume - volume_sing_avg) / volume_std) / n,
                        0)
                    if (flower.stage7):
                        num_bloomed += 1

            if (volume > volume_sing_avg):
                self.water.set_value((volume - volume_sing_avg) / volume_std)
                self.nutrition.set_value(
                    (volume - volume_sing_avg) / volume_std)
            else:
                self.water.set_value(
                    (volume - volume_sing_avg) / volume_sing_avg)
                self.nutrition.set_value(
                    (volume - volume_sing_avg) / volume_sing_avg)

            volume = "{:.6f}".format(volume)
            #print(dt)
            self.pitchLabel.element.text = 'Pitch: ' + pitch.astype('str')
            self.volumeLabel.element.text = 'Volume: ' + volume
            self.plantLabel.element.text = 'Number of flowers planted: ' + str(
                len(self.flowers.get_children()))
            self.bloomLabel.element.text = 'Number of flowers bloomed: ' + str(
                num_bloomed)
            if (flower_under_mouse != None):
                self.flowerbar.set_value(flower_under_mouse.points)
                #self.stageLabel.element.text='Stage: '+flower_under_mouse.stage
            if (num_bloomed == num_flowers):
                self.pitchLabel.element.text = ''
                self.volumeLabel.element.text = ''
                self.colorLabel.element.text = ''
                self.congratsLabel = cocos.text.Label(
                    'Congratulations!',
                    font_name='Times New Roman',
                    font_size=36,
                    anchor_x='center',
                    anchor_y='center')
                self.congratsLabel.position = 780, 120
                self.add(self.congratsLabel)

                audiomixer.unpause()
                #add end menu
                self.endmenuLayer = MultiplexLayer(GameEnd(self))
                endscene = cocos.scene.Scene(scroller_menu, self.endmenuLayer)
                director.replace(FadeTransition(endscene, duration=2))
Exemple #16
0
 def on_credits(self):
     clicksound.play()
     print("To cedits")
     director.replace(FadeTransition(credits_scene, duration=1))
 def start_game(self):
     director.replace(FadeTransition(Scene(Beach_scene(), InGameMenu())))
Exemple #18
0
 def on_instruction(self):
     print("To instruction")
     clicksound.play()
     director.replace(FadeTransition(instruction_scene, duration=1))
Exemple #19
0
 def on_new_game(self):
     #       director.set_scene(main_scene)
     clicksound.play()
     time.sleep(0.5)
     audiomixer.pause()
     director.replace(FadeTransition(test_scene, duration=2))
 def on_key_press(self, key, modifiers):
     if symbol_string(key) == "ENTER":
         director.replace(FadeTransition(Scene(Beach_scene(),
                                               InGameMenu())))
 def control_menu(self):
     director.replace(FadeTransition(Scene(ControlBoi())))
Exemple #22
0
 def show_mainmenu(self):
     """shows the main menu"""
     self.scenes["mainmenu"] = SceneMainMenu()
     director.replace(FadeTransition(self.scenes["mainmenu"], duration=2))