当前位置: 首页>>代码示例>>Python>>正文


Python Block.kill方法代码示例

本文整理汇总了Python中Block.Block.kill方法的典型用法代码示例。如果您正苦于以下问题:Python Block.kill方法的具体用法?Python Block.kill怎么用?Python Block.kill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Block.Block的用法示例。


在下文中一共展示了Block.kill方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from Block import Block [as 别名]
# 或者: from Block.Block import kill [as 别名]
def main():
    import sys
    from Block import Block

    PH_TARGET = "Graphics\placeholder_target.png"
    WINDOWWIDTH = 720
    WINDOWHEIGHT = 380
    windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
    #  N,E,S,W
    bounds = [ 0, WINDOWWIDTH, WINDOWHEIGHT, 0 ]
    timer = pygame.time.Clock()
    fps = 60

    a = Block((255,0,0), 500, 220, 32, 32)
    b = Block((0,255,0), 300, 120, 16, 16)
    c = Block((0,0,255), 100, 20, 8, 8)
    
    gr = pygame.sprite.Group()
    gr2 = pygame.sprite.Group()
    gr.add( a, b, c )
    
    f = FollowBlock(windowSurface, "Graphics\missile01.png", -90)
    f.setCenter( (160, 245) )
    f.speed = 8
    f.setDir( 90 )
    f.seek(gr, 10, bounds)

    while(True):

        #wrap
        for i in gr:
            if i.rect.centery <= 0:
                i.rect.centery = WINDOWHEIGHT
                i.rect.centerx = random.randint(20, 700)
            else:
                i.rect.y -= 4

        #random teleport
        for i in gr:
            
            if i.rect.colliderect( f ):
                i.setCenterPos(random.randint(50,670), random.randint(50,330))
                side = random.randint(8,32)
                r = random.randint(0,255)
                g = random.randint(0,255)
                b = random.randint(0,255)
                i.convertToColor( (r,g,b), side, side )
                i.ph = False
                
            for j in gr2:
                if i.rect.colliderect( j ):
                    i.kill()
                    j.kill()

        #CHECK FOR WIN
        cnt = 0
        for enemy in gr:
            cnt += 1
        if cnt == 0:
            input(" YOU WIN ! (press enter bro)\n")
            pygame.quit()
            sys.exit()

        #events
        for event in pygame.event.get():

            #QUIT
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

            #CREATE BLOCK
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    side = random.randint(8,32)
                    x = random.randint(side,WINDOWWIDTH-side)
                    y = random.randint(side,WINDOWHEIGHT-side)
                    r = random.randint(0,255)
                    g = random.randint(0,255)
                    b = random.randint(0,255)
                    blok = Block((r,g,b), x, y, side, side)
                    blok2 = Block((r,g,b), x, y, side, side)
                    gr.add( blok, blok2 )
                    if f.speed < 16:
                        f.speed += 1
                    else:
                        rnd = random.randint(1,6)
                        for i in range(rnd):
                            f2 = FollowBlock(windowSurface, "Graphics\missile02.png", -90)
                            f2.setCenter( (WINDOWWIDTH/2, WINDOWHEIGHT) )
                            f2.speed = 4.5
                            f2.setDir( random.randint(15,165) )
                            f2.seek(gr, 5, bounds)
                            gr2.add(f2)

        #destroy extra missile if leave window:
        for b in gr2:
            if(b.rect.left   > WINDOWWIDTH  or
               b.rect.right  < 0            or
               b.rect.bottom < 0            or
#.........这里部分代码省略.........
开发者ID:Ibsardar,项目名称:CompletePygameExample,代码行数:103,代码来源:FollowBlock.py


注:本文中的Block.Block.kill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。