-
大小: 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
相关资源
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
- python 名字用字排行
评论
共有 条评论