资源简介
NULL
博文链接:https://chengf.iteye.com/blog/719546

代码片段和文件信息
import pygameosmathtime
from random import randintuniformrandom
from pygame.locals import *
#define the screen size
SCREEN_SIZE = (300300)
#define enum edge
EDGE_LEFT = 1
EDGE_BOTTOM = 2
EDGE_RIGHT = 3
EDGE_TOP = 4
def load_image(folderPathname colorkey=None):
“““ load image and set a colorkey for it“““
fullname = os.path.join(folderPath name)
try:
image = pygame.image.load(fullname)
except pygame.error message:
print ‘Cannot load image:‘ fullname
raise SystemExit message
image = image.convert()
if colorkey is None:
colorkey = image.get_at((00))
image.set_colorkey(colorkey RLEACCEL)
return image
def wait_enter_pressed(keys):
“block the screen to wait a keyborad event“
while True:
e = pygame.event.wait()
if e.type == KEYUP and e.key in keys:
break
elif e.type == QUIT:
pygame.quit()
return
#
class Jet(pygame.sprite.Sprite):
“““class Jet represents a plane in the game“““
def __init__(selfimagesspeedpos):
“““
images:jet images
speed: the speed of jet
pos: the initial position of jet
“““
pygame.sprite.Sprite.__init__(self)
self.speed = speed
self.direction = [00]
self.images = images
self.imageself.rect = images[0]images[0].get_rect()
self.rect.center = pos
def update(self):
“““ move the jet and update the screen“““
dxdy = self.direction
self.rect.move_ip(dx*self.speeddy*self.speed)
rect = self.rect
if rect.left < 0:
rect.left = 0
elif rect.right > SCREEN_SIZE[0]:
rect.right = SCREEN_SIZE[0]
if rect.top < 0:
rect.top = 0
elif rect.bottom > SCREEN_SIZE[1]:
rect.bottom = SCREEN_SIZE[1]
def change_direction(selfvertical=0horizontal=0):
“““ change the jet‘s direction“““
self.direction[0]self.direction[1]= horizontalvertical
self.image = self.images[horizontal]
class Pellet(pygame.sprite.Sprite):
“““ represent the bullet in game“““
def __init__(selfimagespeed):
“““ a pellet use a 1x2 matrix to move“““
pygame.sprite.Sprite.__init__(self)
self.image self.rect = imageimage.get_rect()
self.speed = speed
#init the initial point and the moving matrix
self.rect.centerself.direction = self._generate_line()
def _generate_line(self):
“““ generate a initial point and a moving matrix(direction)“““
edge = randint(EDGE_LEFTEDGE_TOP)
start_x start_y = 00
if edge == EDGE_LEFT:
start_x = 0
start_y = randint(0SCREEN_SIZE[1])
dx dy = uniform(0.51)uniform(-11)
elif edge == EDGE_BOTTOM:
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 134 2010-06-18 15:24 play\images\ball.bmp
文件 713 2010-06-18 16:49 play\images\jet.png
文件 628 2010-06-18 16:49 play\images\jetleft.PNG
文件 624 2010-06-18 16:49 play\images\jetright.PNG
文件 8127 2010-07-22 16:39 play\main.py
目录 0 2010-07-23 11:22 play\images
目录 0 2010-07-23 11:22 play
----------- --------- ---------- ----- ----
10226 7
相关资源
- 中文分词工具评测
- 抖音视频无水印核心源码
- IIs put上传工具
- python 连连看小游戏源码
- 100道Python练习题(附源码)
- python五子棋源码(控制台版本)
- dronet源码+论文(深度学习)
- 坦克大战带源码(python)
- 恐龙快跑 游戏源码(基于pygame)
- cs破解工具
- 教孩子学编程源码
- labelImg-1.8.1(图片标注工具)
- python学生管理系统源码(控制台)
- 缠论dll(czsc - 缠中说禅技术分析工具
- Tushare库打造股票筛选工具
- 自动截屏工具(python源码)
- python学生管理器源码
- 小说阅读项目源码(附数据库脚本)
- 美多商城源码(Python+Diango+Vue)
- QPA进程抓包工具
- 超级玛丽 python源码
- 玩我的世界学python编程源码
- 中山大学-自然语言处理-中文分词项目
- Python其它开发工具的安装与使用.ppt
- python爬虫爬取旅游信息(附源码,c
- 爬取上百张妹子图源码可直接运行
- python 井字棋 游戏源码
- Python源码剖析.pdf59505
- Python 串口工具源码+.exe文件
- 蓝奏云批量上传工具.zip
评论
共有 条评论