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


Python Ship.set_direction方法代码示例

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


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

示例1: _preload

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import set_direction [as 别名]
    def _preload(self, screen):
        rect = screen.get_rect()
        resolution = (rect.width, rect.height)

        yield 'Loading Events'
        self.controller = game_handler
        self.controller.context.mediator = self

        yield 'Loading Background'
        self.bg = ImageView(
            background.load(options=background.STRETCH, resolution=resolution)
        )
        self.views.append(self.bg)

        yield 'Loading Planets'
        for msg in Planet.load():
            yield msg

        yield 'Loading Stars'
        Sun.set_fps(GameMediator.FPS)

        yield 'Loading Sector'
        self.celestials = []

        sun = Sun(resolution[0] / 2, resolution[1] / 2, 50)
        self.celestials.append(sun)
        self.views.append(sun)
        yield

        planet = Planet(0, 0, 8)
        planet.orbit(sun, 140)
        self.celestials.append(planet)
        self.views.append(planet)
        yield

        planet = Planet(0, 0, 10)
        planet.orbit(sun, 60)
        self.celestials.append(planet)
        self.views.append(planet)
        yield

        planet = Planet(0, 0, 30)
        planet.orbit(sun, 200)
        self.celestials.append(planet)
        self.views.append(planet)
        yield

        yield 'Building Ships'
        for msg in Ship.load():
            yield msg

        Ship.set_fps(GameMediator.FPS)

        yield 'Spawning Players'
        self.players = {}

        player1 = Ship(50, 50, base='purple')
        player1.set_MoveSpeed(10)
        player1.set_TurnSpeed(pi)
        player1.set_direction(0)
        self.views.append(player1)
        self.players[1] = player1
        yield

        player2 = Ship(600, 50, base='red')
        player2.set_MoveSpeed(10)
        player2.set_TurnSpeed(pi)
        player2.set_direction(-pi/4)
        self.views.append(player2)
        self.players[2] = player2
        yield

        player3 = Ship(50, 400, base='green')
        player3.set_MoveSpeed(10)
        player3.set_TurnSpeed(pi)
        player3.set_direction(pi/2)
        self.views.append(player3)
        self.players[3] = player3
        yield

        player4 = Ship(600, 400, base='blue')
        player4.set_MoveSpeed(10)
        player4.set_TurnSpeed(pi)
        player4.set_direction(-pi/2)
        self.views.append(player4)
        self.players[4] = player4
        yield

        yield 'Applying Gravity'
        for celestial in self.celestials:
            celestial.pull_on(player1)
            celestial.pull_on(player2)
            celestial.pull_on(player3)
            celestial.pull_on(player4)
开发者ID:Saevon,项目名称:spacebattle,代码行数:96,代码来源:mediators.py

示例2: Level

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

#.........这里部分代码省略.........
                cannon.start_transition(Cannon.DEACTIVATED)
                self.manager.give_energy(opt.energy_from_cannon)
                
        #cannon with cell
        #kill one cell and reverse cannon direction
        #assuming this is only possible if cannon in firing state
        if cannon.get_state_number() == Cannon.FIRING:
            cannon_collides = spritecollide(cannon, shield, False, collide_mask)
            if len(cannon_collides) > 0:
                cannon_collides[0].kill()
                self.manager.add_score(opt.score_cell_shoot)
                cannon.start_transition(Cannon.RETURNING)
            
        #cannon with enemy base -- only if cannon in firing state
        #give points corresponding to enemy state and end level
        #if enemy base is in shooting state, player also gets a life
        if cannon.get_state_number() == Cannon.FIRING and collide_mask(cannon, enemy):
            if enemy.get_state_number() == EnemyBase.MOVING:
                self.manager.add_score(opt.score_mover_destroy)
            elif enemy.get_state_number() == EnemyBase.SPINNING:
                self.manager.add_score(opt.score_spinner_destroy)
            elif enemy.get_state_number() == EnemyBase.SHOOTING:
                self.manager.add_score(opt.score_shooter_destroy)
                self.manager.give_life()
            self.end_level()
        
        #player's bullet with cell
        #kill player bullet but remove cells in a cross pattern
        #if somehow one bullet hits multiple cells one is arbitrarily selected
        bc_collides = groupcollide(player_bullets, shield, True, False, collide_mask)
        for current_bullet in bc_collides.keys():
            self.manager.add_score(opt.score_cell_shoot)
            shield.remove_cross(bc_collides[current_bullet][0])


    def find_centermost_cell(self, cells):
        """Given a list of Cell sprites, 
        returns the one whose rect.centery is closest to the player's rect.centery
        
        Returns None if list is empty
        """
        
        closest_cell = None
        
        for current_cell in cells:
            current_dist = abs(current_cell.rect.centery - self.player.rect.centery)
            if closest_cell is None or current_dist < closest_dist:
                closest_cell = current_cell
                closest_dist = current_dist

        return closest_cell


    def shoot(self):
        """If cannon can be fired, fires cannon.
        
        Otherwise creates bullet moving from player's center along player's direction
        as long as options.max_player_bullets won't be exeeded
        """
        
        if collide_mask(self.player, self.ion_field):
            return

        if self.cannon.start_transition(Cannon.FIRING):
            return        
        
        if len(self.player_bullets) < opt.max_player_bullets:
            new_bullet = Bullet(opt.bullet_filename, opt.bullet_speed, 
                                self.player.get_rect().center, self.player.get_direction())
            self.player_bullets.add(new_bullet)


    def reset_positions(self):
        """Moves sprites to their initial locations:
        player starts in left center facing south and with 0 energy
        player bullets are removed
        enemy bullet starts on enemy base
        enemy base is in moving state
        cannon is in deactivated state

        Note: shield configuration is not reset
        """

        self.player.rect.midleft = (20, int(opt.height/2))
        self.player.set_direction(vector.SOUTH)
        self.player_bullets.empty()
        self.enemy.resume_mover_state()
        self.cannon.start_deactivated()
        self.hbullet.rect.center = self.enemy.rect.center


    def kill_player(self):
        death_animation = DeathAnimation(self.manager, self.player, (self.enemy, self.shield), self,
                opt.death_animation_delay, opt.death_animation_total_runtime)
        self.manager.change_state(death_animation)


    def end_level(self):
        win_animation = WinAnimation(self.manager, self.player, opt.win_animation_total_runtime, opt.exp_field_args)
        self.manager.change_state(win_animation)
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:104,代码来源:level.py


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