예제 #1
0
class Beatector(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.events = []
        self.state = 'INIT'
        self.beat = None
        self.phase = 0.0
        self.count = 0

    def hit(self):
        print("BEAT %d" % (self.count + 1))
        self.count = (self.count + 1) % 4
        self.schedule()

    def initializeBeat(self):
        pivot = self.events[0]
        estimate = 0.0
        for i in range(1, len(self.events)):
            estimate += self.events[i - 1] - self.events[i]
        estimate /= len(self.events) - 1
        print(estimate)
        phase = (pivot + estimate) % (4 * estimate)
        self.beat = Beat(period=estimate, phase=phase)

    def schedule(self):
        if sync.terminate.isSet():
            return

        if self.state == 'INIT':
            self.initializeBeat()
            beater = Timer(self.beat.period, self.hit)
            beater.start()
            self.state = 'ROLLING'
            return

        phase_adjust = self.beat.phase - self.phase
        beater = Timer(self.beat.period + phase_adjust, self.hit)
        beater.start()
        self.phase = self.beat.phase

    # Main thread. Pops events from the sync queue and inserts them
    # into the local event queue. Beat estimation is started as soon
    # as five events are in the queue.
    def run(self):
        print("starting beat estimator")
        while not sync.terminate.isSet():
            sync.queueEvent.wait()
            sync.queueEvent.clear()
            while not sync.queue.empty():
                e = sync.queue.get()
                self.events.insert(0, e)
                if self.state == 'INIT':
                    if len(self.events) == 4:
                        self.schedule()
                elif self.state == 'ROLLING':
                    self.beat.resyncOn(e)
                    self.beat.adjustTempo(self.events)
                    print('Period: %5.4f\tPhase: %5.4f' %
                          (self.beat.period, self.beat.phase))
        print("stopping beat estimator")
예제 #2
0
 def initializeBeat(self):
     pivot = self.events[0]
     estimate = 0.0
     for i in range(1, len(self.events)):
         estimate += self.events[i - 1] - self.events[i]
     estimate /= len(self.events) - 1
     print(estimate)
     phase = (pivot + estimate) % (4 * estimate)
     self.beat = Beat(period=estimate, phase=phase)
예제 #3
0
def beats_to_voice(beats):
    result = Voice()
    for beat in beats:
        cur_beat = Beat()
        tones = re.findall(r'(\\|/)?([0-7\*])(\,|\')*', beat)
        for group_digit in tones:
            cur_beat.add_tone(digit_to_tone(group_digit))
        result.add_beat(cur_beat)
    return result
예제 #4
0
def getBeatFromDat(listOfBeats, ecgData, beatNum, leadNum):
    '''
	Returns an object of the [Beat] class that contains the data associated with the (beatNum + 1)-th beat and
	(leadNum + 1)-th lead of the ECG signal associated with the patient whose list of beats is specified by the list of
	tuples [listOfBeats] (see the documentation for the above method getBeatsFromAnn for a full description of [listOfBeats])
	and whose ECG signal is specified by the array [ecgData] (see the documentation for the above method getECGSignalFromDat for
	a full description of [ecgData].
    
	'''

    (beginSampleIndex, endSampleIndex, typeOfBeat,
     auxillary) = listOfBeats[beatNum]

    timeStamps = []
    ecgReadings = []

    for index in range(beginSampleIndex, endSampleIndex + 1):
        sample = ecgData[index]

        timeStamps.append(sample[0])
        ecgReadings.append(sample[leadNum + 1])

    return Beat(timeStamps, ecgReadings, typeOfBeat, auxillary)
예제 #5
0
def parse(filename):
    file = open(filename, "r", encoding="utf-8")
    chart = mania.Chart()
    json_datas = file.read()
    mc_chart = json.loads(json_datas)
    chart.artist = mc_chart["meta"]["song"]["artist"]
    chart.artist_unicode = mc_chart["meta"]["song"]["artist"]
    chart.creator = mc_chart["meta"]["creator"]
    chart.key_amount = mc_chart["meta"]["mode_ext"]["column"]
    chart.leadin = 0
    chart.preview = mc_chart["meta"].get("preview", 0)
    chart.title = mc_chart["meta"]["song"]["title"]
    chart.title_unicode = mc_chart["meta"]["song"]["title"]
    chart.version = mc_chart["meta"]["version"]
    time_start = 0.0
    audio = ""
    note_special = mc_chart["note"][0]
    if note_special.get("type", 0) == 1:
        time_start = note_special["offset"]
        audio = note_special["sound"]
    else:
        note_special = mc_chart["note"][-1]
        if note_special.get("type", 0) == 1:
            time_start = note_special["offset"]
            audio = note_special["sound"]
        else:
            for mc_note in mc_chart["note"][1:-1]:
                if mc_note.get("type", 0) == 1:
                    time_start = mc_note["offset"]
                    audio = mc_note["sound"]
                    break
    bpms = []
    previous_time = time_start
    previous_bpm = 200.0
    previous_beat = Beat()
    for mc_bpm in mc_chart["time"]:
        bpm = mania.BPM()
        beat = Beat(*mc_bpm["beat"])
        bpm.time = previous_time + (beat - previous_beat).to_time(
            60000.0 / previous_bpm
        )
        bpm.bpm = mc_bpm["bpm"]
        bpms.append(bpm)
        previous_time = bpm.time
        previous_bpm = bpm.bpm
        previous_beat = beat
    chart.bpms = bpms
    notes = []
    previous_bpm_index = 0
    next_bpm_index = 1
    previous_time = time_start
    for mc_note in mc_chart["note"]:
        column = mc_note.get("column", None)
        if column == None:
            continue
        note_beat = Beat(*mc_note["beat"])
        while next_bpm_index < len(bpms):
            next_bpm_beat = Beat(*mc_chart["time"][next_bpm_index]["beat"])
            if note_beat >= next_bpm_beat:
                previous_bpm_beat = Beat(*mc_chart["time"][previous_bpm_index]["beat"])
                previous_time += (next_bpm_beat - previous_bpm_beat).to_time(
                    60000.0 / bpms[previous_bpm_index].bpm
                )
                previous_bpm_index += 1
                next_bpm_index += 1
            else:
                break
        previous_bpm_beat = Beat(*mc_chart["time"][previous_bpm_index]["beat"])
        note = mania.Note()
        note.column = column
        note.start = (note_beat - previous_bpm_beat).to_time(
            60000.0 / bpms[previous_bpm_index].bpm
        ) + previous_time
        end_beat = mc_note.get("endbeat", None)
        if end_beat != None:
            end_beat = Beat(*end_beat)
            temp_previous_bpm_index = previous_bpm_index
            temp_next_bpm_index = next_bpm_index
            temp_previous_time = previous_time
            while temp_next_bpm_index < len(bpms):
                temp_next_bpm_beat = Beat(
                    *mc_chart["time"][temp_next_bpm_index]["beat"]
                )
                if end_beat >= temp_next_bpm_beat:
                    temp_previous_bpm_beat = Beat(
                        *mc_chart["time"][temp_previous_bpm_index]["beat"]
                    )
                    temp_previous_time += (
                        temp_next_bpm_beat - temp_previous_bpm_beat
                    ).to_time(60000.0 / bpms[temp_previous_bpm_index].bpm)
                    temp_previous_bpm_index += 1
                    temp_next_bpm_index += 1
                else:
                    break
            temp_previous_bpm_beat = Beat(
                *mc_chart["time"][temp_previous_bpm_index]["beat"]
            )
            note.end = (end_beat - temp_previous_bpm_beat).to_time(
                60000.0 / bpms[temp_previous_bpm_index].bpm
            ) + temp_previous_time
        hitsound = mc_note.get("sound", None)
        if hitsound != None:
            note.hitsound = hitsound
            note.volume = mc_note.get("vol", 100)
        notes.append(note)
    chart.notes = notes
    chart.audio = audio
    effects = mc_chart.get("effect", None)
    if effects:
        previous_bpm_index = 0
        next_bpm_index = 1
        previous_time = time_start
        for mc_effect in effects:
            beat = Beat(*mc_effect["beat"])
            scroll = mc_effect["scroll"]
            while next_bpm_index < len(bpms):
                next_bpm_beat = Beat(*mc_chart["time"][next_bpm_index]["beat"])
                if beat >= next_bpm_beat:
                    previous_bpm_beat = Beat(
                        *mc_chart["time"][previous_bpm_index]["beat"]
                    )
                    previous_time += (next_bpm_beat - previous_bpm_beat).to_time(
                        60000.0 / bpms[previous_bpm_index].bpm
                    )
                    previous_bpm_index += 1
                    next_bpm_index += 1
                else:
                    break
            previous_bpm_beat = Beat(*mc_chart["time"][previous_bpm_index]["beat"])
            effect = mania.Effect(
                time=(beat - previous_bpm_beat).to_time(
                    60000.0 / bpms[previous_bpm_index].bpm
                )
                + previous_time,
                scroll=scroll,
            )
            chart.effects.append(effect)
    return chart
예제 #6
0
def write(chart: mania.Chart, filename):
    file = open(filename, "w", encoding="utf-8")
    mc = dict()
    mc["meta"] = dict()
    mc["meta"]["creator"] = chart.creator
    mc["meta"]["version"] = chart.version
    mc["meta"]["preview"] = chart.preview
    mc["meta"]["mode"] = 0
    mc["meta"]["time"] = int(time.time())
    mc["meta"]["song"] = dict()
    mc["meta"]["song"]["title"] = chart.title
    mc["meta"]["song"]["artist"] = chart.artist
    mc["meta"]["mode_ext"] = dict()
    mc["meta"]["mode_ext"]["column"] = chart.key_amount
    mc["meta"]["mode_ext"]["bar_begin"] = 0
    mc_time = []
    mc["time"] = mc_time
    previous_bpm_time = chart.bpms[0].time
    previous_beat = Beat()
    previous_bpm = chart.bpms[0].bpm
    mc_time.append(
        {
            "beat": [previous_beat.a, previous_beat.b, previous_beat.c],
            "bpm": previous_bpm,
        }
    )
    for bpm in chart.bpms[1:]:
        r_time = bpm.time - previous_bpm_time
        r_beat = Beat.from_time(r_time, 60000.0 / previous_bpm)
        previous_beat += r_beat
        previous_bpm = bpm.bpm
        previous_bpm_time = bpm.time
        mc_time.append(
            {
                "beat": [previous_beat.a, previous_beat.b, previous_beat.c],
                "bpm": previous_bpm,
            }
        )
    current_bpm_index = 0
    next_bpm_index = 1
    mc_effects = []
    mc["effect"] = mc_effects
    for effect in chart.effects:
        while next_bpm_index < len(chart.bpms):
            if chart.bpms[next_bpm_index].time > effect.time:
                break
            current_bpm_index += 1
            next_bpm_index += 1
        r_time = effect.time - chart.bpms[current_bpm_index].time
        r_beat = Beat.from_time(r_time, 60000.0 / mc_time[current_bpm_index]["bpm"])
        beat = Beat(*mc_time[current_bpm_index]["beat"])
        beat += r_beat
        mc_effect = {"beat": [beat.a, beat.b, beat.c], "scroll": effect.scroll}
        mc_effects.append(mc_effect)
    current_bpm_index = 0
    next_bpm_index = 1
    mc_note = []
    mc["note"] = mc_note
    for note in chart.notes:
        while next_bpm_index < len(chart.bpms):
            if chart.bpms[next_bpm_index].time > note.start:
                break
            next_bpm_index += 1
            current_bpm_index += 1
        r_time = note.start - chart.bpms[current_bpm_index].time
        r_beat = Beat.from_time(r_time, 60000.0 / mc_time[current_bpm_index]["bpm"])
        s_beat = Beat(*mc_time[current_bpm_index]["beat"])
        s_beat += r_beat
        new_note = {"beat": [s_beat.a, s_beat.b, s_beat.c], "column": note.column}
        if note.end > note.start:
            temp_current_bpm_index = current_bpm_index
            temp_next_bpm_index = next_bpm_index
            while temp_next_bpm_index < len(chart.bpms):
                if chart.bpms[temp_next_bpm_index].time > note.end:
                    break
                temp_next_bpm_index += 1
                temp_current_bpm_index += 1
            r_time = note.end - chart.bpms[temp_current_bpm_index].time
            r_beat = Beat.from_time(
                r_time, 60000.0 / mc_time[temp_current_bpm_index]["bpm"]
            )
            e_beat = Beat(*mc_time[temp_current_bpm_index]["beat"])
            e_beat += r_beat
            new_note["endbeat"] = [e_beat.a, e_beat.b, e_beat.c]
        if len(note.hitsound) > 0:
            new_note["sound"] = note.hitsound
            new_note["vol"] = note.volume
        mc_note.append(new_note)
    mc_note.append(
        {
            "beat": [0, 0, 1],
            "sound": chart.audio,
            "vol": 100,
            "offset": chart.bpms[0].time,
            "type": 1,
        }
    )
    mc["extra"] = {
        "test": {"divide": 4, "speed": 100, "save": 0, "lock": 0, "edit_mode": 0}
    }
    strs = json.dumps(mc, ensure_ascii=False, indent=4)
    file.write(strs)
    file.close()
예제 #7
0
    def play_music(self, name):
        beats = []
        combo_counter = 1
        score = 0
        beat_timer = 0
        with open(os.curdir + "/songs/" + name +
                  "/beat_list.txt") as soundtrack_delays:
            d = soundtrack_delays.readline()
            delays = list(d.split(", "))
        try:
            background_image = pygame.image.load(os.curdir + "/songs/" + name +
                                                 "/background_img.jpg")
        except FileNotFoundError:
            background_image = pygame.image.load(
                os.curdir + "/images/default_background_img.jpg")
        background_image = pygame.transform.scale(background_image,
                                                  (1080, 720))
        backboard_image = pygame.image.load(os.curdir +
                                            "/images/backboard.jpg")
        player_button = pygame.image.load(os.curdir +
                                          "/images/player_button.png")
        screen = pygame.Surface((1080, 720), pygame.SRCALPHA)
        screen.fill((0, 0, 0, 125))
        font = pygame.font.SysFont("None", 50)
        another_song_button = Button(
            390, 275,
            pygame.image.load(os.curdir + "/images/another_song_button.png"))
        restart_button = Button(
            390, 370,
            pygame.image.load(os.curdir + "/images/restart_button.png"))
        music_player = threading.Thread(target=music_function,
                                        daemon=True,
                                        args=(os.curdir + "/songs/" + name, ))
        music_player.start()
        run = True
        while run:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_SPACE:
                        if beats:
                            if 260 >= beats[0].x:
                                dis = math.sqrt(
                                    math.pow(200 - (beats[0].x + 45), 2) +
                                    math.pow(520 - (beats[0].y + 45), 2))
                                if dis <= 10:
                                    score += 100 * combo_counter
                                    combo_counter += 1
                                elif 25 >= dis > 10:
                                    score += 50 * combo_counter
                                    combo_counter += 1
                                elif 50 >= dis > 25:
                                    score += 25
                                    combo_counter = 1
                                beats.remove(beats[0])
                    if event.key == pygame.K_ESCAPE:
                        if self.paused:
                            self.paused = False
                            pygame.mixer.music.unpause()
                        else:
                            self.paused = True
                            pygame.mixer.music.pause()
                if not self.paused:
                    if event.type == pygame.USEREVENT + 1:
                        beat_timer += 10
                        if delays[0] != "end" and float(
                                delays[0]) * 1000 == beat_timer:
                            beats.append(Beat(1045, 475))
                            delays.pop(0)
                            beat_timer = 0
                        elif delays[0] == "end" and len(
                                beats
                        ) == 0 and not pygame.mixer.music.get_busy():
                            self.show_score(name, score, background_image)
                else:
                    if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                        if another_song_button.inside():
                            pygame.mixer.music.stop()
                            self.paused = False
                            self.music_selection()
                        elif restart_button:
                            self.paused = False
                            self.play_music(name)

            if self.paused:
                menu_screen = pygame.Surface((1080, 720), pygame.SRCALPHA)
                menu_screen.fill((0, 0, 0, 100))
                self.win.blit(menu_screen, (0, 0))
                another_song_button.draw(self.win)
                restart_button.draw(self.win)
                pygame.display.update()
                self.clock.tick(30)
            else:
                pygame.time.set_timer(pygame.USEREVENT + 1, 10)
                self.win.blit(background_image, (0, 0))
                self.win.blit(screen, (0, 0))
                self.win.blit(backboard_image, (0, 465))
                self.win.blit(player_button, (150, 470))
                for beat in beats:
                    beat.move(5)
                    if beat.x + 90 < 150:
                        combo_counter = 1
                        beats.remove(beat)
                    beat.draw(self.win)
                self.win.blit(font.render(str(score), True, (255, 255, 255)),
                              (1070 - len(str(score)) * 20, 10))
                self.win.blit(
                    font.render(str(combo_counter), True, (255, 255, 255)),
                    (10, 10))
                pygame.display.update()
                self.clock.tick(60)
예제 #8
0
pinList = [2, 3, 4, 17, 27, 22, 10, 9]

for i in pinList:
    GPIO.setup(i, GPIO.OUT)
    GPIO.output(i, GPIO.HIGH)

BEAT_WAIT = 0.687
pygame.mixer.init()
pygame.mixer.music.load('count-on-me.mp3')

try:

    pygame.mixer.music.play()

    # Starts background beat
    Beat(0).start()

    time.sleep(5.34)
    # Starts melody

    # if
    GPIO.output(17, GPIO.LOW)
    time.sleep(0.30)

    # you
    GPIO.output(27, GPIO.LOW)
    time.sleep(0.10)

    # e
    GPIO.output(22, GPIO.LOW)
    time.sleep(0.15)
예제 #9
0
    def run(self, screen, select):

        if Options.boyleft and Options.boyright:
            player = Brother1(300, 634, 1, 42, "boy.png")
            player2 = Brother1(310, 634, 1, 42, "girl2.png")
        elif Options.boyleft and Options.girlright:
            player = Brother1(300, 634, 1, 42, "boy.png")
            player2 = Brother1(310, 634, 1, 42, "girl.png")
        elif Options.girlleft and Options.boyright:
            player = Brother1(300, 634, 1, 42, "boy2.png")
            player2 = Brother1(310, 634, 1, 42, "girl2.png")
        elif Options.girlleft and Options.girlright:
            player = Brother1(300, 634, 1, 42, "boy2.png")
            player2 = Brother1(310, 634, 1, 42, "girl.png")

        level_list = [
            Level_01(player),
            Level_02(player),
            Level_03(player),
            Level_04(player)
        ]
        current_level = level_list[select]

        active_sprite_list = pygame.sprite.Group()
        player.level = current_level
        player2.level = current_level

        active_sprite_list.add(player)
        active_sprite_list.add(player2)

        End.end = True
        clock = pygame.time.Clock()

        healthpic = pygame.image.load("health.png")
        sorry = pygame.image.load("sorry.png")
        background = pygame.Surface(screen.get_size())
        background = background.convert()
        warning = pygame.image.load("warning.png")

        BLACK = (0, 0, 0)
        GREEN = (0, 255, 0)
        ORANGE = (255, 215, 0)
        RED = (255, 0, 0)
        clock = pygame.time.Clock()
        FPS = 24
        totalframes = 0

        if Options.soundon == True:
            pygame.mixer.music.load("super.ogg")
            pygame.mixer.music.play()

        if (select == 0):
            coinshift = 50
            coin2 = Coin(558, 573 + coinshift, 10, 10, "cookiecoin.png")
            coin3 = Coin(611, 540 + coinshift, 10, 10, "cookiecoin.png")
            coin4 = Coin(663, 523 + coinshift, 10, 10, "cookiecoin.png")
            coin5 = Coin(750, 514 + coinshift, 10, 10, "cookiecoin.png")
            coin6 = Coin(708, 518 + coinshift, 10, 10, "cookiecoin.png")
            coin7 = Coin(567, 460 + coinshift, 10, 10, "cookiecoin.png")
            coin8 = Coin(508, 460 + coinshift, 10, 10, "cookiecoin.png")
            coin9 = Coin(334, 451 + coinshift, 10, 10, "cookiecoin.png")
            coin10 = Coin(260, 451 + coinshift, 10, 10, "cookiecoin.png")
            coin11 = Coin(90, 360 + coinshift, 10, 10, "cookiecoin.png")
            coin12 = Coin(160, 360 + coinshift, 10, 10, "cookiecoin.png")
            coin13 = Coin(190, 280 + coinshift, 10, 10, "cookiecoin.png")
            coin14 = Coin(300, 270 + coinshift, 10, 10, "cookiecoin.png")
            coin15 = Coin(380, 270 + coinshift, 10, 10, "cookiecoin.png")
            coin17 = Coin(495, 187 + coinshift, 10, 10, "cookiecoin.png")
            coin18 = Coin(560, 187 + coinshift, 10, 10, "cookiecoin.png")
            coin19 = Coin(660, 240 + coinshift, 10, 10, "cookiecoin.png")
            coin20 = Coin(737, 240 + coinshift, 10, 10, "cookiecoin.png")

        if (select == 1):
            shift = 10
            shift_y = 30
            coin1 = Coin(289 - shift, 564 + shift_y + 30, 10, 10,
                         "cookiecoin.png")
            coin2 = Coin(30 - shift, 451 + shift_y, 10, 10, "cookiecoin.png")
            coin3 = Coin(391 - shift, 454 + shift_y, 10, 10, "cookiecoin.png")
            coin4 = Coin(399 - shift, 398 + shift_y, 10, 10, "cookiecoin.png")
            coin5 = Coin(661 - shift, 156 + shift_y, 10, 10, "cookiecoin.png")
            coin6 = Coin(689 - shift, 157 + shift_y, 10, 10, "cookiecoin.png")
            coin7 = Coin(713 - shift, 158 + shift_y, 10, 10, "cookiecoin.png")
            coin8 = Coin(745 - shift, 158 + shift_y, 10, 10, "cookiecoin.png")
            coin9 = Coin(775 - shift, 158 + shift_y, 10, 10, "cookiecoin.png")
            coin10 = Coin(297 - shift, 133 + shift_y + 90, 10, 10,
                          "cookiecoin.png")
            coin11 = Coin(332 - shift, 133 + shift_y + 90, 10, 10,
                          "cookiecoin.png")
            coin12 = Coin(261 - shift, 134 + shift_y + 90, 10, 10,
                          "cookiecoin.png")
            coin13 = Coin(564 - shift, 266 + shift_y, 10, 10, "cookiecoin.png")
            coin14 = Coin(604 - shift, 269 + shift_y, 10, 10, "cookiecoin.png")
            coin15 = Coin(88 - shift, 169 + shift_y + 30, 10, 10,
                          "cookiecoin.png")
            coin16 = Coin(151 - shift, 169 + shift_y + 30, 10, 10,
                          "cookiecoin.png")
            coin17 = Coin(73 - shift, 215 + shift_y + 30, 10, 10,
                          "cookiecoin.png")
            coin18 = Coin(92 - shift, 238 + shift_y + 30, 10, 10,
                          "cookiecoin.png")
            coin19 = Coin(119 - shift, 244 + shift_y + 30, 10, 10,
                          "cookiecoin.png")
            coin20 = Coin(156 - shift, 238 + shift_y + 30, 10, 10,
                          "cookiecoin.png")
            coin21 = Coin(182 - shift, 215 + shift_y + 30, 10, 10,
                          "cookiecoin.png")
            coin22 = Coin(800, 390, 10, 10, "cookiecoin.png")
            coin23 = Coin(850, 360, 10, 10, "cookiecoin.png")
            coin24 = Coin(900, 390, 10, 10, "cookiecoin.png")
            coin25 = Coin(950, 360, 10, 10, "cookiecoin.png")
            coin26 = Coin(1000, 390, 10, 10, "cookiecoin.png")
            coin27 = Coin(1050, 360, 10, 10, "cookiecoin.png")
            coin28 = Coin(250 + 200, 450, 10, 10, "cookiecoin.png")
            coin29 = Coin(300 + 200, 420, 10, 10, "cookiecoin.png")
            coin30 = Coin(350 + 200, 450, 10, 10, "cookiecoin.png")
            coin31 = Coin(400 + 200, 420, 10, 10, "cookiecoin.png")
            coin32 = Coin(450 + 200, 450, 10, 10, "cookiecoin.png")
            coin33 = Coin(700, 520, 10, 10, "cookiecoin.png")
            coin34 = Coin(750, 550, 10, 10, "cookiecoin.png")
            coin35 = Coin(900, 520, 10, 10, "cookiecoin.png")
            coin36 = Coin(950, 550, 10, 10, "cookiecoin.png")
            coin37 = Coin(1000, 520, 10, 10, "cookiecoin.png")
            coin38 = Coin(850, 550, 10, 10, "cookiecoin.png")
            coin39 = Coin(800, 520, 10, 10, "cookiecoin.png")

        if (select == 2):
            coin1 = Coin(0, 500, 10, 10, "cookiecoin.png")
            coin3 = Coin(170, 420, 10, 10, "cookiecoin.png")
            coin5 = Coin(340, 340, 10, 10, "cookiecoin.png")
            coin6 = Coin(425, 300, 10, 10, "cookiecoin.png")
            coin7 = Coin(510, 300, 10, 10, "cookiecoin.png")
            coin8 = Coin(595, 300, 10, 10, "cookiecoin.png")
            coin9 = Coin(680, 340, 10, 10, "cookiecoin.png")
            coin10 = Coin(765, 380, 10, 10, "cookiecoin.png")
            coin11 = Coin(850, 420, 10, 10, "cookiecoin.png")
            coin12 = Coin(935, 460, 10, 10, "cookiecoin.png")
            coin13 = Coin(1020, 500, 10, 10, "cookiecoin.png")
            coin14 = Coin(0, 300, 10, 10, "cookiecoin.png")
            coin15 = Coin(85, 340, 10, 10, "cookiecoin.png")
            coin16 = Coin(170, 360, 10, 10, "cookiecoin.png")
            coin18 = Coin(340, 420, 10, 10, "cookiecoin.png")
            coin19 = Coin(425, 460, 10, 10, "cookiecoin.png")
            coin20 = Coin(510, 500, 10, 10, "cookiecoin.png")
            coin21 = Coin(595, 500, 10, 10, "cookiecoin.png")
            coin22 = Coin(680, 460, 10, 10, "cookiecoin.png")
            coin23 = Coin(765, 420, 10, 10, "cookiecoin.png")
            coin25 = Coin(680, 150, 10, 10, "cookiecoin.png")
            coin26 = Coin(660, 150, 10, 10, "cookiecoin.png")
            coin27 = Coin(640, 150, 10, 10, "cookiecoin.png")
            coin28 = Coin(700, 150, 10, 10, "cookiecoin.png")
            coin29 = Coin(720, 150, 10, 10, "cookiecoin.png")
            coin30 = Coin(740, 150, 10, 10, "cookiecoin.png")
            coin31 = Coin(760, 150, 10, 10, "cookiecoin.png")
            coin32 = Coin(1032, 99, 10, 10, "cookiecoin.png")
            coin33 = Coin(311, 78, 10, 10, "cookiecoin.png")

        if (select == 3):
            coin1 = Coin(791, 496, 10, 10, "cookiecoin.png")
            coin2 = Coin(52, 295, 10, 10, "cookiecoin.png")
            coin3 = Coin(487, 202, 10, 10, "cookiecoin.png")
            coin4 = Coin(706, 145, 10, 10, "cookiecoin.png")
            coin5 = Coin(1015, 403, 10, 10, "cookiecoin.png")
            coin6 = Coin(220, 576, 10, 10, "cookiecoin.png")
            coin7 = Coin(526, 492, 10, 10, "cookiecoin.png")
            coin8 = Coin(285, 271, 10, 10, "cookiecoin.png")
            coin9 = Coin(930, 96, 10, 10, "cookiecoin.png")
            coin10 = Coin(987, 162, 10, 10, "cookiecoin.png")
            coin11 = Coin(987, 294, 10, 10, "cookiecoin.png")
            coin12 = Coin(930, 360, 10, 10, "cookiecoin.png")
            coin13 = Coin(1044, 228, 10, 10, "cookiecoin.png")
            coin14 = Coin(987, 228, 10, 10, "cookiecoin.png")
            coin15 = Coin(930, 228, 10, 10, "cookiecoin.png")
            coin16 = Coin(873, 228, 10, 10, "cookiecoin.png")
            coin17 = Coin(816, 228, 10, 10, "cookiecoin.png")

        pygame.time.wait(200)
        gravity = -.05
        count = 0
        while 1:

            dt = clock.tick(30)
            screen.blit(pygame.image.load("kitchen.png"), (0, 0))
            screen.blit(healthpic, (100, 8))

            pygame.draw.rect(screen, BLACK, (50, 50, 255, 40))
            if (Health.health > 150):
                pygame.draw.rect(screen, GREEN,
                                 (55, 55, Health.health - 5, 30))
            elif (Health.health > 50):
                pygame.draw.rect(screen, ORANGE,
                                 (55, 55, Health.health - 5, 30))
            else:
                pygame.draw.rect(screen, RED, (55, 55, Health.health - 5, 30))

            keys = pygame.key.get_pressed()
            for event in pygame.event.get():
                if Options.boyright:
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_a:
                            player2.go_left2(dt)
                        if event.key == pygame.K_d:
                            player2.go_right2(dt)
                elif Options.girlright:
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_a:
                            player2.go_left2(dt)
                        if event.key == pygame.K_d:
                            player2.go_right2(dt)
                if Options.boyleft:
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_LEFT:
                            player.go_left(dt)
                        if event.key == pygame.K_RIGHT:
                            player.go_right(dt)
                if Options.girlleft:
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_LEFT:
                            player.go_left(dt)
                        if event.key == pygame.K_RIGHT:
                            player.go_right(dt)
                if event.type == QUIT:
                    pygame.quit()
                if event.type == pygame.KEYUP:
                    if event.key == pygame.K_LEFT and player.change_x < 0:
                        player.stop()
                    if event.key == pygame.K_RIGHT and player.change_x > 0:
                        player.stop()
                if event.type == pygame.KEYUP:
                    if event.key == pygame.K_a and player2.change_x < 0:
                        player2.stop()
                    if event.key == pygame.K_d and player2.change_x > 0:
                        player2.stop()

            if keys[pygame.K_w] and keys[pygame.K_UP]:
                player.jump(dt)
                player2.jump(dt)

            if keys[pygame.K_u]:
                count = 1
                Coin.List = pygame.sprite.Group()

            if (player.rect.x <= 0):
                player.rect.x = 0
            if (player.rect.x >= 1116 - 50):
                player.rect.x = 1116 - 50
            if (player2.rect.x <= 0):
                player2.rect.x = 0
            if (player2.rect.x >= 1116 - 50):
                player2.rect.x = 1116 - 50

            active_sprite_list.update()
            current_level.draw(screen)
            active_sprite_list.draw(screen)

            totalframes += 1
            BaseClass.allsprites.draw(screen)

            process(player, player2, FPS, totalframes, 1, dt / 1000., select)
            Robot.movement()
            Robot.update_one()
            Vegetable.movement()
            Vegetable.update_two()
            player.update_all()
            player2.update_all()
            Coin.remove()
            if (abs(player.rect.x - player2.rect.x) > 200):
                screen.blit(warning, (400, 200))
                Health.health -= .20

            if Health.health <= 0:
                screen.blit(sorry, (300, 200))
                pygame.display.flip()
                pygame.time.wait(2000)
                BaseClass.allsprites = pygame.sprite.Group()
                Robot.List = pygame.sprite.Group()
                Brother1.List = pygame.sprite.Group()
                Vegetable.List = pygame.sprite.Group()
                Robot.update_one()
                Vegetable.update_two()
                return

            if keys[pygame.K_ESCAPE]:
                Coin.List = pygame.sprite.Group()
                BaseClass.allsprites = pygame.sprite.Group()
                Robot.List = pygame.sprite.Group()
                Brother1.List = pygame.sprite.Group()
                Vegetable.List = pygame.sprite.Group()
                Robot.update_one()
                Vegetable.update_two()
                pygame.display.update()
                return

            if len(Coin.List) == 0 or count == 1:
                screen.blit(greatjob, (180, 300))
                pygame.display.flip()
                pygame.time.wait(2000)
                BaseClass.allsprites = pygame.sprite.Group()
                Robot.List = pygame.sprite.Group()
                Brother1.List = pygame.sprite.Group()
                Vegetable.List = pygame.sprite.Group()
                Robot.update_one()
                Vegetable.update_two()
                pygame.display.update()
                if select == 0:
                    Beaten.level1 = True
                if select == 1:
                    Beaten.level2 = True
                if select == 2:
                    Beaten.level3 = True
                if select == 3:
                    Beaten.level4 = True
                if Beaten.level4:
                    Beat().run(screen)
                return

            pygame.display.flip()
예제 #10
0
파일: layer.py 프로젝트: FriendlyAI/rizumu
 def insert_beat(self, beat_time):
     self.beats.insert(0, Beat(beat_time))