forked from zhiyuan/Project1
封装为类
This commit is contained in:
1 parent
8fba77d1c0
commit
2f7261f59c
1 file changed
+25
-20
@@ -1,38 +1,43 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
# 初始化
|
from src.config.color import Color
|
||||||
pygame.init()
|
from src.config.game_config import GameConfig
|
||||||
|
|
||||||
# 设置窗口大小
|
|
||||||
window_size = (1920/2, 1080/2)
|
|
||||||
screen = pygame.display.set_mode(window_size)
|
|
||||||
|
|
||||||
# 设置标题
|
|
||||||
pygame.display.set_caption("Test Name")
|
|
||||||
|
|
||||||
rect = [10,20,30,40]
|
rect = [10,20,30,40]
|
||||||
black = (0,0,0)
|
|
||||||
white = (255,255,255)
|
|
||||||
|
|
||||||
def update():
|
class Game:
|
||||||
pass
|
def __init__(self):
|
||||||
|
# 初始化
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
# 设置窗口大小
|
||||||
|
size = (GameConfig.window_x, GameConfig.window_y)
|
||||||
|
self.screen = pygame.display.set_mode(size)
|
||||||
|
|
||||||
|
# 设置标题
|
||||||
|
pygame.display.set_caption(GameConfig.game_name)
|
||||||
|
|
||||||
def main():
|
|
||||||
# 运行循环
|
# 运行循环
|
||||||
running = True
|
self.running = True
|
||||||
while running:
|
self.run()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
while self.running:
|
||||||
# 事件处理
|
# 事件处理
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
# 检查是否关闭
|
# 检查是否关闭
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
running = False
|
self.running = False
|
||||||
|
|
||||||
screen.fill(black)
|
self.screen.fill(GameConfig.bg_color)
|
||||||
|
|
||||||
pygame.draw.rect(screen, white, rect)
|
self.update()
|
||||||
|
|
||||||
# 更新显示
|
# 更新显示
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
pygame.draw.rect(self.screen, Color.white, rect)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
Game()
|
||||||
Reference in new issue
Block a user