单向场景切换版本 #1
@@ -1,38 +1,43 @@
|
||||
import pygame
|
||||
|
||||
# 初始化
|
||||
pygame.init()
|
||||
|
||||
# 设置窗口大小
|
||||
window_size = (1920/2, 1080/2)
|
||||
screen = pygame.display.set_mode(window_size)
|
||||
|
||||
# 设置标题
|
||||
pygame.display.set_caption("Test Name")
|
||||
from src.config.color import Color
|
||||
from src.config.game_config import GameConfig
|
||||
|
||||
rect = [10,20,30,40]
|
||||
black = (0,0,0)
|
||||
white = (255,255,255)
|
||||
|
||||
def update():
|
||||
pass
|
||||
class Game:
|
||||
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
|
||||
while running:
|
||||
self.running = True
|
||||
self.run()
|
||||
|
||||
def run(self):
|
||||
while self.running:
|
||||
# 事件处理
|
||||
for event in pygame.event.get():
|
||||
# 检查是否关闭
|
||||
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()
|
||||
|
||||
def update(self):
|
||||
pygame.draw.rect(self.screen, Color.white, rect)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Game()
|
||||
Reference in new issue
Block a user