示例#1
0
    def run(self):

        self.running = True
        self.evManager.Post(InitializeEvent())
        self.state.push(STATE_MENU)
        while self.running:
            newTick = TickEvent()
            self.evManager.Post(newTick)
            if self.state.peek() == STATE_MENU:
                pass
            elif self.state.peek() == STATE_LIBRARY:
                pass
            elif self.state.peek() == STATE_EMPTYLIBRARY:
                pass
            elif self.state.peek() == STATE_ENDGAME:
                pass
            elif self.state.peek() == STATE_CHOOSEFILE:
                pass
            elif self.state.peek() == STATE_FILENOTFOUND:
                pass
            elif self.state.peek() == STATE_PLAY:
                if not self.pause:
                    for i in range(len(self.listInstruments)):
                        self.instrumentNow(self.listInstruments[i], i)
                    if not self.passTimeMusic and timer.time(
                    ) >= self.config["timeadvence"]:
                        self.passTimeMusic = True
                        pygame.mixer.music.play()
                    if timer.time(
                    ) >= self.duration + self.config["timeadvence"]:
                        self.evManager.Post(StateChangeEvent(STATE_ENDGAME))
            elif self.state.peek() == STATE_LOADING:
                pass
            else:
                self.running = False
示例#2
0
    def __init__(self, evManager):

        # config

        with open('config.json') as json_data:
            self.config = json.load(json_data)

        # variable for game state

        self.time_start = None
        self.music = None

        self.arrayInstruments = None
        self.listInstruments = None
        self.saveArrayInstruments = None
        self.saveListInstruments = None
        self.gamescore = 0

        self.passTimeMusic = False
        self.duration = None
        self.file = None
        self.bestscore = None

        self.pause = False

        self.timeVideoCheckPoint = timer.time()
        self.passVideo = False

        # general
        self.evManager = evManager
        evManager.RegisterListener(self)
        self.running = False
        self.state = StateMachine()
示例#3
0
文件: view.py 项目: Alewep/REETM
    def renderplay(self):
        """
        Draw the current game state on screen.
        Does nothing if isinitialized == False (pygame.init failed)
        """
        self.screen.fill((0, 0, 0))
        if self.video is None:
            self.initializeVideo()
        else:
            self.video.update(time=timer.time() -
                              self.model.config["timeadvence"])
            self.video.draw(self.screen)

        self.BUTTONPAUSE.draw(self.screen)
        self.drawCheckCircles(screen_height)
        self.drawCheckLetters(screen_height)

        if self.message is not None:
            self.displaySucces(self.message)

        if not self.model.pause:
            for instrument in self.instruments_state:
                self.updateInstrument_state(instrument)
            self.drawInstruments()
        else:
            self.drawInstruments()
            self.PANELPAUSE.draw(self.screen)

        self.displayScore()
        self.displayBestScore()

        # flip the display to show whatever we drew
        pygame.display.flip()
示例#4
0
    def instrumentNow(self, liste_beat, num_classe):

        if (len(liste_beat) >
                0) and (timer.time() >=
                        (liste_beat[0] - self.config["timeadvence"])):
            newBeatEvent = BeatEvent(Beat(liste_beat[0]), num_classe)
            self.evManager.Post(newBeatEvent)
            liste_beat.pop(0)
示例#5
0
文件: view.py 项目: Alewep/REETM
    def __init__(self, evManager, model):
        """
        evManager (EventManager): Allows posting messages to the event queue.
        model (GameEngine): a strong reference to the game Model.
                
        Attributes:
        isinitialized (bool): pygame is ready to draw.
        screen (pygame.Surface): the screen surface.
        clock (pygame.time.Clock): keeps the fps constant.

        """

        self.evManager = evManager
        evManager.RegisterListener(self)
        self.model = model
        self.isinitialized = False
        self.screen = None
        self.clock = None
        self.imgMenu = None

        self.instruments_state = []

        self.message = None
        self.a_pressed = False
        self.z_pressed = False
        self.e_pressed = False

        self.buttonMenuPlay = None
        self.buttonMenuReturn = None
        self.fileSelected = None
        self.songs_list = None
        self.counter = 0
        self.cooldown = 1000
        self.last = timer.time()

        self.positions = self.positions_difficuly()

        self.video = None

        self.YOUTUBELINKTEXTBOX = None
        self.BUTTONYOUTUBELINK = None
        self.BUTTONRESET = None
        self.BUTTONPAUSE = None
        self.PANELPAUSE = None
        self.BUTTONPASTE = None
