• 大小: 5KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-17
  • 语言: Python
  • 标签: 源码  工具  

资源简介

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


评论

共有 条评论