def __init__(self, count_combo, score, marks, accuracy, map): self.result = -1 self.count_combo = str(count_combo) + 'x' self.score = str(score) self.marks = [str(i) + 'x' for i in marks.values()] if accuracy == 100: self.rank = load_image('skin/rank_SS.png') elif accuracy > 95: self.rank = load_image('skin/rank_S.png') elif accuracy > 90: self.rank = load_image('skin/rank_A.png') elif accuracy > 80: self.rank = load_image('skin/rank_B.png') elif accuracy > 70: self.rank = load_image('skin/rank_C.png') else: self.rank = load_image('skin/rank_D.png') self.accuracy = str('%.2f' % accuracy) + '%' self.back_btn = Button(-30, 630, 236, 92, '', back_button_image, self.back) self.restart_btn = Button(908, 630, 236, 92, '', restart_button_image, self.restart) map_id = map[2].map_id mapset_id = map[2].mapset_id time = str(dt.datetime.now().time()).split('.')[0] date = str(dt.datetime.now().date()) con = sqlite3.connect('records.db') cur = con.cursor() cur.execute( f"INSERT INTO Records(map_id, mapset_id, score, accuracy, combo, date, time) VALUES({map_id}, {mapset_id}, {score}, {accuracy}, {count_combo}, '{date}', '{time}')") con.commit()
def select_character(): # меню выбора персонажа global closed if closed: return screen = CharacterMenu() game = True res = -1 while not transition.get_transition(): # отображение перехода for event in pygame.event.get(): if event.type == pygame.QUIT: closed = True return transition.render() pygame.display.flip() clock.tick(fps) screen.render() while game: for event in pygame.event.get(): if event.type == pygame.QUIT: closed = True game = False if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: x, y = event.pos # обработка смен персонажа if 200 < x < 300 and 310 < y < 410: screen.switch_chr(-1) elif 820 < x < 920 and 310 < y < 410: screen.switch_chr(1) if transition.get_transition(): # отображение перехода if not transition.background: pygame.image.save(display, 'image/background_for_load.png') transition.background = load_image('background_for_load.png') transition.render() else: screen.render() pygame.display.flip() res = screen.get_result() if res != -1: game = False if res == 0: # возвращение к экрану select_map frame = transition.get_frame() if frame != 35 and frame != -1: transition.reverse() transition.background = None select_map()
def start_menu(): global closed if closed: return # функция для создания, отрисовки стартового меню screen = StartMenu() game = True res = -1 # переменная, возвращающая состояние экрана while not transition.get_transition(): # отображение перехода между меню for event in pygame.event.get(): if event.type == pygame.QUIT: closed = True return transition.render() pygame.display.flip() clock.tick(fps) screen.render() while game: for event in pygame.event.get(): if event.type == pygame.QUIT: game = False closed = True if event.type == pygame.KEYDOWN: keys = pygame.key.get_pressed() if keys[pygame.K_SPACE] or keys[ pygame.K_RETURN]: # переход в меню выбора карт screen.result = 1 pygame.mixer.music.stop() if transition.get_transition(): # отображение перехода между меню if not transition.background: # сохранение изображения на экране для быстрой отрисовки pygame.image.save(display, 'image/background_for_load.png') transition.background = load_image('background_for_load.png') transition.render() else: screen.render() pygame.display.flip() clock.tick(fps) res = screen.get_result() if res != -1: game = False if res == 1: frame = transition.get_frame() # смена состояния перехода if frame != 35 and frame != -1: transition.reverse() transition.background = None select_map()
def result_game(count_combo, score, marks, accuracy, map): # экран с результатом игры global closed if closed: return screen = ResultScreen(count_combo, score, marks, accuracy, map) game = True transition.frame = -1 transition.transition_back = False while not transition.get_transition(): # отрисовка перехода for event in pygame.event.get(): if event.type == pygame.QUIT: closed = True return transition.render() pygame.display.flip() clock.tick(fps) screen.render() while game: for event in pygame.event.get(): if event.type == pygame.QUIT: closed = True game = False if transition.get_transition(): # отрисовка перехода if not transition.background: pygame.image.save(display, 'image/background_for_load.png') transition.background = load_image('background_for_load.png') transition.render() else: screen.render() pygame.display.flip() clock.tick(fps) res = screen.get_result() if res == 0: # переход к меню выбора карт game = False frame = transition.get_frame() if frame != 35 and frame != -1: transition.reverse() transition.background = None select_map() if res == 1: game = False play_map(map)
def settings(): # функция для отрисовки, создания меню настроек global closed if closed: return screen = Settings() game = True while not transition.get_transition(): # отображение перехода for event in pygame.event.get(): if event.type == pygame.QUIT: closed = True return transition.render() pygame.display.flip() clock.tick(fps) screen.render() while game: for event in pygame.event.get(): if event.type == pygame.QUIT: closed = True return if transition.get_transition(): # отображение перехода if not transition.background: pygame.image.save(display, 'image/background_for_load.png') transition.background = load_image('background_for_load.png') transition.render() else: screen.render() pygame.display.flip() clock.tick(fps) res = screen.get_result() if res != -1: game = False if res == 0: # возврат в функцию select_map frame = transition.get_frame() if frame != 35 and frame != -1: transition.reverse() transition.background = None return
def pause(objects, background): # экран паузы global closed if closed: return screen = PauseMenu(objects, background) game = True timer = False timer_image = [load_image(f'timer_{i}.png') for i in range(1, 4)] while game: for event in pygame.event.get(): if event.type == pygame.QUIT: closed = True return -2 if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: return pause(objects, background) if timer: screen.render_map() time_after_pause = (pygame.time.get_ticks() - time_in_pause) / 1000 if time_after_pause < 3: display.blit(timer_image[-1 * (int(time_after_pause) + 1)], (600, 295)) else: game = False timer = False else: screen.render_pause() pygame.display.flip() clock.tick(fps) res = screen.get_result() if res == 0: if not timer: timer = True time_in_pause = pygame.time.get_ticks() elif res != -1: game = False return res
import pygame from GameParameter import display from GameEffects import load_image from Button import Button st_x = 350 background_image = load_image('pause_background.png') continue_button_image = (load_image('pause_continue_0.png'), load_image('pause_continue_1.png')) restart_button_image = (load_image('pause_restart_0.png'), load_image('pause_restart_1.png')) back_button_image = (load_image('pause_back_0.png'), load_image('pause_back_1.png')) class PauseMenu: def __init__(self, map_objects, map_background): self.result = -1 # переменная для отслеживания состояния экрана self.map_keys = map_objects[0] # изображения клавиш self.map_objects = map_objects[1:] # изображений нот self.map_background = map_background # изображений заднего фона self.map_background.set_alpha(100) self.continue_btn = Button(455, 200, 238, 72, '', continue_button_image, self.continue_map) self.restart_btn = Button(455, 350, 238, 72, '', restart_button_image, self.restart)
import pygame import sqlite3 from GameParameter import display, fps from Button import Button from GameEffects import drawing_text, load_image from Settings import load_settings exit_button_image = [load_image(f'menu_back_{i}.png') for i in range(2)] chr_button_image = [load_image(f'chr_button_{i}.png') for i in range(2)] play_button_image = (load_image('play_button_0.png'), load_image('play_button_1.png')) settings_button_image = [ load_image(f'settings_button_{i}.png') for i in range(2) ] song_rect = load_image('select_menu_rect.png') song_rect_active = load_image('select_menu_rect_active.png') menu_back_plus = load_image('menu_back+.png') menu_plus = load_image('menu+.png') back_mask = load_image('back_mask.png') records_rect = load_image('record_rect.png') settings_values = load_settings() glow_left = load_image('glow_left.png') glow_right = load_image('glow_right.png') shift_v = 300 class SelectMenu: def __init__(self, maps): settings_values = load_settings() self.result = -1 # переменная для отслеживания состояния экрана
from GameParameter import display from GameEffects import drawing_text, load_image from Button import Button import sqlite3 import datetime as dt background = load_image('result_background.png') back_button_image = [load_image(f'pause_back_{i}.png') for i in range(2)] restart_button_image = [load_image(f'pause_restart_{i}.png') for i in range(2)] miss = load_image('skin/hit0.png') bad = load_image('skin/hit50.png') good = load_image('skin/hit100.png') great = load_image('skin/hit200.png') perfect = load_image('skin/hit300.png') marvelous = load_image('skin/hit300g.png') class ResultScreen: def __init__(self, count_combo, score, marks, accuracy, map): self.result = -1 self.count_combo = str(count_combo) + 'x' self.score = str(score) self.marks = [str(i) + 'x' for i in marks.values()] if accuracy == 100: self.rank = load_image('skin/rank_SS.png') elif accuracy > 95: self.rank = load_image('skin/rank_S.png') elif accuracy > 90:
import pygame import math from GameParameter import clock, fps, display from GameEffects import drawing_text, load_image, AnimatedSprite from Settings import load_settings # загрузка изображений клавиш(без 'd' на конце - клавиши на 1 и 4 линиях, с 'd' - клавиши на 2 и 3) key0_image = load_image('skin/key0.png') # клавиши с предпиской '0' - не нажатая клавиша key1_image = load_image('skin/key1.png') # клавиши с предпиской '1' - нажатая клавиша key0d_image = load_image('skin/key0d.png') key1d_image = load_image('skin/key1d.png') # загрузка изображений одиночных(без 's' на конце) и длинных(с 's' на конце) нот note0_image = load_image('skin/note0.png') # ноты с предпиской '0' появляются на 1 и 4 линиях note0s_image = load_image('skin/note0s.png') # ноты с предпиской '1' появляются на 2 и 3 линиях note1_image = load_image('skin/note1.png') note1s_image = load_image('skin/note1s.png') # загрузка изображений игрового поля stage_image = load_image('skin/stage.png') stage_light_image = load_image('skin/stage_light.png') lightning_image = load_image('skin/lighting.png') # изображение вспышки при уничтожение ноты # загрузка изображений оценок hit0 = load_image('skin/hit0.png') # оценка - Miss hit50 = load_image('skin/hit50.png') # оценка - Bad hit100 = load_image('skin/hit100.png') # оценка - Good hit200 = load_image('skin/hit200.png') # оценка - Great hit300 = load_image('skin/hit300.png') # оценка - Perfect hit301 = load_image('skin/hit300g.png') # оценка - Marvelous
import pygame from GameParameter import display from GameEffects import drawing_text, load_image from Button import Button # загрузка изображений background = load_image('menu_background.png') exit_button_image = [load_image(f'menu_back_{i}.png') for i in range(2)] changer_btn_up_image = [ load_image(f'changer_button_up_{i}.png') for i in range(2) ] changer_btn_down_image = [ load_image(f'changer_button_down_{i}.png') for i in range(2) ] music_volume_image = load_image( 'music_volume_text.png') # изображение надписи 'music volume' scroll_speed_image = load_image( 'scroll_speed_text.png') # изображение надписи 'scroll speed' confirm_btn_image = [load_image(f'confirm_btn_{i}.png') for i in range(2)] def load_settings(): # функия получения настроек пользователя settings = {} with open('user_settings.txt') as file: for elem in file: name, value = elem[:elem.find(':')], elem[elem.find(':') + 1:] settings[name] = value.rstrip() # если пользователь удалил настройку из файла, то оно заменяется стандартным if 'music_volume' not in settings: settings['music_volume'] = 100 if 'scroll_speed' not in settings:
' уничтожены и дадут оценку "Great" '), ('Во время игры, комбо не будет сбрасываться,', 'если вы пропустили ноту и комбо меньше 100'), ('Во ремя игры заряжается способность. При', 'её активации на некоторое время все оценки', ' "Great" и "Good" станут "Perfect"'), ('Во время игры, все оценки, кроме "Perfect" ', 'и "Marvelous", сбивают вам комбо, но оценки', ' дают на 50% больше очков')) # музыкальные темы персонажей character_theme = ('flandre_theme.mp3', 'marisa_theme.mp3', 'reimu_theme.mp3', 'remilia_theme.mp3', 'sakuya_theme.mp3') # загрузка изоюражений left_button_image = (load_image('left_button_0.png'), load_image('left_button_1.png')) right_button_image = (load_image('right_button_0.png'), load_image('right_button_1.png')) confirm_button_image = (load_image('confirm_btn_0.png'), load_image('confirm_btn_1.png')) exit_button_image = [load_image(f'menu_back_{i}.png') for i in range(2)] menu_background = [ load_image('menu_background.png'), load_image('menu_back+.png'), load_image('menu+.png') ] # загрузка настроек пользователя settings_values = load_settings()
def select_map(): # функция отрисовки, создания меню выбора карт global closed if closed: return scrolling_v = 0 # скорость, с которой движутся карты scrolling_a = -10000 # ускорение, с которым движутся карты screen = SelectMenu(maps) max_y = max(screen.maps, key=lambda x: x[1])[1] min_y = min(screen.maps, key=lambda x: x[1])[1] game = True res = -1 while not transition.get_transition(): # отображение перехода for event in pygame.event.get(): if event.type == pygame.QUIT: closed = True return transition.render() pygame.display.flip() clock.tick(fps) screen.render() while game: for event in pygame.event.get(): if event.type == pygame.QUIT: game = False closed = True if event.type == pygame.MOUSEBUTTONDOWN: # прокрутка меню if event.button == 4: scrolling_v += 600 elif event.button == 5: scrolling_v -= 600 elif event.button == 1: screen.render() if scrolling_v != 0: for i, elem in enumerate(screen.maps): if scrolling_v > 0: if min_y > 100: scrolling_v = 0 continue if scrolling_v < 0: if max_y < 530: scrolling_v = 0 continue maps[i][1] += int(scrolling_v / fps_menu) # перемещение карт на экране max_y += int(scrolling_v / fps_menu) min_y += int(scrolling_v / fps_menu) # изменение скорости движения карт if scrolling_v < 0: scrolling_v -= scrolling_a / fps_menu scrolling_v = min(0, scrolling_v) if scrolling_v > 0: scrolling_v += scrolling_a / fps_menu scrolling_v = max(0, scrolling_v) if transition.get_transition(): # отображение перехода if not transition.background: pygame.image.save(display, 'image/background_for_load.png') transition.background = load_image('background_for_load.png') transition.render() else: screen.render() pygame.display.flip() clock.tick(fps) res = screen.get_result() if res != -1: game = False if res == 1: # переход в стартовое меню frame = transition.get_frame() if frame != 35 and frame != -1: transition.reverse() transition.background = None start_menu() elif res == 2: # переход в меню выбора персонажа frame = transition.get_frame() if frame != 35 and frame != -1: transition.reverse() transition.background = None select_character() elif res == 3: # переход к игре map = screen.get_map() play_map(map) elif res == 4: # переход к настройкам frame = transition.get_frame() if frame != 35 and frame != -1: transition.reverse() transition.background = None settings() select_map()
if not transition.background: pygame.image.save(display, 'image/background_for_load.png') transition.background = load_image('background_for_load.png') transition.render() else: screen.render() pygame.display.flip() clock.tick(fps) res = screen.get_result() if res == 0: # переход к меню выбора карт game = False frame = transition.get_frame() if frame != 35 and frame != -1: transition.reverse() transition.background = None select_map() if res == 1: game = False play_map(map) if __name__ == '__main__': pygame.init() pygame.display.set_caption('リズム') pygame.display.set_icon(load_image("icon.ico")) transition = AnimationTransition() size = width, height = 1120, 720 display = pygame.display.set_mode(size) start_menu() pygame.quit()