Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b581f4def2 | ||
|
|
f76bbc6442 | ||
|
|
538af0d98c | ||
|
|
876645f4b0 | ||
|
|
5c91fce9fd |
No files matched your search
@@ -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)
|
||||||
@@ -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.
+22
-4
@@ -7,10 +7,14 @@
|
|||||||
# Description:
|
# Description:
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
import pygame
|
import pygame
|
||||||
|
from common.colorconf import Color
|
||||||
|
|
||||||
# 初始化pygame
|
# 初始化pygame
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
|
# 初始化音乐
|
||||||
|
pygame.mixer.init()
|
||||||
|
|
||||||
# 设置窗口大小
|
# 设置窗口大小
|
||||||
size = (800, 600)
|
size = (800, 600)
|
||||||
screen = pygame.display.set_mode(size)
|
screen = pygame.display.set_mode(size)
|
||||||
@@ -18,6 +22,10 @@ screen = pygame.display.set_mode(size)
|
|||||||
# 窗口名称
|
# 窗口名称
|
||||||
pygame.display.set_caption("New_game")
|
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_x = 400
|
||||||
dirty_y = 300
|
dirty_y = 300
|
||||||
@@ -28,9 +36,10 @@ up_status = False
|
|||||||
down_status = False
|
down_status = False
|
||||||
|
|
||||||
# 颜色
|
# 颜色
|
||||||
WHITE = (255, 255, 255)
|
color = Color()
|
||||||
RED = (255, 0, 0)
|
WHITE = color.white
|
||||||
BLUE = (0, 0, 255)
|
RED = color.red
|
||||||
|
BLUE = color.blue
|
||||||
# 游戏循环
|
# 游戏循环
|
||||||
running = True
|
running = True
|
||||||
while running:
|
while running:
|
||||||
@@ -70,7 +79,16 @@ while running:
|
|||||||
# 填充窗口颜色
|
# 填充窗口颜色
|
||||||
screen.fill((255, 255, 255))
|
screen.fill((255, 255, 255))
|
||||||
|
|
||||||
# 绘制矩形
|
# 绘制矩形(移动体和固定体)
|
||||||
dirty = pygame.draw.rect(screen, BLUE, [dirty_x, dirty_y, 20, 30])
|
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.display.update()
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
Binary file not shown.
Reference in new issue
Block a user