From a604dc3b7c34406bce07b7b89b2225b58132d906 Mon Sep 17 00:00:00 2001 From: zhiyuan <2672347597@qq.com> Date: Sat, 25 Jul 2026 23:50:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=98=E5=88=B6=E7=9F=A9=E5=BD=A2=E5=B9=B6?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=B8=8A=E4=B8=8B=E5=B7=A6=E5=8F=B3wasd?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=B9=B6=E9=99=90=E5=88=B6=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- page/page.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 page/page.py diff --git a/page/page.py b/page/page.py new file mode 100644 index 0000000..8237992 --- /dev/null +++ b/page/page.py @@ -0,0 +1,76 @@ +# -*-coding:utf-8 -*- # +# --------------------------------------------------------------------------- +# ProjectName: Game_project +# FileName: page.py +# Author: Zhi_yuan +# Datetime: 2026/7/25 下午10:44 +# Description: +# --------------------------------------------------------------------------- +import pygame + +# 初始化pygame +pygame.init() + +# 设置窗口大小 +size = (800, 600) +screen = pygame.display.set_mode(size) + +# 窗口名称 +pygame.display.set_caption("New_game") + +# 状态值 +dirty_x = 400 +dirty_y = 300 + +Left_status = False +right_status = False +up_status = False +down_status = False + +# 颜色 +WHITE = (255, 255, 255) +RED = (255, 0, 0) +BLUE = (0, 0, 255) +# 游戏循环 +running = True +while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + # 按下按键 + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT or event.key == pygame.K_a: + Left_status = True + elif event.key == pygame.K_RIGHT or event.key == pygame.K_d: + right_status = True + elif event.key == pygame.K_UP or event.key == pygame.K_w: + up_status = True + elif event.key == pygame.K_DOWN or event.key == pygame.K_s: + down_status = True + # 松开按键 + elif event.type == pygame.KEYUP: + if event.key == pygame.K_LEFT or event.key == pygame.K_a: + Left_status = False + elif event.key == pygame.K_RIGHT or event.key == pygame.K_d: + right_status = False + elif event.key == pygame.K_UP or event.key == pygame.K_w: + up_status = False + elif event.key == pygame.K_DOWN or event.key == pygame.K_s: + down_status = False + elif event.type == pygame.MOUSEBUTTONDOWN: + print("Mouse button pressed at", event.pos) + if Left_status and dirty_x >= 0: + dirty_x -= 1 + if right_status and dirty_x <= 780: + dirty_x += 1 + if up_status and dirty_y >= 0: + dirty_y -= 1 + if down_status and dirty_y <= 570: + dirty_y += 1 + # 填充窗口颜色 + screen.fill((255, 255, 255)) + + # 绘制矩形 + dirty = pygame.draw.rect(screen, BLUE, [dirty_x, dirty_y, 20, 30]) + pygame.display.update() +pygame.quit() \ No newline at end of file