示例#6
0
文件: view.py 项目: Alewep/REETM
    def renderloading(self):

        fontTitle = pygame.font.SysFont('arial', 100)

        self.screen.fill((0, 0, 0))
        self.screen.blit(self.imgMenu, (0, 0))
        text = fontTitle.render("Loading", True, (255, 255, 255))
        if self.counter == 3:
            self.counter = 0

        now = timer.time()

        if now - self.last >= self.cooldown:
            self.last = now
            self.counter += 1
        if self.counter == 0:
            text = fontTitle.render("Loading.", True, (133, 193, 233))
        elif self.counter == 1:
            text = fontTitle.render("Loading..", True, (133, 193, 233))
        elif self.counter == 2:
            text = fontTitle.render("Loading...", True, (133, 193, 233))

        self.screen.blit(text, (375, 300))
        pygame.display.flip()
示例#7
0
 def updatePosition(self):
     actualTime = timer.time()
     durationLife = actualTime - self.timeSend
     self.position = durationLife * self.speed()
示例#8
0
    def charginMusic(self):
        try:
            self.passTimeMusic = False
            if self.file is not None:
                # place music to a other directory into Library
                name, ext = os.path.splitext(os.path.basename(self.file))
                self.music = Music(PATHOFLIBRARY, name)
                library.placeInLibrary(self.file, self.music.musicPath())
                musicfile = AutomaticBeats(self.music.musicPath(),
                                           preprocessPath=PREPROCESSEDPATH,
                                           spleeter=self.config["spleeter"])
                dictInstruments = musicfile.getinstruments()
                musicfile.savejson(self.music.jsonPath())

            elif self.music is not None:
                musicfile = AutomaticBeats(self.music.musicPath(),
                                           preprocessPath=PREPROCESSEDPATH,
                                           spleeter=self.config["spleeter"])

                if not os.path.exists(
                        self.music.jsonPath(spleeter=self.config["spleeter"])):
                    dictInstruments = musicfile.getinstruments()
                    musicfile.savejson(self.music.jsonPath())
                else:
                    dictInstruments = library.json_to_dict(
                        self.music.jsonPath(spleeter=self.config["spleeter"]))

            self.arrayInstruments = [
                (instrument[1] * 1000 + self.config["timeadvence"])
                for instrument in dictInstruments.items()
            ]

            if self.config['difficulty'] == 3:
                self.arrayInstruments = [
                    (instrument[1] * 1000 + self.config["timeadvence"])
                    for instrument in dictInstruments.items()
                ]

            elif self.config['difficulty'] == 2:

                arraykicksnare = [
                    (instrument[1] * 1000 + self.config["timeadvence"])
                    for instrument in dictInstruments.items()
                    if (instrument[0] in ['Kick', 'Snare'])
                ]
                arraykicksnare = np.concatenate(
                    [arraykicksnare[0], arraykicksnare[1]])

                self.arrayInstruments = [np.sort(arraykicksnare)] + [
                    (instrument[1] * 1000 + self.config["timeadvence"])
                    for instrument in dictInstruments.items()
                    if (instrument[0] == 'Hihat')
                ]
            elif self.config['difficulty'] == 1:
                arrayallinstruments = [
                    (instrument[1] * 1000 + self.config["timeadvence"])
                    for instrument in dictInstruments.items()
                ]
                arrayallinstruments = np.concatenate([
                    arrayallinstruments[0], arrayallinstruments[1],
                    arrayallinstruments[2]
                ])
                self.arrayInstruments = [np.sort(arrayallinstruments)]

            if self.config["simplification"]:
                self.arrayInstruments = simplification(
                    self.arrayInstruments,
                    timerange=self.config["timeRangeForSimplification"])

            self.saveArrayInstruments = copy.deepcopy(self.arrayInstruments)
            if os.path.exists(self.music.bestScorePath()):
                self.bestscore = np.loadtxt(self.music.bestScorePath())
            pygame.mixer.init()

            pygame.mixer.music.load(self.music.musicPath())
            pygame.mixer.music.pause()

            self.duration = musicfile.getduration() * 1000  # ms
            self.gamescore = 0
            self.listInstruments = [
                instrument.tolist() for instrument in self.arrayInstruments
            ]
            self.saveListInstruments = copy.deepcopy(self.listInstruments)
            self.state.push(STATE_PLAY)
            timer.reset()
            self.timeVideoCheckPoint = timer.time()
            self.passVideo = False
        except Exception as e:
            warnings.warn(str(e))
            self.state.push(STATE_MENU)
示例#9
0
 def setTimeSend(self):
     self.timeSend = timer.time()
示例#10
0
 def __init__(self, time):
     self.time = time
     self.timeSend = timer.time()
     self.distanceInPixel = 0
     self.position = 0
示例#11
0
 def __init__(self, instrumentclass, pressed):  # instrumentclass is int
     self.name = "Input event"
     self.classe = instrumentclass
     self.time = timer.time()
     self.pressed = pressed
示例#12
0
文件: view.py 项目: Alewep/REETM
 def isexcellent(self, beat):
     return (beat.time <
             timer.time() + self.model.config["delta_excellent"]) and (
                 beat.time > timer.time() - self.model.config["delta_meh"])