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


Python Ship.stop_move_left方法代码示例

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


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

示例1: Vacuum

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import stop_move_left [as 别名]
class Vacuum():

    def __init__(self):
        if not pygame.font: print 'Warning, fonts disabled'
        if not pygame.mixer: print 'Warning, sound disabled'
        self.initialise()
        self.loop()

    def initialise(self):
        """this function is called when the program starts.
           it initializes everything it needs, then runs in
           a loop until the function returns."""
        #Initialize Everything
        pygame.init()
        self.screen = pygame.display.set_mode((640, 480))
        pygame.display.set_caption('VacuumFire')
        pygame.mouse.set_visible(0)
        #icon
        icon, foo = utils.load_image('icon.png')
        pygame.display.set_icon(icon)

        self.game_paused = False
        #sounds
        self.sounds = {};
        self.sounds['music'] = utils.load_sound('archivo.ogg')
        self.sounds['warning'] = utils.load_sound('warning.wav')
        self.sounds['powerup'] = utils.load_sound('powerup.wav')
        self.sounds['music'].play()
        #Create The Backgound
        self.background = Background(self.screen.get_size())
        #game variables
        self.score = 0
        #Display The Background
        self.screen.blit(self.background, (0, 0))
        pygame.display.flip()


        #The player's ship
        self.ship = Ship()
        #The player's ship
        self.lifemeter = LifeMeter()
        self.player    = pygame.sprite.RenderPlain((self.ship))
        #group that stores all enemies
        self.enemies    = pygame.sprite.Group()
        #group that stores all powerups
        self.powerups    = pygame.sprite.Group()
        #group that stores all the lasers the player shoots
        self.fire        = pygame.sprite.Group()
        #group for information sprites in the screen, should be rendered the last one
        self.hud         = pygame.sprite.Group()
        self.explosions  = pygame.sprite.Group()
        self.hud.add(self.lifemeter)
        #The level
        self.level = Stage('level_1')
        self.font = utils.load_font('4114blasterc.ttf', 36)


        self.clock = pygame.time.Clock()

        self.game_started = False
        self.game_finished = False

    def handle_keys(self):
        #Handle Input Events
        for event in pygame.event.get():
            if event.type == QUIT:
                #exit
                return
            elif event.type == KEYDOWN and event.key == K_ESCAPE and self.game_finished == True:
                pygame.quit()
                quit()
                
            if event.type == KEYDOWN:
                self.game_started = True
                if event.key == K_ESCAPE:
                    return false   #exit
                elif event.key == K_SPACE:
                    #shoot a laser if the max number is not reached
                    if Laser.num < Laser.max_lasers:
                        self.laser = Laser(self.ship)
                        self.fire.add(self.laser)
                elif event.key == K_LEFT:
                    self.ship.move_left()
                elif event.key == K_RIGHT:
                    self.ship.move_right()
                elif event.key == K_UP:
                    self.ship.move_up()
                elif event.key == K_DOWN:
                    self.ship.move_down()
                elif event.key == K_p:
                    self.game_paused = not self.game_paused

            if event.type == KEYUP:
                if event.key == K_LEFT:
                    self.ship.stop_move_left()
                elif event.key == K_RIGHT:
                    self.ship.stop_move_right()
                elif event.key == K_UP:
                    self.ship.stop_move_up()
                elif event.key == K_DOWN:
#.........这里部分代码省略.........
开发者ID:codelurker,项目名称:VacuumFire,代码行数:103,代码来源:main.py

示例2: Vacuum

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import stop_move_left [as 别名]

#.........这里部分代码省略.........
                self.game_finished = True
            elif event.type == KEYDOWN and event.key == K_ESCAPE and self.game_finished == True:
                self.scene_finished = True
                
            if event.type == KEYDOWN:
                self.game_started = True
                if event.key == K_ESCAPE:
                    return False   #exit
                elif event.key == K_SPACE:
                    #shoot a laser if the max number is not reached
                    if Laser.num < Laser.max_lasers:
                        #print "There's {0} lasers in the screen and the max is {1}".format(Laser.num, Laser.max_lasers)
                        laser = Laser(self.ship)
                        self.fire.add(laser)
                        if self.ship.buddies > 0:
                            self.fire.add(DiagonalLaser(self.ship, "up"))
                        if self.ship.buddies > 1:
                            self.fire.add(DiagonalLaser(self.ship, "down"))
                        if self.ship.buddies > 2:
                            self.fire.add(DiagonalLaser(self.ship, "back"))
                elif event.key == K_LEFT:
                    self.ship.move_left()
                elif event.key == K_RIGHT:
                    self.ship.move_right()
                elif event.key == K_UP:
                    self.ship.move_up()
                elif event.key == K_DOWN:
                    self.ship.move_down()
                elif event.key == K_p:
                    self.game_paused = not self.game_paused

            if event.type == KEYUP:
                if event.key == K_LEFT:
                    self.ship.stop_move_left()
                elif event.key == K_RIGHT:
                    self.ship.stop_move_right()
                elif event.key == K_UP:
                    self.ship.stop_move_up()
                elif event.key == K_DOWN:
                    self.ship.stop_move_down()

        return True

    def process_powerups(self):
        #powerups got by the player, remove them, play a sound and apply them
        powerups_obtained  = pygame.sprite.spritecollide(self.ship, self.powerups, True)
        for powerup_obtained in powerups_obtained:
            #play powerup sound
            self.sounds['powerup'].play()
            self.score.add_score(powerup_obtained.value)
            #TODO powerup should be processed in ship
            print 'powerup:',powerup_obtained.type
            if powerup_obtained.type == 0:
                self.ship.life_up()
                self.hud.add(Flying_Label( self.ship.rect, 'Energy'))
                self.lifemeter.life = self.ship.life
            elif powerup_obtained.type == 1 and self.ship.powerup['speedup'] < 5:
                self.ship.powerup['speedup'] += 1 
                self.powerup_speed.set_status(self.ship.powerup['speedup'])
                self.hud.add(Flying_Label( self.ship.rect, 'Speed up'))
                #print "Increase speed to {0}".format(self.ship.powerup['speedup'])
            elif powerup_obtained.type == 2 and Laser.max_lasers < 5:
                Laser.max_lasers += 1 
                Laser.move += 2 
                self.powerup_weapon.set_status(Laser.max_lasers)
                print "Increase lasers to {0}".format(Laser.max_lasers)
开发者ID:timepilot,项目名称:VacuumFire,代码行数:70,代码来源:vacuum.py


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