贪吃蛇001(设置游戏窗口和启动页面)
import pygame#窗口变量windows_width = 800windows_height = 480cell_size = 20 #方块大小map_width=windows_width//cell_sizemap_hight = windows_height//cell_size#设置颜色变量red = (255,0,0)blue = (0,0,255)blue2 = (4,23,
·
import pygame
#窗口变量
windows_width = 800
windows_height = 480
cell_size = 20 #方块大小
map_width=windows_width//cell_size
map_hight = windows_height//cell_size
#设置颜色变量
red = (255,0,0)
blue = (0,0,255)
blue2 = (4,23,120)
#初始化pygame(退出游戏时记得使用pygame.quit())
pygame.init()
screen = pygame.display.set_mode((windows_width,windows_height))
screen.fill(blue2)
pygame.display.set_caption("PYTHON 贪吃蛇98")
#开始界面
gamestart = pygame.image.load('gamestart.png')
gamestart = pygame.transform.scale(gamestart,(windows_width,windows_height)) # transform.scale缩放图片
screen.blit(gamestart,(0,0)) #blit 第一个参数:要显示的元素,第二个参数:坐标
font = pygame.font.Font('myfont.ttf',60)
tip = font.render("贪吃蛇",True,red) #渲染
screen.blit(tip,(300,30))
font = pygame.font.Font('my_pygame/resources/font/myfont.ttf',40)
tip = font.render("按任意键开始游戏(按ESC退出游戏)",True,blue) #设定需要显示的文字,True代表打开抗锯齿(字体显示平滑),blue颜色
screen.blit(tip, (100, 300))
pygame.display.update()
#死循环可以让游戏窗口停住(不会闪退)
while True:
pass
更多推荐
所有评论(0)