今天还是学习利用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