def __init__(self, num_lanes, path, level, speed): Arbapp.__init__(self) self.num_lanes = num_lanes self.score = 0 self.speed = float(speed) self.rate = Rate(self.speed) self.grid = [['background']*num_lanes for h in range(self.height)] # The coming notes (last line included even if it will overwritten by the bottom bar) self.bar = ['idle']*num_lanes # The bottom bar, idle = not pressed, hit = pressed during a note, pressed = pressed outside a note # Threads creation and starting self.renderer = Renderer(self.model, self.grid, self.bar, self.height, num_lanes, self.width) self.reader = SongReader(path, num_lanes, level, speed) self.sound = SoundManager(path) self.hits = UserHits(self.num_lanes)
class LightsHero(Arbapp): def __init__(self, num_lanes, path, level, speed): Arbapp.__init__(self) self.num_lanes = num_lanes self.score = 0 self.speed = float(speed) self.rate = Rate(self.speed) self.grid = [['background']*num_lanes for h in range(self.height)] # The coming notes (last line included even if it will overwritten by the bottom bar) self.bar = ['idle']*num_lanes # The bottom bar, idle = not pressed, hit = pressed during a note, pressed = pressed outside a note # Threads creation and starting self.renderer = Renderer(self.model, self.grid, self.bar, self.height, num_lanes, self.width) self.reader = SongReader(path, num_lanes, level, speed) self.sound = SoundManager(path) self.hits = UserHits(self.num_lanes) def next_line(self): # Delete the last line leaving the grid # Note : The bottom bar will overwrite the last line but the latter needs to be kept to draw the bottom bar for l in range(self.height-1, 0, -1): for w in range(self.num_lanes): self.grid[l][w] = self.grid[l-1][w] # Ask for a new line to the song reader and fill the top of the grid with it new_line = self.reader.read() for lane in range(self.num_lanes): self.grid[0][lane] = new_line[lane] def process_user_hits(self): """ Read user inputs, update the bottom bar with key states and warn the UserHits class to update the score """ for lane in range(self.num_lanes): must_press = self.grid[self.height-1][lane] == 'active' or self.grid[self.height-1][lane] == 'bump' pressed = self.hits.get_pressed_keys()[lane] if must_press and pressed: status = 'hit' elif pressed: status = 'pressed' else: status = 'idle' self.bar[lane] = status # warn the user hits class whether the note has to be played self.hits.set_note(lane, self.grid[self.height-1][lane] in ['bump', 'active']) def display_score(self): levels = [15, 40, 60, 80, 90, 101] sentences = ["did you really play?", "you need to practice...", "I'm pretty sure you can do better...", "that's a fair score!", "awesome, you're a master!", "incredible, did you cheat?"] colors = ['darkred', 'orange', 'gold', 'yellowgreen', 'green', 'white'] score = int((100.*self.hits.score)/self.hits.max_score) for i, level in enumerate(levels): if score<level: sentence = sentences[i] color = colors[i] break print "You scored", score, '% with', self.hits.score, 'hits over', self.hits.max_score if self.hits.score>0: self.model.write("You scored {}%, {}".format(score, sentence), color) def run(self): countdown = self.height # Countdown triggered after Midi's EOF start = time() # We loop while the end countdown is not timed out # it starts decreasing only when EOF is returned by the song reader while countdown>0: self.next_line() self.process_user_hits() self.renderer.update_view() if self.reader.eof: countdown -= 1 # delayed sound playing while the first notes are reaching the bottom bar if not self.sound.started and time()-start > (self.height-2)/self.speed: self.sound.start() self.rate.sleep() self.display_score()
class LightsHero(Arbapp): def __init__(self, num_lanes, path, level, speed): Arbapp.__init__(self) self.num_lanes = num_lanes self.score = 0 self.speed = float(speed) self.rate = Rate(self.speed) self.grid = [['background']*num_lanes for h in range(self.height)] # The coming notes (last line included even if it will overwritten by the bottom bar) self.bar = ['idle']*num_lanes # The bottom bar, idle = not pressed, hit = pressed during a note, pressed = pressed outside a note # Threads creation and starting self.renderer = Renderer(self.model, self.grid, self.bar, self.height, num_lanes, self.width) self.reader = SongReader(path, num_lanes, level, speed) self.sound = SoundManager(path) self.hits = UserHits(self.num_lanes) def next_line(self): # Delete the last line leaving the grid # Note : The bottom bar will overwrite the last line but the latter needs to be kept to draw the bottom bar for l in range(self.height-1, 0, -1): for w in range(self.num_lanes): self.grid[l][w] = self.grid[l-1][w] # Ask for a new line to the song reader and fill the top of the grid with it new_line = self.reader.read() for lane in range(self.num_lanes): self.grid[0][lane] = new_line[lane] def process_user_hits(self): """ Read user inputs, update the bottom bar with key states and warn the UserHits class to update the score """ for lane in range(self.num_lanes): must_press = self.grid[self.height-1][lane] == 'active' or self.grid[self.height-1][lane] == 'bump' pressed = self.hits.get_pressed_keys()[lane] if must_press and pressed: status = 'hit' elif pressed: status = 'pressed' else: status = 'idle' self.bar[lane] = status # warn the user hits class whether the note has to be played self.hits.set_note(lane, self.grid[self.height-1][lane] in ['bump', 'active']) def run(self): countdown = self.height # Countdown triggered after Midi's EOF start = time() # We loop while the end countdown is not timed out # it starts decreasing only when EOF is returned by the song reader while countdown>0: self.next_line() self.process_user_hits() self.renderer.update_view() if self.reader.eof: countdown -= 1 # delayed sound playing while the first notes are reaching the bottom bar if not self.sound.started and time()-start > (self.height-2)/self.speed: self.sound.start() self.rate.sleep() print "You scored", int((100.*self.hits.score)/self.hits.max_score), '% with', self.hits.score, 'hits over', self.hits.max_score