From 719d9a9fe499fcaeeac066ce00bf75e267016a26 Mon Sep 17 00:00:00 2001 From: pjxkry3oe <274867911@qq.com> Date: Sun, 2 Jun 2024 17:07:25 +0800 Subject: [PATCH] ADD file via upload --- study.py | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 study.py diff --git a/study.py b/study.py new file mode 100644 index 0000000..cee564e --- /dev/null +++ b/study.py @@ -0,0 +1,108 @@ +import pygame +import random + +pygame.mixer.init() +pygame.init() +username_input = pygame_textinput.TextInput() +password_input = pygame_textinput.TextInput(password=True) + +screen = pygame.display.set_mode((800, 600)) +font = pygame.font.Font(None, 36) +login_button = {'rect': pygame.Rect(350, 400, 100, 50), 'text': 'Login'} +username = "" +password = "" + +while True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + sys.exit() + if event.type == pygame.MOUSEBUTTONDOWN: + mx, my = event.pos + if login_button['rect'].collidepoint(mx, my): + if username_input.get_text() == "admin" and password_input.get_text() == "123": + print("Login successful!") + else: + print("Login failed!") + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_RETURN: + username = username_input.get_text() + password = password_input.get_text() + + screen.fill((255, 255, 255)) + username_input.update(event) + screen.blit(username_input.get_surface(), (350, 250)) + password_input.update(event) + screen.blit(password_input.get_surface(), (350, 300)) + pygame.draw.rect(screen, (0, 255, 0), login_button['rect']) + text = font.render(login_button['text'], True, (255, 255, 255)) + screen.blit(text, (login_button['rect'].x + 10, login_button['rect'].y + 10)) + + pygame.display.update() +screen_width = 900 +screen_height = 600 +screen = pygame.display.set_mode((screen_width, screen_height)) + +se_fly = pygame.mixer.Sound('./fb_music/fly.wav') +se_crash = pygame.mixer.Sound('./fb_music/crash.wav') +font = pygame.font.Font("./fonts/msyhbd.ttf", 24) + +img_title = pygame.image.load('./fb_img/title.png') + +img_bg = pygame.image.load('./fb_img/baibg.png') +bg_start = 0 +bg_speed = 1 +game_bg = { + 'start': 0, + 'speed': 1 +} + +img_pipe = pygame.image.load('./fb_img/pipe.png') +pipe_width = 50 +pipe_height = 600 +pipe_speed = 2 +# space_up_down = 150 +space_front_back = pipe_speed * 110 + +max_top = -pipe_height + 70 +min_top = -pipe_height + screen_height // 2 + 30 +pipe_list = [] + +# -------- goodtimp start --------- +pX +pY +score +gold_list = [] +gold_width = 30 +gold_height = 30 + +max_gold_count = 3 +min_space = 100 +prop = 100 +max_gold_score = 3 + +img_gold = pygame.image.load('./fb_img/gold_medal.png') +img_gold = pygame.transform.scale(img_gold, (gold_width, gold_height)) +img_silver = pygame.image.load('./fb_img/silver_medal.png') +img_silver = pygame.transform.scale(img_silver, (gold_width, gold_height)) +# -------- goodtimp end ---------- + +begin = pygame.image.load('./fb_img/start.png') +pause = pygame.image.load('./fb_img/pause.png') + +if event.type == pygame.MOUSEBUTTONDOWN: + mx, my = event.pos + if begin_button['px'] == 20 and bt_crash(mx, my): + begin_button['state'] = not begin_button['state'] + bt_pause() + + m1, m2, m3 = pygame.mouse.get_pressed() +mx, my = pygame.mouse.get_pos() +if m1: + if bt_crash(mx, my) and begin_button['px'] == 400: +game_run['begin'] = True +if bt_crash(mx, my) and begin_button['px'] == 400 and game_run['isOver'] is True: + begin_button['again'] = True + if m3: +game_init() +pygame.display.update()