太空虫子

太空虫子

"""
   太空虫子。
   太空外星害虫来袭,小虫子被赋予光荣任务去消灭它们。
   可是它没有武器,只有去撞死它们。
   请按上下左右方向箭头,消灭所有害虫!
   
"""

from sprites import *

width,height = 600,760
screen = Screen()               # 新建屏幕
screen.setup(width,height)      # 屏幕宽高
screen.bgcolor('black')         # 背景颜色
screen.title('太空虫子_by www.lixingqiu.com')

# 铺设星空背景
star = Sprite(shape='star',visible=False)
star.color('white')             # 星星为白色
for _ in range(50):
    star.gotorandom()
    star.scale(max(0.01,random.random()/10))
    star.stamp()                # 星星盖图章
 
pest_group = Group('pest')      # 新建所有害虫组
rows = 8                        # 行数 
cols = 8                        # 列数 
startx = -200                   # 起始x坐标
starty = 300                    # 起始y坐标
for r in range(rows):           # 迭代rows
    for c in range(cols):       # 迭代cols
        x = startx + c * 60     # 形成x坐标
        y = starty - r * 40     # 形成y坐标
        p = Sprite(shape='res/pest.png',pos=(x,y),tag='pest')
        p.dy = 0                # 垂直速度为0   
        p.da = 0                # 加速度为-0.5

# 新建木条,作为虫子的托盘   
woodbar = Sprite('res/woodbar.png',pos=(0,-320))

bug = Sprite(pos=(0,-200))      # 新建虫子
bug.left(90)                    # 左转90度
bug.dx = 0                      # 水平速度
bug.dy = 0                      # 垂直速度

leftkey = Key("Left")           # 实例化左方向箭头
rightkey = Key("Right")         # 实例化右方向箭头
upkey = Key("Up")               # 实例化上方向箭头
downkey = Key("Down")           # 实例化下方向箭头

screen.listen()
clock = Clock()                 # 新建时钟对象

以下代码省略......

下载完整源代码与素材,请

成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

李兴球

李兴球的博客是Python创意编程原创博客

评论已关闭。