学python的第15天

今天还是学习利用pygame进行编程
我们先搭建一个程序的主框架

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=400,650
	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("1234567890.png")
		createMap()

写完这个框架后,我们需要写上面提到的4个pass的内容
先把class Bird(object):类完善

class Bird(object):
	def __init__(self):
		self.birdRect=pygame.Rect(65,50,50,50)
		self.birdStatus=[pygame.image.load("1.png"),pygame.image.load("2.png"),pygame.image.load("3.png")]
		self.status=0
		self.birdx=100
		self.birdy=350
		self.jump=False
		self.gravity=5
		self.dead=False
	def birdUpdate(self):
		if self.jump:
			self.JumpSpeed-=1
			self.birdy-=self.jumpSpeed
		else:
			self.gravity+=0.02
			self.birdy+=self.gravity
		self.birdRect[1]=self.birdy

再完善Pipeline(self)

class Pipeline(object):
	def __init__(self):
		self.wallx=400
		self.pineUp=pygame.image.load("top.png")
		self.pineDown=pygame.image.load("bottom.png")
	def updatePipeline(self):
		self.wallx-=5
		if self.wallx<-80:
			self.wallx=400
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值