资源简介
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
相关资源
- Python 串口工具源码+.exe文件
- 蓝奏云批量上传工具.zip
- python源码制作whl文件.rar
- SIFT源码python实现
- 图形识别与颜色识别工具
- python网络爬虫获取景点信息源码
- 电力窃漏电用户自动识别 源码
- 3D打印机控制软件Cura源码
- python爬取维基百科程序语言消息盒(
- python坦克大战分步骤源码及素材
- 使用python编写的打飞机游戏源码
- 正方教务系统新版sql注入漏洞利用工
- 50G金融资料包python源码包
- python_web实战-源码
- Python黑帽子 黑客与渗透测试编程之道
- python新浪微博爬虫,爬取微博和用户
- python火车票查询软件及源码
- QGIS的GeoHey-Toolbox-0.2纠偏工具
- Python源码剖析★PART2★(完整清晰版
- Python黑帽子(黑客与渗透测试编程之
- python坦克大战图片源码.zip
- python新浪微博爬虫,爬取微博和用户
- 量化投资:以Python为工具,代码和数
- 基于python的FMU仿真工具
- Python基础教程第3版中英文源码.rar
- 基于hadoop的电影推荐系统源码.zip
- Python贪吃蛇源码+背景音乐+中文字体
- Python数据挖掘和实战课程源码
- python之外星人入侵完整版程序源码
- Python-PyGradle使用Gradle来构建Python项目
评论
共有 条评论