import pygame
import time
import keyboard
import sys
import random
pygame.init()
# 初始化设置
WHITE=(255,255,255)
BLACK=(0,0,0)
BLUE=(0,0,255)
RED=(255,0,0)
GREEN=(0,255,0)
#基本颜色设定
screen = pygame.display.set_mode((1024,720))
pygame.display.set_caption('梦回北宋——第一幕')
screen.fill(WHITE)
background1 = pygame.image.load('D:\编程资料\背景\开始界面背景.png')
screen.blit(background1, (0, 80))
pygame.display.update()
#屏幕显示
bgm=pygame.mixer.music.load('D:\编程资料\背景音乐.mp3')
pygame.mixer.music.play(-1)
#播放背景音乐
text = pygame.font.SysFont('楷体', 50)
class Button:
def __init__(self, content, color, x, y):
self.surface = text.render(content, True, color)
self.WIDTH = self.surface.get_width()
self.HEIGHT = self.surface.get_height()
self.x = x
self.y = y
def display(self):
screen.blit(self.surface, (self.x, self.y))
def check_click(self, position):
x_match = position[0] > self.x and position[0] < self.x + self.WIDTH
y_match = position[1] > self.y and position[1] < self.y + self.HEIGHT
if x_match and y_match:
return True
else:
return False
#按钮类,分为三块
KS=Button('start',WHITE,100,450)
KS.display()
pygame.display.update()
缩进问题?? 是不是tab键和空格混用了,检查下是不是都是空格缩进