Compare commits

...
4 changed files with 132 additions and 0 deletions

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: Game_project
# FileName: colorconf.py
# Author: Zhi_yuan
# Datetime: 2026/8/7 下午9:21
# Description:
# ---------------------------------------------------------------------------
class Color:
def __init__(self):
self.white = (255, 255, 255)
self.red = (255, 0, 0)
self.blue = (0, 0, 255)
+25
View File
@@ -0,0 +1,25 @@
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: Game_project
# FileName: pageconf.py
# Author: Zhi_yuan
# Datetime: 2026/8/7 下午9:34
# Description:
# ---------------------------------------------------------------------------
import pygame
class Page:
def __init__(self):
# pygame初始化
pygame.init()
# 音乐模块初始化
pygame.mixer.init()
# 大小设置
size = (800, 600)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("New_game")
if __name__ == "__main__":
Page()
Binary file not shown.
+94
View File
@@ -0,0 +1,94 @@
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName: Game_project
# FileName: page.py
# Author: Zhi_yuan
# Datetime: 2026/7/25 下午10:44
# Description:
# ---------------------------------------------------------------------------
import pygame
from common.colorconf import Color
# 初始化pygame
pygame.init()
# 初始化音乐
pygame.mixer.init()
# 设置窗口大小
size = (800, 600)
screen = pygame.display.set_mode(size)
# 窗口名称
pygame.display.set_caption("New_game")
# 播放并循环音乐
pygame.mixer_music.load(r'D:\python_project\Game_project\file\vespidaze-upbeat-rpg-battle-460971.mp3')
pygame.mixer_music.play(-1)
# 状态值
dirty_x = 400
dirty_y = 300
Left_status = False
right_status = False
up_status = False
down_status = False
# 颜色
color = Color()
WHITE = color.white
RED = color.red
BLUE = color.blue
# 游戏循环
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])
enemy = pygame.draw.rect(screen, RED, [40, 60, 10, 10])
# 碰撞监测
if dirty.colliderect(enemy):
print("die")
dirty_x = 400
dirty_y = 300
dirty = pygame.draw.rect(screen, BLUE, [dirty_x, dirty_y, 20, 30])
pygame.display.update()
pygame.quit()