def __init__(self, size, pos, beat_idx, instrument_idx, topleft, beats): super().__init__(size, pos) self.beat_id = beat_idx self.instrument_id = instrument_idx self.instrument_pitch = instruments[instrument_idx] self.beats = beats self.beat_on = False self.beat_note = Note(480, self.instrument_pitch) self.topleft = topleft self.relative_pos = (beat_idx, instrument_idx) self.set_color(color=Tile.base_color, source="./data/button_down.png")
def play_current(self, string_idx): fret_pos = self.current_frets[string_idx] pitch = self.string_pitches[string_idx][fret_pos - 1] note = Note(480, pitch) self.audio.set_notes([note]) self.audio.note_seq.start_now() correct_string = string_idx == len(self.played_strings) correct_fret = self.current_frets[string_idx] == self.actual_frets[ string_idx] if correct_string and correct_fret: self.played_strings.append(string_idx) else: self.played_strings = []
def __init__(self, prev_room, level=0, on_finished_puzzle=None): super().__init__() self.door_sources = { (4, 9): "./data/Door_up.png", # UP (4, -1): "./data/door_down.png", # DOWN (-1, 4): "./data/door_left.png", # LEFT (9, 4): "./data/Door_right.png", # RIGHT } self.prev_room = prev_room self.on_finished_puzzle = on_finished_puzzle self.animations = AnimGroup() self.level = level self.notes, self.actual_key = levels[level] duration = choice(durations) pitch_shift = choice(range(-3, 4)) self.user_notes = [ Note(duration, n.get_pitch() + pitch_shift) for n in self.notes ] render_user_notes = self.level < 2 self.actual_sound = PuzzleSound(self.notes) self.user_sound = PuzzleSound(self.user_notes) self.music_bar = MusicBar(self.notes, self.user_notes, render_user_notes, self.actual_sound) self.animations.add(self.music_bar) self.add(self.animations) self.user_key = "C" self.place_objects() self.key_label = CLabelRect( (Window.width // 30, 23 * Window.height // 32), f"Key: {self.user_key}", 34) self.add(Color(rgba=(1, 1, 1, 1))) self.add(self.key_label) self.create_instructions((Window.width, Window.height)) self.add(self.instructions_text_color) self.add(self.instructions_text) self.objects = {}
def __init__(self, prev_room=None, level=0, on_finished_puzzle=None): super().__init__() self.door_sources = { (4, 9): "./data/Door_up.png", # UP (4, -1): "./data/door_down.png", # DOWN (-1, 4): "./data/door_left.png", # LEFT (9, 4): "./data/Door_right.png", # RIGHT } self.prev_room = prev_room self.next_room = None self.level = level self.on_finished_puzzle = on_finished_puzzle self.note_index = 1 self.cpu_turn = True self.user_sequence = [] self.correct_sequence = levels[level] self.mummy_source = sources[level] self.colors = [ Color(rgb=(0, 1, 0)), # Green Color(rgb=(1, 0, 0)), # Red Color(rgb=(1, 1, 0)), # Yellow Color(rgb=(0, 0, 1)), # Blue Color(rgb=(1, 165 / 255, 0)), # Orange ] # Setup audio self.notes = [Note(480, p) for p in (60, 64, 67, 72, 74)] self.audio = PuzzleSound(self.notes, preset=24, simon_says=True) self.tile_size = (self.grid.tile_side_len, self.grid.tile_side_len) self.create_objects() self.place_objects()
class SequencerTile(Tile): active_color = Color(rgba=(0, 1, 0, 1)) inactive_color = Color(rgba=(0, 0.4, 0, 1)) rest = Note(480, 0) def __init__(self, size, pos, beat_idx, instrument_idx, topleft, beats): super().__init__(size, pos) self.beat_id = beat_idx self.instrument_id = instrument_idx self.instrument_pitch = instruments[instrument_idx] self.beats = beats self.beat_on = False self.beat_note = Note(480, self.instrument_pitch) self.topleft = topleft self.relative_pos = (beat_idx, instrument_idx) self.set_color(color=Tile.base_color, source="./data/button_down.png") def on_button_press(self): # toggle audio mapped to it # toggle tile appearance self.toggle() def toggle(self): # flip tile, toggle audio if self.beat_on: self.set_beats(rest=True) self.set_color( color=SequencerTile.base_color, source="./data/button_down.png" ) else: self.set_beats(rest=False) self.set_color(SequencerTile.base_color, source="./data/button_up.png") self.beat_on = not self.beat_on def turn_off(self): self.set_beats(rest=True) self.set_color(color=SequencerTile.base_color, source="./data/button_down.png") self.beat_on = False def set_beats(self, rest=True): for i in range(len(self.beats)): for j in range(len(self.beats)): if self.beat_id % 4 == i and self.instrument_id == j: self.beats[i][j] = SequencerTile.rest if rest else self.beat_note def toggle_neighbors(self, objects, sequencer_size): x, y = self.relative_pos x_left = None if x == 0 else x - 1 x_right = None if x == sequencer_size - 1 else x + 1 y_down = None if y == sequencer_size - 1 else y + 1 y_up = None if y == 0 else y - 1 coords = [(x_left, y), (x_right, y), (x, y_up), (x, y_down)] coords = [ (self.topleft[0] + coord[0], self.topleft[1] - coord[1]) for coord in coords if None not in coord ] for coord in coords: if coord in objects: objects[coord].toggle()
from src.puzzle import Puzzle # make audio loop so notes change in real time # map a 4 x 4 grid x axis is beat and y axis is instrument (hi-hat, bass drum, etc.) # no concept of actual sound levels = { 0: [" X ", "XXX ", " X ", " "], 1: ["XX ", "X X", " XX", " X"], 2: [" XX", " X ", "X X", "X XX"], 3: ["X X", " XX ", "XX ", " X "], } # hi-hat, snare, bass drum, tambourine instruments = [42, 38, 36, 54] all_rests = [[Note(480, 0) for i in instruments] for _ in range(8)] # character knows which tile its on # receive tile, toggle that tile and the surrounding ones class DrumsPuzzle(Puzzle): def __init__(self, prev_room, level=0, on_finished_puzzle=None): super().__init__() self.door_sources = { (4, 9): "./data/Door_up.png", # UP (4, -1): "./data/door_down.png", # DOWN (-1, 4): "./data/door_left.png", # LEFT (9, 4): "./data/Door_right.png", # RIGHT }
def update_pitch(self, fret_pos=0): self.note = Note(480, self.pitches[fret_pos])
def play_actual(self, string_idx): fret_pos = self.actual_frets[string_idx] pitch = self.string_pitches[string_idx][fret_pos - 1] note = Note(480, pitch) self.audio.set_notes([note]) self.audio.note_seq.start_now()
Rectangle, Translate, ) from kivy.graphics.instructions import InstructionGroup from src.button import Button from common.gfxutil import AnimGroup, CLabelRect, KFAnim, CRectangle from src.grid import DoorTile, Switch, Tile from src.puzzle_sound import Note, PuzzleSound from src.puzzle import Puzzle levels = { 0: [ ( Note(480, 62), Note(480, 64), Note(480, 65), Note(480, 67), Note(480, 69), Note(480, 71), Note(480, 72), Note(480, 74), ), "C", ], 1: [ ( Note(240, 74), Note(240, 73), Note(240, 70),