• 大小: 73KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-05-08
  • 语言: Python
  • 标签: Python  flappybird  

资源简介

使用了pygame和gameobject实现的python版的flappybird小游戏

资源截图

代码片段和文件信息

start_image_filename = ‘start.png‘
back_image_filename = ‘bg.jpg‘
block_image_filename = ‘pipe.png‘
bird_image_filename = ‘bird.png‘
import pygame
from pygame.locals import *
from gameobjects.vector2 import *   
import random
import math
SCREEN_SIZE = (378537)
#SCREEN_SIZE = (600800)
run1 = 0
run2 = 0
over = 0
def load_image(file width number):
    surface = pygame.image.load(file).convert_alpha()
    height = surface.get_height() 
    return [surface.subsurface(
        Rect((i * width 0) (width height))
        ) for i in range(number)]
class object(object):#实体类
    def __init__(selfnameposition):
        self.name = name
        self.position = Vector2(*position)
        self.speed = 0
class Fish(pygame.sprite.Sprite):
    #_life = 100
    images = []
    def __init__(selfr):
        self.order = 0
        self.rate = 0.2
        self.height = 60
        self.number = 3
        self.position = Vector2(189269)
        self.r = r
        self.speed = 0
        pygame.sprite.Sprite.__init__(self)
        self.images = load_image(bird_image_filename80 3)
        self.image = self.images[self.order]
        #self.rect = Rect(0 0 self.width self.height)
        #self.life = self._life
        self.passed_time = 0
 
    def update(self passed_time):
        self.passed_time += passed_time
        self.order = ( self.passed_time / self.rate ) % self.number
        if self.order == 0 and self.passed_time > self.rate:
            self.passed_time = 0
        self.image = self.images[int(self.order)]

    def render(selfscreen):
        xy = self.position
        x -= 40
        y -= 30
        screen.blit(self.image(int(x)int(y)))

#class Fish(object):#小球类
    #def __init__(selfnamepositionr):
        #object.__init__(selfnameposition)
        #self.r = r
    #def render(selfscreen):#绘制小球自己
        #xy = self.position
        #pygame.draw.circle(screen (25116240) (int(x)int(y))self.r)

class Block(object):#方块类
    def __init__(selfnamepositionIDimage):
        object.__init__(selfnameposition)
        self.ran = random.randint(0200)#随机值用于开口位置
        self.ID = ID#用于标记这是第几个方块,方便统计分数
        self.image = image
    def render(selfscreen):#绘制上下两个长方形形成障碍物
        xy = self.position       
        screen.blit(self.image(x250+self.ran))
        screen.blit(self.image(xself.ran-353))
class Button(object):#按钮类
    def __init__(self  positionimage):
 
        self.position = position
        self.image = image
 
    def render(self screen):
        x y = self.position
        w h = self.image.get_size()
        screen.blit(self.image (x-w/2 y-h/2))
 
    def is_over(self point):#判断鼠标是否在按钮上
        if (SCREEN_SIZE[0]-self.image.get_size()[0])/2 < point[0]<(SCREEN_SIZE[0]+self.image.get_size()[0])/2:
            if (SCREEN_SIZE[1]-self.image.get_size()[1])/2 < point[1]<(SCREEN_SIZE[1]+self.image.get_size()[1])/2:
           

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件       49954  2014-03-09 23:41  bg.jpg
     文件       12443  2014-03-09 23:40  bird.png
     文件        9398  2014-07-03 00:05  flappyfish1.2test.py
     文件       13607  2014-03-12 15:34  pipe.png
     文件         158  2014-07-01 20:05  readme.txt
     文件       10288  2014-03-13 19:58  start.png

评论

共有 条评论