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


Python Ghost.draw方法代码示例

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


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

示例1: test

# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import draw [as 别名]
def test():
    '''test function for proof of concept of the new level system'''
    #new level system is generated from a file, while the game is running as opposed to all at once.
    def drawDiagnostic(surf,**kwargs):
        f = pygame.font.Font(None,20)
        h = 0
        for i in kwargs:
            outstr = '{0}:{1}'.format(i,kwargs[i])
            font_obj = f.render(outstr,False,Constants.WHITE)
            surf.blit(font_obj,(Constants.WIDTH-font_obj.get_width(),h*20))
            h += 1
    pygame.init()
    screen = pygame.display.set_mode((Constants.WIDTH,Constants.HEIGHT))
    player = Ghost((50,300))
    parts = pygame.sprite.Group()
    gens = pygame.sprite.Group()
    sparks = pygame.sprite.Group()
    num = 0
    off = .75
    timer = gameTime.Timer()
    fpsClock = pygame.time.Clock()
    events = []
    for i in xrange(100):
        for j in xrange(10):
            #pos = (i*30+200,j*30+100)
            pos = (Constants.WIDTH,j*30+100)
            out = '{0}:{1}:{2}'.format((i*30+200)/off,(num%4+6)*10+num%2,pos)
            events.append(out)
            num += 1
    timeline = gameTime.EventQueue()
    timeline.load(events)
    while True:
        screen.fill(Constants.BLACK)
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                SystemExit
            elif event.type == MOUSEBUTTONDOWN:
                angle = player.angle_to_point(event.pos)
                vel = [7*math.cos(angle),-7*math.sin(angle)]
                player.setVelocity(vel)
            elif event.type == Constants.ADD_PARTICLE:
                parts.add(event.particle(event.pos))
            elif event.type == Constants.ADD_GENERATOR:
                gens.add(event.particle(event.pos,flip=event.flip))
            elif event.type == Constants.ADD_SPARK:
                sparks.add(environment.Spark(event.pos,event.charge,event.color,event.vel))
        pygame.event.clear()
        if timeline._next:
            while timeline._next and timer.curr>timeline._next.time:
                pygame.event.post(timeline.pop())
        parts.update(off)
        parts.draw(screen)
        gens.update(off)
        gens.draw(screen)
        sparks.update(off)
        sparks.draw(screen)
        player.update(off)
        player.draw(screen)
        coll = pygame.sprite.spritecollideany(player,parts,pygame.sprite.collide_mask)
        if coll:
            player.collected[coll.charge]+=1
            coll.kill()
        drawDiagnostic(screen,velocity=player.velocity,neutrons=player.collected[0],protons=player.collected[1],electrons=player.collected[2],particle_cnt=len(parts))
        pygame.display.update()
        fpsClock.tick(60)
        timer.update()
开发者ID:mynameis7,项目名称:ElectroGhost,代码行数:69,代码来源:main.py


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