1、python中第三方包的下载安装及使用,如pygame
2、pygame使用时的问题:
①pygame包中很多模块的使用方法及含义
②white中三个参数为什么必须是255?
pygame模块简介:
1、pygame语法:
import pygame
pygame.init() #初始化
print('游戏代码')
pygame.quit() #卸载模块,释放空间
2、各函数的用法
① rect 用法
描述绘制的窗口的位置,包括坐标,宽度,高度等
② screen 创建游戏窗口
import pygame
pygame.init()
1、#创建游戏窗口
320表示宽度,580表示高度
pygame.display.set_mode((320,580))
2、游戏循环
while True:
pass
pygame.quit()
QUIT:用户按下关闭按钮
KEYDOWN:键盘被按下
3、pygame的简单应用实例:
import pygame,sys
from pygame.locals import *
white=255,255,255 #白色色度
black=200,200,200 #黑色色度
pygame.init()
screen=pygame.display.set_mode((900,600))
myfront=pygame.font.Font(None,90) #从一个字体文件创建一个字体对象
textmessage=myfront.render("hello baobao",True,black)
while True:
for event in pygame.event.get():
if event.type in (QUIT,KEYDOWN):
sys.exit()
screen.fill(white)
screen.blit(textmessage,(100,100))
pygame.display.update() #更新屏幕的部分以显示软件