"""小鸟捕手.py 这是飞扬小鸟变种小游戏,在这个游戏中不再是帮助小鸟飞了,而是按空格键操作管道去"捕"小鸟""" __author__ = "李兴球" __date__ = "2018年6月" import pygame from pygame.locals import * from random import randint class Button(): def __init__(self,images,position): self.images = images # 造型列表 self.index=0 # 造型索引号 self.image = images[self.index] self.rect = self.image.get_rect() self.rect.center = position self.cursor_in= False # 鼠标指针是否在按钮矩形内 def contain_point(self,point): """判断某点是否在矩形范围内""" pass def draw(self): screen.blit(self.image,self.rect) class Bird(): """定义鸟类""" class Pipe(): def __init__(self,图像,x,y,yspeed): self.image = 图像 self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.yspeed = yspeed self.move_counts = 0 #按空格键时让它的值为10 def move(self): if self.move_counts >0: self.rect.move_ip(0,self.yspeed) self.move_counts = self.move_counts - 1 if self.move_counts ==5: # 移动次数为5就反向移动 self.yspeed = - self.yspeed screen_size = (480,360) screen = pygame.display.set_mode(screen_size) pygame.display.set_caption("小鸟捕手_作者:李兴球_萍乡风火轮少儿编程") background = pygame.image.load("backdrop2.png") 开始按钮0 = pygame.image.load("开始按钮0.png") 开始按钮1 = pygame.image.load("开始按钮1.png") 按钮们 = [开始按钮0,开始按钮1] 鸟0 = pygame.image.load("鸟0.png") 鸟1 = pygame.image.load("鸟1.png") 鸟2 = pygame.image.load("鸟2.png") 上管道 = pygame.image.load("上管道.png") 下管道 = pygame.image.load("下管道.png") 开始按钮 = Button(按钮们, (screen_size[0]//2,screen_size[1]//2)) pygame.mixer.init() pygame.mixer.music.load("Itty Bitty 8 Bit.wav") pygame.mixer.music.play(-1,0) 捕声效 = pygame.mixer.Sound("footstep grass.wav") pygame.font.init() font = pygame.font.Font("c:/windows/fonts/msyh.ttf",30) fontSurface = font.render("小鸟捕手",True,(255,0,0)) 开始界面= True pass print("进入游戏中...") bird_images = [鸟0,鸟1,鸟2] pipe_up = Pipe(上管道,400,0,5) 鸟 = Bird(bird_images,0,180) clock = pygame.time.Clock() 游戏中 = True while 游戏中: for event in pygame.event.get(): if event.type ==QUIT: 游戏中 = False pass pipe_up.move() screen.blit(background,(0,0)) screen.blit(fontSurface,(200,50)) 鸟.draw() pipe_up.draw() pygame.display.update() clock.tick(30) pygame.quit()
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)
发表评论