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


Python Character.attack方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Character import Character [as 别名]
# 或者: from Character.Character import attack [as 别名]
class GameState:
    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode((1280, 800))
        self.area = self.screen.get_rect()
        self.walls = Wall.gather_walls()

        self.my_clock = pygame.time.Clock()     # Utility object

        self.background = Background()          # Objects we put on screen
        self.character = Character(self.area)

        self.all_but_background = PgGroup((self.character, self.walls))

        self.monsters = Monster.spawn_monsters(self.character, self.walls, ((ChampionMeleeMonster, 15), (Monster, 30),
                                                                            (RangeMonster, 25)))

        # So we can call each monster's attack method.
        self.monster_group = PgGroup(self.monsters)

        # Used to update everything to screen.
        self.all_sprites = PgGroup((self.character, self.monsters, self.background, self.walls))

        # Used to draw. We separate background so we can ensure it gets pictured before other things.
        self.all_but_background.add(self.monsters)

        self.time_test = False # Changed things in while loop so need to recreate timetest.
        self.time_dict = {'drawmove': 0, 'abilitydraw': 0, 'eventloop': 0, 'attacks': 0, 'collisions': 0,
                          'move': 0, 'clear/recover': 0, 'drawbars': 0}
        self.loop_counter = 0

        self.find_key = {K_LSHIFT: 0, K_SPACE: 1, LEFT: 2, RIGHT: 3}

    def clear_weapon(self):
        # If sword is on screen, clear it off.
        for sprite in self.all_but_background:
            if isinstance(sprite, Attack) and sprite.is_dead():
                sprite.kill()

    def clear_dead(self):
        # Remove dead monsters/players from game.
        for sprite in self.all_but_background:
            if type(sprite) is Monster or Character:
                if sprite.is_dead():
                    sprite.kill()
                    if isinstance(sprite, Monster):
                        self.character.experience += sprite.exp_value
                        if self.character.level_up():
                            self.character.ability_manager.ability_points += 1
                    elif type(sprite) is Character:
                        exit()

    def main(self):
        elapsed_time = 0
        while True:
            for event in pygame.event.get():
                if event.type == QUIT:
                    if self.time_test:
                        for key, value in self.time_dict.items():
                            print(key, value/self.loop_counter)
                    pygame.display.quit()
                    pygame.quit()
                    exit()
                if event.type == KEYUP:
                    Mover.handle_character_event(event, False)
                elif event.type == KEYDOWN:
                    if event.key == K_LSHIFT or event.key == K_SPACE:
                        key = self.find_key[event.key]
                        weapon = self.character.attack(pygame.mouse.get_pos(), self.character.ability_manager.elements[key])
                        if weapon is not None:
                            self.all_but_background.add(weapon) # For collisions
                            self.all_sprites.add(weapon) # For movement
                    else:
                        Mover.handle_character_event(event, True)
                elif event.type == MOUSEBUTTONDOWN:
                    if Rect(30, 640, 370, 100).collidepoint(event.pos) or (self.character.ability_manager.menu_up and Rect(30, 360, 370, 300).collidepoint(event.pos)):
                         ability_leveled =  self.character.ability_manager.handle_click(event)
                         if ability_leveled:
                             self.character.ability_levels[ability_leveled] += 1
                             self.character.increment_maxes()
                    elif Rect(880, 640, 370, 115).collidepoint(event.pos) or (self.character.inventory.menu_up and Rect(880, 280, 370, 360).collidepoint(event.pos)):
                         self.character.inventory.handle_click(event, self.character.ability_levels)
                         self.character.increment_maxes() # If Item that boost ToughenUp is equipped, health needs to change.
                    else:
                        self.character.ability_manager.menu_up = False
                        self.character.inventory.menu_up = False
                        if event.button == LEFT or event.button == RIGHT:
                             key = self.find_key[event.button]
                             weapon = self.character.attack(event.pos, self.character.ability_manager.elements[key])
                             if weapon is not None:
                                 self.all_but_background.add(weapon) # For collisions
                                 self.all_sprites.add(weapon) # For movement

            self.screen.fill((0, 0, 0))

            self.character.calc_velocity(elapsed_time)

            monster_weapons = PgGroup.monster_attack(self.monster_group, self.character.rect.center)
            self.all_but_background.add(monster_weapons)
            self.all_sprites.add(monster_weapons)
#.........这里部分代码省略.........
开发者ID:DavidJayBrady,项目名称:PygameArena,代码行数:103,代码来源:mainloop.py

示例2: Character

# 需要导入模块: from Character import Character [as 别名]
# 或者: from Character.Character import attack [as 别名]
from Character import Character

__author__ = 'Chase Anderson'

Alice = Character("Alice", 0, 0, 100)

Alice.move_right()

Alice.move_right()

print Alice.x

print Alice.y

print Alice.hp

Bob = Character("Bob", 3, 0, 100)

Bob.attack(Alice)

Alice.report_health()

Alice.move_left()

Alice.attack(Bob)

Bob.report_health()
开发者ID:W0mpRat,项目名称:IntroductionOOP,代码行数:29,代码来源:Battle.py


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