def __init__(self): Scene.__init__(self, 'game1', 'orchestra_cat_idle.jpg') self.timer = Timer(990, 600, 80, True, 3) self.x = self.width / 6 self.y = self.height * 3 / 4 self.cursor = Cursor(256, 485, (5, 170), True) self.notes = [] self.click = False self.won = False self.cling_start = False self.red_position = -1 self.gen_notes() self.ding_background = pygame.image.load(os.path.join('assets', 'orchestra_cat_idle_ding.jpg')) self.ding_background = pygame.transform.scale(self.ding_background, pygame.display.get_surface().get_size()) self.dong_background = pygame.image.load(os.path.join('assets', 'orchestra_cat_idle_ding_elephant.jpg')) self.dong_background = pygame.transform.scale(self.dong_background, pygame.display.get_surface().get_size()) self.base_background = self.background self.cling_sound = pygame.mixer.Sound(os.path.join('assets', 'ding.wav')) self.clong_sound = pygame.mixer.Sound(os.path.join('assets', 'elephant.wav')) self.notes_pictures = { "black": pygame.transform.scale(pygame.image.load(os.path.join('assets', 'note_black.png')), (36, 80)), "red": pygame.transform.scale(pygame.image.load(os.path.join('assets', 'note_red.png')), (36, 80)), "yellow": pygame.transform.scale(pygame.image.load(os.path.join('assets', 'note_yellow.png')), (18, 40)) }
def update(self, mixer): Scene.update(self, mixer) if self.ticks <= 30: return True if not self.click: self.cursor.slide(randint(8, 20)) self.timer.update() if self.timer.is_over(): if self.won: self.transit('trans_win', 'game2', 45) else: self.transit('trans_lose', 'splash', 45) return True if not self.click: if pygame.mouse.get_pressed()[0]: self.click = True if abs(self.cursor.x - self.notes[self.red_position][0]) < 45: self.won = True self.cling_win() else: self.cling_lose()
def update(self, mixer): Scene.update(self, mixer) if self.start_button.is_clicked(): self.start('game0') if self.gallery.is_clicked(): self.start('gallery')
def __init__(self): Scene.__init__(self, 'splash', 'background_yellow.png') self.gallery = ButtonImage(100, 550, 'gallery.png', (108, 108), True) self.start_button = ButtonImage(self.width / 2 + 30, self.height * 0.6, 'start.png', (300, 200), True) self.title = pygame.image.load(os.path.join('assets', 'title.png')) self.title = pygame.transform.scale(self.title, pygame.display.get_surface().get_size())
def draw(self, win): Scene.draw(self, win) self.gauge.draw(win) self.timer.draw(win) win.blit( self.current_clap, self.current_clap.get_rect(center=(self.width / 2, self.height * 3 / 4)))
def reset(self): Scene.reset(self) self.timer.reset() self.cursor.reset() self.gen_notes() self.background = self.base_background self.click = False self.won = False self.cling_start = False
def __init__(self): Scene.__init__(self, 'gallery', 'menu_background.png') self.font_title = pygame.font.Font( os.path.join('assets', 'SigmarOne-Regular.ttf'), 80) self.font_back = pygame.font.Font( os.path.join('assets', 'SigmarOne-Regular.ttf'), 30) self.back = ButtonImage(100, 80, 'back.png', (130, 130), True) self.back_text = self.font_back.render("Back", True, (255, 255, 255)) self.title = self.font_title.render("Gallery", True, (255, 255, 255))
def __init__(self): Scene.__init__(self, 'game0', 'orchestra_dog.jpg') self.gauge = Gauge(100, self.height / 2, (50, 200), True, 5) self.timer = Timer(990, 600, 80, True, 3) self.click = False self.clap = pygame.image.load(os.path.join('assets', 'clap.png')) self.no_clap = pygame.image.load(os.path.join('assets', 'no_clap.png')) self.clap_sound = pygame.mixer.Sound(os.path.join( 'assets', 'clip.wav')) self.current_clap = self.no_clap
def draw(self, win): Scene.draw(self, win) self.timer.draw(win) self.cursor.draw(win) for i, note in enumerate(self.notes): if i == self.red_position: win.blit(self.notes_pictures["red"], self.notes_pictures["red"].get_rect(center=note)) else: win.blit(self.notes_pictures["black"], self.notes_pictures["black"].get_rect(center=note)) if self.cling_start: if self.cling_start <= self.ticks <= self.cling_start + 30: if self.won: self.background = self.ding_background else: self.background = self.dong_background win.blit(self.notes_pictures["yellow"], (380, 140)) else: self.background = self.base_background
def update(self, mixer): Scene.update(self, mixer) self.timer.update() self.gauge.decrease(0.1) if self.timer.is_over(): self.transit('trans_lose', 'splash', 45) return True if self.click: if not pygame.mouse.get_pressed()[0]: self.current_clap = self.no_clap self.click = False else: if pygame.mouse.get_pressed()[0]: self.gauge.increase(1.3) self.current_clap = self.clap self.clap_sound.play() self.click = True if self.gauge.is_full(): self.transit('trans_win', 'game1', 45)
def update(self, mixer): Scene.update(self, mixer) if self.back.is_clicked(): self.start('splash')
def draw(self, win): Scene.draw(self, win) self.back.draw(win) win.blit(self.back_text, self.back_text.get_rect(center=(100, 150))) win.blit(self.title, self.title.get_rect(center=(self.width / 2, 200)))
def draw(self, win): Scene.draw(self, win) win.blit(self.title, self.title.get_rect(center=(self.width/2, self.height/2))) self.gallery.draw(win) self.start_button.draw(win)
def reset(self): Scene.reset(self) self.gauge.reset() self.timer.reset()