学python的第14天

今天继续学习使用pygame进行编程
首先,回顾昨天所学的模块(pygame常用模块)

模块名功能
pygame.cdrom访问光驱
pygame.cursors加载光标
pygame.display访问显示设备
pygame.draw绘制形状,线和点
pygame.event管理事件
pygame.font使用字体
pygame.image加载和存储图片
pygame.joystick使用游戏手柄或类似的东西
pygame.key读取键盘按键
pygame.mixer声音
pygame.mouse鼠标
pygame.movie播放视频
pygame.music播放音频
pygame.overlay访问高级视频叠加
pygame.rect管理矩形区域
pygame.sndarray操作声音区域
pygame.sprite操作移动图象
pygame.surface管理图象和屏幕
pygame.surfarray管理点阵图象数据
pygame.time管理时间和帧信息
pygame.transform缩放和移动图像

今天开始创建一个pygame窗口

# -*- coding:utf-8 -*-
import sys
import pygame

pygame.init()
size=width,height=320,240
screen=pygame.display.set_mode(size)

while True:
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			pygame.quit()
			sys.exit()

这个是可以运行的
继续学习display模块的常用方法

方法名功能
pygame.display.init初始化display模块
pygame.display.quit结束display模块
pygame.display.get_init如果display模块已经被初始化,返回True
pygame.display.set_mode初始化一个准备显示的界面
pygame.display.get_surface获取当前的Surface对象
pygame.display.flip更新整个待显示的Surface对象到屏幕上
pygame.display.update更新部分内容显示到屏幕上,如果没有参数,和flip相同

下面为我的一个程序

# -*- coding:utf-8 -*-
import sys
import pygame

pygame.init()
size=width,height=1920,1000
screen=pygame.display.set_mode(size)
color=(0,0,0)

ball=pygame.image.load("1.png")
ballrect=ball.get_rect()

while True:
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			pygame.quit()
			sys.exit()
	screen.fill(color)
	screen.blit(ball,ballrect)
	pygame.display.flip()

下面写一个做游戏的框架

import pygame
import sys
import random
class Bird(object):
    def __init__(self):
        pass
    def birdUpdate(self):
        pass

class Pipeline(object):
    def __init__(self):
        pass
    def updatePipeline(self):
        pass

def createMap():
    screen.fill((255,255,255))
    screen.blit(background,(0,0))
    pygame.display.update()

if __name__=='__main__':
    pygame.init()
    size=width,height=1920,1000
    screen=pygame.display.set_mode(size)
    clock=pygame.time.Clock()
    Pipeline=Pipeline()
    Bird=Bird()
    while True:
        clock.tick(60)
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()
                sys.exit()
        background=pygame.image.load("123.png")
        createMap()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值